Added concepts with the same key handling
This commit is contained in:
@@ -13,9 +13,10 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
"""
|
||||
Used to add a new concept
|
||||
"""
|
||||
NAME = "AddNewConcept"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Add new Concept", 50)
|
||||
super().__init__(self.NAME, 50)
|
||||
|
||||
def matches(self, context, return_value):
|
||||
return return_value.status and \
|
||||
|
||||
@@ -9,10 +9,11 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ConceptEvaluator(OneReturnValueEvaluator):
|
||||
NAME = "Concept"
|
||||
evaluation_steps = [BuiltinConcepts.EVALUATION, BuiltinConcepts.AFTER_EVALUATION]
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Concept Evaluator", 50)
|
||||
super().__init__(self.NAME, 50)
|
||||
|
||||
def matches(self, context, return_value):
|
||||
return return_value.status and \
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from evaluators.AddConceptEvaluator import AddConceptEvaluator
|
||||
from evaluators.BaseEvaluator import AllReturnValuesEvaluator
|
||||
from parsers.BaseParser import BaseParser
|
||||
|
||||
@@ -8,8 +9,10 @@ class DuplicateConceptEvaluator(AllReturnValuesEvaluator):
|
||||
Use to recognize when we tried to add the same concept twice
|
||||
"""
|
||||
|
||||
NAME = "DuplicateConcept"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Duplicate Concept Evaluator", 10)
|
||||
super().__init__(self.NAME, 10)
|
||||
self.already_defined = None
|
||||
|
||||
def matches(self, context, return_values):
|
||||
@@ -22,7 +25,7 @@ class DuplicateConceptEvaluator(AllReturnValuesEvaluator):
|
||||
if sheerka.isinstance(ret.value, BuiltinConcepts.AFTER_EVALUATION):
|
||||
if ret.status:
|
||||
parsing = True
|
||||
elif ret.who == "Evaluators:Add new Concept":
|
||||
elif ret.who == sheerka.get_evaluator_name(AddConceptEvaluator.NAME):
|
||||
if not ret.status and ret.value.body.args[0] == "Duplicate object.":
|
||||
add_concept_in_error = True
|
||||
self.already_defined = ret.value.body.obj
|
||||
|
||||
@@ -14,8 +14,10 @@ class MultipleSameSuccessEvaluator(AllReturnValuesEvaluator):
|
||||
It has a low priority to let other evaluators try to resolve the errors
|
||||
"""
|
||||
|
||||
NAME = "MultipleSameSuccess"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Parsers Evaluator", 10)
|
||||
super().__init__(self.NAME, 10)
|
||||
self.success = []
|
||||
|
||||
def matches(self, context, return_values):
|
||||
|
||||
@@ -13,8 +13,10 @@ class OneSuccessEvaluator(AllReturnValuesEvaluator):
|
||||
It has a low priority to let other evaluators try to resolve the errors
|
||||
"""
|
||||
|
||||
NAME = "OneSuccess"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Parsers Evaluator", 10)
|
||||
super().__init__(self.NAME, 10)
|
||||
self.successful_return_value = None
|
||||
|
||||
def matches(self, context, return_values):
|
||||
|
||||
@@ -8,8 +8,11 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PythonEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
NAME = "Python"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("Python Evaluator", 50)
|
||||
super().__init__(self.NAME, 50)
|
||||
|
||||
def matches(self, context, return_value):
|
||||
return return_value.status and \
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from evaluators.BaseEvaluator import AllReturnValuesEvaluator, BaseEvaluator
|
||||
import logging
|
||||
|
||||
from parsers.BaseParser import BaseParser
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TooManySuccessEvaluator(AllReturnValuesEvaluator):
|
||||
"""
|
||||
Used to filter the responses
|
||||
It has a low priority to let other evaluators try to resolve the errors
|
||||
"""
|
||||
|
||||
NAME = "TooManySuccess"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(self.NAME, 10)
|
||||
self.success = []
|
||||
|
||||
def matches(self, context, return_values):
|
||||
sheerka = context.sheerka
|
||||
after_evaluation = False
|
||||
nb_successful_evaluators = 0
|
||||
only_parsers_in_error = True
|
||||
unlisted = False
|
||||
|
||||
for ret in return_values:
|
||||
|
||||
if sheerka.isinstance(ret.value, BuiltinConcepts.AFTER_EVALUATION):
|
||||
if ret.status:
|
||||
after_evaluation = True
|
||||
|
||||
elif ret.who.startswith(BaseEvaluator.PREFIX):
|
||||
if ret.status:
|
||||
nb_successful_evaluators += 1
|
||||
self.success.append(ret)
|
||||
elif ret.who.startswith(BaseParser.PREFIX):
|
||||
if ret.status:
|
||||
only_parsers_in_error = False
|
||||
else:
|
||||
unlisted = True
|
||||
|
||||
return after_evaluation and nb_successful_evaluators > 1 and only_parsers_in_error and not unlisted
|
||||
|
||||
def eval(self, context, return_values):
|
||||
reference = self.get_value(self.success[0].value)
|
||||
|
||||
for return_value in self.success[1:]:
|
||||
actual = self.get_value(return_value.value)
|
||||
if actual != reference:
|
||||
sheerka = context.sheerka
|
||||
too_many_success = sheerka.new(BuiltinConcepts.TOO_MANY_SUCCESS, obj=self.success)
|
||||
return sheerka.ret(self.name, False, too_many_success, parents=return_values)
|
||||
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_value(obj):
|
||||
if not isinstance(obj, Concept):
|
||||
return obj
|
||||
|
||||
return obj if obj.body is None else obj.body
|
||||
Reference in New Issue
Block a user