from core.builtin_concepts import ParserResultConcept from core.concept import Concept, ConceptParts from evaluators.BaseEvaluator import OneReturnValueEvaluator import logging from parsers.BaseParser import BaseParser log = logging.getLogger(__name__) class ConceptEvaluator(OneReturnValueEvaluator): def __init__(self): super().__init__("Concept Evaluator", 50) def matches(self, context, return_value): return return_value.status and \ return_value.who.startswith(BaseParser.PREFIX) and \ isinstance(return_value.value, Concept) and \ not isinstance(return_value.value, ParserResultConcept) # because there are specific evaluators def eval(self, context, return_value): sheerka = context.sheerka concept = return_value.value # pre condition should already be validated by the parser. # It's a mandatory condition for the concept before it can be recognized if len(concept.codes) == 0: sheerka.add_codes_to_concept(context, concept) # TODO; check pre # if pre is not true, return Concept with a false value if ConceptParts.BODY in concept.codes: body = concept.codes[ConceptParts.BODY] if body is None: return None # nothing to do return sheerka.ret(self.name, True, body.value, parents=[return_value]) else: return sheerka.ret(self.name, True, concept, parents=[return_value])