Fixed #49 : working
This commit is contained in:
@@ -1123,12 +1123,22 @@ class SheerkaRuleManager(BaseService):
|
||||
|
||||
|
||||
class ReteConditionExprVisitor(ExpressionVisitor):
|
||||
"""
|
||||
From an ExprNode, construct the list of Rete condition that can be used in the ReteNetwork
|
||||
"""
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
self.var_counter = 0
|
||||
self.variables = {}
|
||||
|
||||
def get_conditions(self, expr_node):
|
||||
self.var_counter = 0
|
||||
self.variables.clear()
|
||||
|
||||
conditions = self.visit(expr_node)
|
||||
return [AndConditions(conditions)]
|
||||
|
||||
def add_variable(self, target):
|
||||
var_name = f"__x_{self.var_counter:02}__"
|
||||
self.var_counter += 1
|
||||
@@ -1165,17 +1175,25 @@ class ReteConditionExprVisitor(ExpressionVisitor):
|
||||
conditions.append(Condition(root, attr, variable))
|
||||
return variable
|
||||
|
||||
def get_conditions(self, expr_node):
|
||||
self.var_counter = 0
|
||||
self.variables.clear()
|
||||
def visit_VariableNode(self, expr_node: VariableNode):
|
||||
if expr_node.attributes_str is None and not expr_node.name.startswith("__"):
|
||||
# try to recognize a concept
|
||||
res = evaluate(self.context,
|
||||
expr_node.name,
|
||||
evaluators=CONDITIONS_VISITOR_EVALUATORS,
|
||||
desc=None,
|
||||
eval_body=True,
|
||||
eval_where=False,
|
||||
is_question=False,
|
||||
expect_success=False,
|
||||
stm=None)
|
||||
res = expect_one(self.context, res)
|
||||
if res.status and isinstance(res.value, Concept):
|
||||
return self.recognize_concept(["__ret", "body"], res.value, {})
|
||||
|
||||
conditions = self.visit(expr_node)
|
||||
return [AndConditions(conditions)]
|
||||
|
||||
def visit_VariableNode(self, expr_node):
|
||||
conditions = []
|
||||
var_name, attr = self.init_or_get_variable_from_name(expr_node.unpack(), conditions)
|
||||
if expr_node.attributes_str is not None:
|
||||
if attr:
|
||||
conditions.append(Condition(var_name, attr, True))
|
||||
return conditions
|
||||
|
||||
@@ -1277,3 +1295,7 @@ class ReteConditionExprVisitor(ExpressionVisitor):
|
||||
conditions.extend(res)
|
||||
else:
|
||||
conditions.append(Condition(left, attr, value))
|
||||
|
||||
|
||||
class PythonConditionExprVisitor(ExpressionVisitor):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user