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
+42
View File
@@ -0,0 +1,42 @@
from core.builtin_concepts import BuiltinConcepts
from core.concept import Concept
from evaluators.BaseEvaluator import AllReturnValuesEvaluator
import logging
from parsers.BaseParser import BaseParser
log = logging.getLogger(__name__)
class ParsersEvaluator(AllReturnValuesEvaluator):
"""
Used to filter the responses
It has a low priority to let other evaluators try to resolve the errors
"""
def __init__(self):
super().__init__("Parsers Evaluator", 10)
self.successful_return_value = None
def matches(self, context, return_values):
sheerka = context.sheerka
after_parsing = False
nb_successful_evaluators = 0
only_parsers = True
for ret in return_values:
if sheerka.isinstance(ret.value, BuiltinConcepts.AFTER_PARSING):
if ret.status:
after_parsing = True
elif ret.who.startswith(self.PREFIX):
if ret.status:
nb_successful_evaluators += 1
self.successful_return_value = ret
else:
if not ret.who.startswith(BaseParser.PREFIX):
only_parsers = False
return after_parsing and nb_successful_evaluators == 1 and only_parsers
def eval(self, context, return_values):
sheerka = context.sheerka
return sheerka.ret(self.name, True, self.successful_return_value.value, parents=return_values)