First implementation of questions management
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka.services.sheerka_service import BaseService
|
||||
|
||||
|
||||
class SheerkaQuestion(BaseService):
|
||||
NAME = "Question"
|
||||
|
||||
def __init__(self, sheerka):
|
||||
super().__init__(sheerka)
|
||||
|
||||
def initialize(self):
|
||||
self.sheerka.bind_service_method(self.question, False)
|
||||
self.sheerka.bind_service_method(self.is_question, False)
|
||||
|
||||
def question(self, context, q):
|
||||
"""
|
||||
Evaluate q in the context in a question
|
||||
:param context:
|
||||
:param q:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if isinstance(q, Concept):
|
||||
with context.push(BuiltinConcepts.EVALUATE_CONCEPT, q, desc=f"Evaluating question '{q}'") as sub_context:
|
||||
sub_context.global_hints.add(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
sub_context.global_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
sub_context.global_hints.add(BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED)
|
||||
sub_context.protected_hints.add(BuiltinConcepts.RETURN_BODY_REQUESTED)
|
||||
|
||||
evaluated = self.sheerka.evaluate_concept(sub_context, q)
|
||||
|
||||
return evaluated
|
||||
|
||||
def is_question(self, context):
|
||||
"""
|
||||
Returns True if a question is asked
|
||||
:return:
|
||||
"""
|
||||
return context.in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
Reference in New Issue
Block a user