43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
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)
|