Fixed #29: Parsers: Implement parsing memoization
Fixed #77 : Parser: ShortTermMemoryParser should be called separately Fixed #78 : Remove VariableNode usage Fixed #79 : ConceptManager: Implement compile caching Fixed #80 : SheerkaExecute : parsers_key is not correctly computed Fixed #81 : ValidateConceptEvaluator : Validate concept's where and pre clauses right after the parsing Fixed #82 : SheerkaIsAManager: isa() failed when the set as a body Fixed #83 : ValidateConceptEvaluator : Support BNF and SYA Concepts Fixed #84 : ExpressionParser: Implement the parser as a standard parser Fixed #85 : Services: Give order to services Fixed #86 : cannot manage smart_get_attr(the short, color)
This commit is contained in:
@@ -111,13 +111,23 @@ class SheerkaEvaluateRules(BaseService):
|
||||
|
||||
return expect_one(context, results)
|
||||
|
||||
def evaluate_conditions(self, context, conditions, bag):
|
||||
def evaluate_conditions(self, context, conditions, bag, missing_vars=None):
|
||||
"""
|
||||
Evaluate the conditions
|
||||
:param context:
|
||||
:param conditions:
|
||||
:param bag: variables that are supposed to be in short term memory
|
||||
:param missing_vars: if initialized to a set, keeps tracks of the missing variables
|
||||
:return:
|
||||
"""
|
||||
bag_variables = set(bag.keys())
|
||||
|
||||
results = []
|
||||
for compiled_condition in conditions:
|
||||
|
||||
if compiled_condition.variables.intersection(bag_variables) != compiled_condition.variables:
|
||||
if isinstance(missing_vars, set):
|
||||
missing_vars.update(compiled_condition.variables - bag_variables)
|
||||
continue
|
||||
|
||||
if compiled_condition.not_variables.intersection(bag_variables):
|
||||
@@ -131,11 +141,12 @@ class SheerkaEvaluateRules(BaseService):
|
||||
|
||||
# do not forget to reset the 'is_evaluated' in the case of a concept
|
||||
for concept in compiled_condition.concepts_to_reset:
|
||||
concept.get_metadata().is_evaluated = False
|
||||
concept.get_hints().is_evaluated = False
|
||||
|
||||
evaluator = self.evaluators_by_name[compiled_condition.evaluator_type]
|
||||
res = evaluator.eval(context, compiled_condition.return_value)
|
||||
if res.status and isinstance(res.body, bool) and res.body:
|
||||
value = context.sheerka.objvalue(res.body)
|
||||
if res.status and isinstance(value, bool) and value:
|
||||
# one successful value found. No need to look any further
|
||||
results = [res] # don't we care about the other failing results ?
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user