Fixed #131 : Implement ExprToConditions
Fixed #130 : ArithmeticOperatorParser Fixed #129 : python_wrapper : create_namespace Fixed #128 : ExpressionParser: Cannot parse func(x) infixed concept 'xxx'
This commit is contained in:
@@ -343,7 +343,7 @@ class TestDefConceptEvaluator(TestUsingMemoryBasedSheerka):
|
||||
assert created_concept.get_metadata().variables == [('n1', None), ('one', None), ('two', None), ('n2', None)]
|
||||
assert created_concept.get_metadata().parameters == ['n1', 'n2']
|
||||
|
||||
def test_i_can_eval_when_bnf_with_implicit_variables_from_unamed_ordered_choice(self):
|
||||
def test_i_can_eval_when_bnf_with_implicit_variables_from_unnamed_ordered_choice(self):
|
||||
sheerka, context, one, two, three = self.init_concepts("one", "two", "three", create_new=True)
|
||||
text = "def concept choice from bnf (one|two) 'or' (two|three) 'or' (two|three)=c3"
|
||||
def_ret_val = DefConceptParser().parse(context, ParserInput(text))
|
||||
@@ -382,7 +382,7 @@ class TestDefConceptEvaluator(TestUsingMemoryBasedSheerka):
|
||||
assert created_concept.get_metadata().variables == [('n1', None), ('n2', None)]
|
||||
assert created_concept.get_metadata().parameters == ['n1', 'n2']
|
||||
|
||||
def test_i_can_eval_when_bnf_with_implicit_variables_from_unamed_unordered_choice(self):
|
||||
def test_i_can_eval_when_bnf_with_implicit_variables_from_unnamed_unordered_choice(self):
|
||||
# as it's not possible to directly defined UnorderedChoice, we test isa concept
|
||||
sheerka, context, one, two, number = self.init_concepts("one", "two", "number", create_new=True)
|
||||
global_truth_context = self.get_context(global_truth=True)
|
||||
|
||||
@@ -55,6 +55,7 @@ class TestExpressionEvaluator(TestUsingMemoryBasedSheerka):
|
||||
"one",
|
||||
"number",
|
||||
Concept("x is a y", body="isa(x,y)", pre="is_question()").def_var("x").def_var("y"))
|
||||
context.add_to_protected_hints(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
evaluator = ExpressionEvaluator()
|
||||
|
||||
parsed_return_value = ExpressionParser().parse(context, ParserInput("one is a number"))
|
||||
@@ -72,6 +73,7 @@ class TestExpressionEvaluator(TestUsingMemoryBasedSheerka):
|
||||
"one",
|
||||
"number",
|
||||
Concept("x is a y", body="isa(x,y)", pre="is_question()").def_var("x").def_var("y"))
|
||||
context.add_to_protected_hints(BuiltinConcepts.EVAL_QUESTION_REQUESTED)
|
||||
evaluator = ExpressionEvaluator()
|
||||
|
||||
parsed_return_value = ExpressionParser().parse(context, ParserInput("self is a number"))
|
||||
|
||||
@@ -27,17 +27,17 @@ class TestPrepareEvalCommon(TestUsingMemoryBasedSheerka):
|
||||
def test_i_can_update_process_when_evaluating_a_concept(self):
|
||||
sheerka, context, foo = self.init_concepts("foo")
|
||||
|
||||
eval_context = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
|
||||
parsing_prop_context = eval_context.push(BuiltinConcepts.PARSING, {"prop": ConceptParts.BODY})
|
||||
level1 = parsing_prop_context.push(BuiltinConcepts.TESTING, "some stuff")
|
||||
level2 = level1.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
|
||||
eval_ctx = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
|
||||
parsing_prop_ctx = eval_ctx.push(BuiltinConcepts.PARSE_CODE, {"concept": foo, "prop": ConceptParts.BODY})
|
||||
level1_ctx = parsing_prop_ctx.push(BuiltinConcepts.TESTING, "some stuff")
|
||||
level2_ctx = level1_ctx.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
|
||||
|
||||
PrepareEvalCommon.update_context_hints(level2, "prop_name", ["to_put_in_context"])
|
||||
PrepareEvalCommon.update_context_hints(level2_ctx, "prop_name", ["to_put_in_context"])
|
||||
assert not context.in_context("to_put_in_context")
|
||||
assert not eval_context.in_context("to_put_in_context")
|
||||
assert not parsing_prop_context.in_context("to_put_in_context")
|
||||
assert not level1.in_context("to_put_in_context")
|
||||
assert not level2.in_context("to_put_in_context")
|
||||
assert not eval_ctx.in_context("to_put_in_context")
|
||||
assert not parsing_prop_ctx.in_context("to_put_in_context")
|
||||
assert not level1_ctx.in_context("to_put_in_context")
|
||||
assert not level2_ctx.in_context("to_put_in_context")
|
||||
assert foo.get_compiled_context_hints() == {ConceptParts.BODY: ["to_put_in_context"]}
|
||||
|
||||
def test_i_can_update_for_the_correct_variable(self):
|
||||
@@ -45,15 +45,15 @@ class TestPrepareEvalCommon(TestUsingMemoryBasedSheerka):
|
||||
# use this name, rather than the attribute being parsed
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo").def_var("var_name"))
|
||||
|
||||
eval_context = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
|
||||
parsing_prop_context = eval_context.push(BuiltinConcepts.PARSING, {"prop": ConceptParts.BODY})
|
||||
level1 = parsing_prop_context.push(BuiltinConcepts.TESTING, "some stuff")
|
||||
level2 = level1.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
|
||||
eval_ctx = context.push(BuiltinConcepts.EVALUATING_CONCEPT, foo, desc=f"some desc")
|
||||
parsing_prop_ctx = eval_ctx.push(BuiltinConcepts.PARSE_CODE, {"concept": foo, "prop": ConceptParts.BODY})
|
||||
level1_ctx = parsing_prop_ctx.push(BuiltinConcepts.TESTING, "some stuff")
|
||||
level2_ctx = level1_ctx.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
|
||||
|
||||
PrepareEvalCommon.update_context_hints(level2, "var_name", ["to_put_in_context"])
|
||||
PrepareEvalCommon.update_context_hints(level2_ctx, "var_name", ["to_put_in_context"])
|
||||
assert not context.in_context("to_put_in_context")
|
||||
assert not eval_context.in_context("to_put_in_context")
|
||||
assert not parsing_prop_context.in_context("to_put_in_context")
|
||||
assert not level1.in_context("to_put_in_context")
|
||||
assert not level2.in_context("to_put_in_context")
|
||||
assert not eval_ctx.in_context("to_put_in_context")
|
||||
assert not parsing_prop_ctx.in_context("to_put_in_context")
|
||||
assert not level1_ctx.in_context("to_put_in_context")
|
||||
assert not level2_ctx.in_context("to_put_in_context")
|
||||
assert foo.get_compiled_context_hints() == {"var_name": ["to_put_in_context"]}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts, ReturnValueConcept, UserInputConcept
|
||||
from core.concept import Concept
|
||||
from core.concept import Concept, ConceptParts
|
||||
from evaluators.PrepareEvalQuestionEvaluator import PrepareEvalQuestionEvaluator
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
r = ReturnValueConcept
|
||||
@@ -48,3 +47,29 @@ class TestPrepareEvalQuestionEvaluator(TestUsingMemoryBasedSheerka):
|
||||
assert BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED in context.protected_hints
|
||||
assert BuiltinConcepts.EVAL_BODY_REQUESTED in context.protected_hints
|
||||
assert BuiltinConcepts.RETURN_BODY_REQUESTED in context.protected_hints
|
||||
|
||||
def test_i_can_eval_when_parsing_asts(self):
|
||||
sheerka, context, foo = self.init_concepts(Concept("foo", body="question(q)").def_var("q"))
|
||||
|
||||
parsing_prop_ctx = context.push(BuiltinConcepts.PARSE_CODE, {"concept": foo, "prop": ConceptParts.BODY})
|
||||
level1_ctx = parsing_prop_ctx.push(BuiltinConcepts.TESTING, "some stuff")
|
||||
level2_ctx = level1_ctx.push(BuiltinConcepts.TESTING, "some stuff") # another level for the fun
|
||||
ret_val = r("name", True, UserInputConcept("question(q)"))
|
||||
|
||||
prepare_evaluator = PrepareEvalQuestionEvaluator()
|
||||
prepare_evaluator.matches(level2_ctx, ret_val)
|
||||
res = prepare_evaluator.eval(level2_ctx, ret_val)
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(res.body, BuiltinConcepts.USER_INPUT)
|
||||
assert res.body.body == "q"
|
||||
|
||||
assert BuiltinConcepts.EVAL_QUESTION_REQUESTED not in context.protected_hints
|
||||
assert BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED not in context.protected_hints
|
||||
assert BuiltinConcepts.EVAL_BODY_REQUESTED not in context.protected_hints
|
||||
assert BuiltinConcepts.RETURN_BODY_REQUESTED not in context.protected_hints
|
||||
|
||||
assert foo.get_compiled_context_hints() == {"q": [BuiltinConcepts.EVAL_QUESTION_REQUESTED,
|
||||
BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED,
|
||||
BuiltinConcepts.EVAL_BODY_REQUESTED,
|
||||
BuiltinConcepts.RETURN_BODY_REQUESTED]}
|
||||
|
||||
@@ -11,7 +11,7 @@ from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from core.tokenizer import Tokenizer
|
||||
from evaluators.PythonEvaluator import PythonEvaluator, PythonEvalError
|
||||
from parsers.BaseNodeParser import SourceCodeNode, SourceCodeWithConceptNode
|
||||
from parsers.FunctionParser import FunctionParser
|
||||
from parsers.FunctionParserOld import FunctionParserOld
|
||||
from parsers.PythonParser import PythonNode, PythonParser
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import CB, compare_with_test_object
|
||||
@@ -318,7 +318,7 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
|
||||
context = self.get_context()
|
||||
context.add_to_short_term_memory("get_obj_name", get_obj_name)
|
||||
|
||||
parsed = FunctionParser().parse(context, ParserInput("get_obj_name(r:|1:)"))
|
||||
parsed = FunctionParserOld().parse(context, ParserInput("get_obj_name(r:|1:)"))
|
||||
python_evaluator = PythonEvaluator()
|
||||
evaluated = python_evaluator.eval(context, parsed)
|
||||
|
||||
@@ -344,7 +344,7 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
|
||||
context = self.get_context()
|
||||
context.add_to_short_term_memory("return_return_value", return_return_value)
|
||||
|
||||
parsed = FunctionParser().parse(context, ParserInput(method))
|
||||
parsed = FunctionParserOld().parse(context, ParserInput(method))
|
||||
python_evaluator = PythonEvaluator()
|
||||
evaluated = python_evaluator.eval(context, parsed)
|
||||
ret_val = return_return_value(expected_status)
|
||||
@@ -371,9 +371,9 @@ class TestPythonEvaluator(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.parametrize("parser, value", [
|
||||
(PythonParser(), "3"),
|
||||
(FunctionParser(), "3"),
|
||||
(FunctionParserOld(), "3"),
|
||||
(PythonParser(), 3),
|
||||
(FunctionParser(), 3),
|
||||
(FunctionParserOld(), 3),
|
||||
])
|
||||
def test_i_can_eval_unresolved_rules(self, parser, value):
|
||||
context = self.get_context()
|
||||
|
||||
Reference in New Issue
Block a user