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)
|
|
|
|
def matches(self, context, return_values):
|
|
return context.in_context(BuiltinConcepts.CONCEPT_VALUE_REQUESTED)
|
|
|
|
def eval(self, context, return_values):
|
|
sheerka = context.sheerka
|
|
result = []
|
|
|
|
for ret_val in return_values:
|
|
if ret_val.status and isinstance(ret_val.body, Concept) and ret_val.body.body != BuiltinConcepts.NOT_INITIALIZED:
|
|
context.log(f"Evaluating {ret_val.body}", who=self)
|
|
result.append(sheerka.ret(self.name, True, ret_val.body.body, parents=[ret_val]))
|
|
elif ret_val.status and sheerka.isaset(context, ret_val.body):
|
|
context.log(f"Evaluating set {ret_val.body}", who=self)
|
|
result.append(sheerka.ret(
|
|
self.name,
|
|
True,
|
|
sheerka.get_set_elements(context, ret_val.body),
|
|
parents=[ret_val]))
|
|
|
|
if len(result) > 0:
|
|
return result
|
|
|
|
return None
|