Files
Sheerka-Old/src/evaluators/PrepareEvalGlobalTruthEvaluator.py
T
kodjo 71d1b1d1ca Fixed #101 : Implement PLURIAL
Fixed #103 : Implement PlurialNodeParser
Fixed #104 : Implement dynamic concept
Fixed #107 : PrepareEvalxxxEvaluator: context hints are lost on a second evaluation
2021-08-05 19:07:21 +02:00

51 lines
1.7 KiB
Python

from core.builtin_concepts import BuiltinConcepts
from evaluators.BaseEvaluator import OneReturnValueEvaluator
from evaluators.PrepareEvalCommon import PrepareEvalCommon
class PrepareEvalGlobalTruthEvaluator(OneReturnValueEvaluator, PrepareEvalCommon):
"""
To recognize when the user input is a global truth
"""
NAME = "PrepareEvalGlobalTruth"
def __init__(self, **kwargs):
super().__init__(self.NAME, [BuiltinConcepts.BEFORE_PARSING], 90)
self.inner_text = None
def reset(self):
self.inner_text = None
def matches(self, context, return_value):
if not (return_value.status and
context.sheerka.isinstance(return_value.body, BuiltinConcepts.USER_INPUT) and
isinstance(return_value.body.body, str)):
return False
text = return_value.body.body.strip()
if not (text.startswith("global_truth(") and text.endswith(")")):
return False
self.inner_text = text[13:-1].strip()
if self.inner_text == "":
return False
return True
def eval(self, context, return_value):
sheerka = context.sheerka
new_text_to_parse = sheerka.ret(
self.name,
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.inner_text, user_name=context.event.user_id))
self.update_context_hints(context,
self.inner_text, [
BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED,
BuiltinConcepts.EVAL_BODY_REQUESTED,
BuiltinConcepts.RETURN_BODY_REQUESTED
])
return new_text_to_parse