Managing concept properties in ConceptEvaluator
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from core.builtin_concepts import ParserResultConcept
|
||||
from core.builtin_concepts import ParserResultConcept, BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
import logging
|
||||
@@ -9,6 +9,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ConceptEvaluator(OneReturnValueEvaluator):
|
||||
evaluation_steps = [BuiltinConcepts.EVALUATION, BuiltinConcepts.AFTER_EVALUATION]
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Concept Evaluator", 50)
|
||||
|
||||
@@ -31,12 +33,32 @@ class ConceptEvaluator(OneReturnValueEvaluator):
|
||||
# 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
|
||||
# Evaluate the properties
|
||||
for prop in concept.props:
|
||||
sub_context = context.push(self.name, f"Evaluating property '{prop}'", concept)
|
||||
res = self.evaluate_parsing(sheerka, sub_context, concept.codes[prop])
|
||||
if res.status:
|
||||
concept.set_prop(prop, res.value)
|
||||
else:
|
||||
return sheerka.ret(
|
||||
self.name,
|
||||
False,
|
||||
sheerka.new(BuiltinConcepts.PROPERTY_EVAL_ERROR, body=prop, concept=concept, error=res.value),
|
||||
parents=[return_value])
|
||||
|
||||
return sheerka.ret(self.name, True, body.value, parents=[return_value])
|
||||
|
||||
else:
|
||||
# Evaluate body
|
||||
if ConceptParts.BODY not in concept.codes:
|
||||
return sheerka.ret(self.name, True, concept, parents=[return_value])
|
||||
|
||||
body = concept.codes[ConceptParts.BODY]
|
||||
if body is None:
|
||||
return None # seems weird
|
||||
|
||||
sub_context = context.push(self.name, "Evaluating body", concept)
|
||||
res = self.evaluate_parsing(sheerka, sub_context, body)
|
||||
return sheerka.ret(self.name, res.status, res.value, parents=[return_value])
|
||||
|
||||
def evaluate_parsing(self, sheerka, context, parsing_result):
|
||||
res = sheerka.chain_process(context, parsing_result, self.evaluation_steps)
|
||||
res = sheerka.expect_one(context, res)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user