from core.builtin_concepts import BuiltinConcepts from evaluators.BaseEvaluator import OneReturnValueEvaluator class AddToMemoryEvaluator(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 = "AddToMemory" def __init__(self): super().__init__(self.NAME, [BuiltinConcepts.AFTER_EVALUATION], 10) 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 from core.sheerka.services.SheerkaMemory import SheerkaMemory return len(context.sheerka.services[SheerkaMemory.NAME].registration) > 0 def eval(self, context, return_value): if context.sheerka.during_initialisation: from core.sheerka.services.SheerkaMemory import SheerkaMemory service = context.sheerka.services[SheerkaMemory.NAME] service.registration.clear() return None context.sheerka.commit_registered_objects(context) return None # no need to have a second pass