Implemented a first and basic version of a Rete rule engine
This commit is contained in:
@@ -35,8 +35,9 @@ class ConceptDetectedError(ParsingError):
|
||||
|
||||
class PythonNode(Node):
|
||||
|
||||
def __init__(self, source, ast_=None, objects=None):
|
||||
self.source = source
|
||||
def __init__(self, source, ast_=None, original_source=None, objects=None):
|
||||
self.source = source # what was parsed
|
||||
self.original_source = original_source or source # to remember source before concept id replacement
|
||||
self.ast_ = ast_ # if ast_ else ast.parse(source, mode="eval") if source else None
|
||||
self.objects = objects or {} # when objects (mainly concepts or rules) are recognized in the expression
|
||||
self.compiled = None
|
||||
@@ -64,6 +65,9 @@ class PythonNode(Node):
|
||||
if self.source != other.source:
|
||||
return False
|
||||
|
||||
if self.original_source != other.original_source:
|
||||
return False
|
||||
|
||||
if self.ast_ and other.ast_:
|
||||
self_dump = self.get_dump(self.ast_)
|
||||
other_dump = self.get_dump(other.ast_)
|
||||
@@ -74,6 +78,9 @@ class PythonNode(Node):
|
||||
def __hash__(self):
|
||||
return hash((self.source, self.ast_.hash))
|
||||
|
||||
def get_python_node(self):
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def get_dump(ast_):
|
||||
if not ast_:
|
||||
@@ -156,7 +163,7 @@ class PythonParser(BaseParser):
|
||||
BuiltinConcepts.PARSER_RESULT,
|
||||
parser=self,
|
||||
source=parser_input.as_text(),
|
||||
body=PythonNode(source_code, tree, tracker),
|
||||
body=PythonNode(source_code, tree, objects=tracker),
|
||||
try_parsed=None))
|
||||
|
||||
self.log_result(context, parser_input.as_text(), ret)
|
||||
|
||||
Reference in New Issue
Block a user