Refactored to allow ConceptEvaluator

This commit is contained in:
2019-11-14 22:04:38 +01:00
parent 576ce77740
commit 9e10e77737
30 changed files with 2406 additions and 1007 deletions
+35
View File
@@ -0,0 +1,35 @@
from core.concept import Concept, ConceptParts
from evaluators.BaseEvaluator import OneReturnValueEvaluator
import logging
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 == "Parsers:ConceptParser" and \
isinstance(return_value.value, Concept)
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
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])