39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from core.builtin_concepts import BuiltinConcepts
|
|
from core.concept import Concept
|
|
from evaluators.BaseEvaluator import AllReturnValuesEvaluator
|
|
|
|
|
|
class EvalEvaluator(AllReturnValuesEvaluator):
|
|
"""
|
|
Returns the body of all successful concepts
|
|
"""
|
|
|
|
NAME = "Eval"
|
|
|
|
def __init__(self):
|
|
super().__init__(self.NAME, [BuiltinConcepts.AFTER_EVALUATION], 80)
|
|
self.successful_return_value = None
|
|
self.to_eval = []
|
|
self.eval_requested = None
|
|
|
|
def matches(self, context, return_values):
|
|
sheerka = context.sheerka
|
|
for ret in return_values:
|
|
if ret.status and sheerka.isinstance(ret.body, BuiltinConcepts.CONCEPT_EVAL_REQUESTED):
|
|
self.eval_requested = ret
|
|
elif ret.status and isinstance(ret.body, Concept) and ret.body.body:
|
|
self.to_eval.append(ret)
|
|
|
|
return self.eval_requested is not None and len(self.to_eval) > 0
|
|
|
|
def eval(self, context, return_value):
|
|
sheerka = context.sheerka
|
|
result = []
|
|
context.log(self.verbose_log, f"{len(self.to_eval)} return value(s) to eval", who=self)
|
|
|
|
for ret_val in self.to_eval:
|
|
context.log(self.verbose_log, f"{ret_val}", who=self)
|
|
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val, self.eval_requested]))
|
|
|
|
return result
|