Add Symbolic Reasoner
This commit is contained in:
26
nexus/mnemosyne/reasoner.py
Normal file
26
nexus/mnemosyne/reasoner.py
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
"""Symbolic Reasoner — Rule-based event triggering for the Mnemosyne archive."""
|
||||
import json
|
||||
|
||||
class Reasoner:
|
||||
def __init__(self, rules_path):
|
||||
with open(rules_path) as f:
|
||||
self.rules = json.load(f)
|
||||
|
||||
def evaluate(self, archive_entries):
|
||||
triggers = []
|
||||
for rule in self.rules:
|
||||
if self._check_condition(rule['condition'], archive_entries):
|
||||
triggers.append(rule['action'])
|
||||
return triggers
|
||||
|
||||
def _check_condition(self, condition, entries):
|
||||
# Simple symbolic checks: e.g., "count(type=error) > 5"
|
||||
if condition.startswith("count"):
|
||||
parts = condition.split(" ")
|
||||
key, val = parts[0][6:-1].split("=")
|
||||
op = parts[1]
|
||||
threshold = int(parts[2])
|
||||
count = sum(1 for e in entries if e.get(key) == val)
|
||||
if op == ">": return count > threshold
|
||||
return False
|
||||
Reference in New Issue
Block a user