Implemented a first and basic version of a Rete rule engine
This commit is contained in:
@@ -36,12 +36,16 @@ def inject_context(context):
|
||||
|
||||
|
||||
class Expando:
|
||||
def __init__(self, bag):
|
||||
def __init__(self, name, bag):
|
||||
self.__name = name
|
||||
for k, v in bag.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
def __repr__(self):
|
||||
return f"{dir(self)}"
|
||||
return f"{vars(self)}"
|
||||
|
||||
def get_name(self):
|
||||
return self.__name
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -89,12 +93,12 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
def eval(self, context, return_value):
|
||||
sheerka = context.sheerka
|
||||
node = get_python_node(return_value.value.value)
|
||||
node = return_value.value.value.get_python_node()
|
||||
|
||||
debugger = context.get_debugger(PythonEvaluator.NAME, "eval")
|
||||
debugger.debug_entering(node=node)
|
||||
exception_debugger = context.get_debugger("Exceptions", PythonEvaluator.NAME + ".eval")
|
||||
get_trace_back = context.debug_enabled or exception_debugger.is_enabled()
|
||||
get_trace_back = exception_debugger.is_enabled()
|
||||
|
||||
context.log(f"Evaluating python node {node}.", self.name)
|
||||
|
||||
@@ -179,8 +183,6 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
"""
|
||||
unreferenced_names_visitor = UnreferencedNamesVisitor(context)
|
||||
names = unreferenced_names_visitor.get_names(node.ast_)
|
||||
if context.debug_enabled:
|
||||
context.debug(self.NAME, "eval", "names", names)
|
||||
return self.get_globals_by_names(context, names, node, expression_only)
|
||||
|
||||
def get_sheerka_method(self, context, name, expression_only):
|
||||
@@ -200,6 +202,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
my_globals = {
|
||||
"Concept": core.concept.Concept,
|
||||
"BuiltinConcepts": core.builtin_concepts.BuiltinConcepts,
|
||||
"Expando": Expando,
|
||||
"ExecutionContext": ExecutionContext,
|
||||
"in_context": context.in_context,
|
||||
}
|
||||
@@ -218,14 +221,14 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
continue
|
||||
|
||||
# support reference to sheerka
|
||||
if name == "sheerka":
|
||||
if name.lower() == "sheerka":
|
||||
bag = {}
|
||||
visitor = NamesWithAttributesVisitor()
|
||||
for sequence in visitor.get_sequences(node.ast_, "sheerka"):
|
||||
if (len(sequence) > 1 and
|
||||
(method := self.get_sheerka_method(context, sequence[1], expression_only)) is not None):
|
||||
bag[sequence[1]] = method
|
||||
my_globals["sheerka"] = Expando(bag)
|
||||
my_globals[name] = Expando("sheerka", bag)
|
||||
continue
|
||||
|
||||
# search in local variables. To remove when local variables will be merged with memory
|
||||
|
||||
Reference in New Issue
Block a user