from core.builtin_concepts import BuiltinConcepts from core.concept import Concept from evaluators.BaseEvaluator import OneReturnValueEvaluator class PostExecutionEvaluator(OneReturnValueEvaluator): """ Last chance to alter the return_value This evaluator is supposed to be a generic evaluator for all rules that must be executed just before the aggregations """ NAME = "PostExecution" def __init__(self): super().__init__(self.NAME, [BuiltinConcepts.AFTER_EVALUATION], 90) def matches(self, context, return_value): evaluation_parents = context.get_parents(lambda c: c.action == BuiltinConcepts.PROCESSING) if len(evaluation_parents) > 1: return False # It must be executed only when the top level context # only support the rule for the COMMANDS value = return_value.body return isinstance(value, Concept) and context.sheerka.isa(value, context.sheerka.new(BuiltinConcepts.AUTO_EVAL)) def eval(self, context, return_value): # only support the rule for the COMMANDS #body = return_value.body.body body = context.sheerka.objvalue(return_value) return context.sheerka.ret( self.name, True, body if body != BuiltinConcepts.NOT_INITIALIZED else return_value.body, parents=[return_value])