Fixed #68: Implement SheerkaQL

Fixed #70: SheerkaFilterManager : Pipe functions
Fixed #71: SheerkaFilterManager : filter_objects
Fixed #75: SheerkaMemory: Enhance memory() to use the filtering capabilities
Fixed #76: SheerkaEvaluateConcept: Concepts that modify the state of the system must not be evaluated during question
This commit is contained in:
2021-04-26 19:13:47 +02:00
parent bef5f3208c
commit 1059ce25c5
57 changed files with 5759 additions and 1302 deletions
+57 -3
View File
@@ -7,6 +7,7 @@ from core.sheerka.services.SheerkaConceptManager import SheerkaConceptManager
from evaluators.MutipleSameSuccessEvaluator import MultipleSameSuccessEvaluator
from evaluators.OneSuccessEvaluator import OneSuccessEvaluator
from evaluators.PythonEvaluator import PythonEvalError
from sheerkapython.python_wrapper import MethodAccessError
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
from tests.parsers.parsers_utils import CMV, CC, compare_with_test_object, CB
@@ -642,7 +643,7 @@ as:
assert res[0].body == 21
def test_i_can_use_where_in_bnf(self):
sheerka = self.get_sheerka()
sheerka, context = self.init_test().unpack()
init = [
"def concept one as 1",
@@ -683,12 +684,12 @@ as:
assert len(res) == 1
assert not res[0].status
assert sheerka.isinstance(res[0].body, BuiltinConcepts.MULTIPLE_ERRORS)
assert str(BuiltinConcepts.CONDITION_FAILED) in [error.key for error in sheerka.get_errors(res[0].body.body)]
assert sheerka.has_error(context, res, __type=BuiltinConcepts.CONDITION_FAILED)
res = sheerka.evaluate_user_input("eval twenty three")
assert len(res) == 1
assert not res[0].status
assert str(BuiltinConcepts.CONDITION_FAILED) in [error.key for error in sheerka.get_errors(res[0].body.body)]
assert sheerka.has_error(context, res, __type=BuiltinConcepts.CONDITION_FAILED)
def test_i_can_manage_some_type_of_infinite_recursion(self):
sheerka = self.get_sheerka()
@@ -1298,6 +1299,7 @@ as:
assert sheerka.objvalue(res[0].body.get_value("qty")) == 2
def test_i_can_implement_the_concept_and(self):
# Normally, redefining and leads to a circular ref between the concept and the python
init = [
"def concept x and y as x and y",
"set_is_lesser(__PRECEDENCE, c:x and y:, 'Sya')",
@@ -1308,3 +1310,55 @@ as:
assert len(res) == 1
assert res[0].status
def test_i_can_use_result_from_memory_filtering(self):
init = [
"def concept female",
"def concept girl",
"set_isa(girl, female)",
"def concept she ret memory('isa(self, female)')",
"girl"
]
sheerka = self.init_scenario(init)
context = self.get_context(sheerka)
res = sheerka.evaluate_user_input("set_attr(she, 'my_attr', 'my value')")
assert len(res) == 1
assert res[0].status
girl_from_memory = sheerka.get_last_from_memory(context, "girl")
assert girl_from_memory.obj.get_value("my_attr") == "my value"
def test_i_can_use_result_from_memory_filtering_within_other_concept(self):
init = [
"def concept female",
"def concept girl",
"set_isa(girl, female)",
"def concept she ret memory('isa(self, female)')",
"def concept x attribute y equals z as set_attr(x, y, z)",
"girl"
]
sheerka = self.init_scenario(init)
context = self.get_context(sheerka)
res = sheerka.evaluate_user_input("eval she attribute 'my_attr' equals 'my value'")
assert len(res) == 1
assert res[0].status
girl_from_memory = sheerka.get_last_from_memory(context, "girl")
assert girl_from_memory.obj.get_value("my_attr") == "my value"
def test_i_cannot_use_method_that_alter_the_global_state_within_question(self):
init = [
"def concept foo as question(set_debug(True))",
]
sheerka = self.init_scenario(init)
context = self.get_context(sheerka)
res = sheerka.evaluate_user_input("question(set_debug(True))")
assert sheerka.has_error(context, res, __type="MethodAccessError")
res = sheerka.evaluate_user_input("eval foo")
assert sheerka.has_error(context, res, __type="MethodAccessError")