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:
@@ -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")
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
from core.builtin_concepts_ids import BuiltinConcepts
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
|
||||
class TestSheerkaNonRegPipeFunctions(TestUsingMemoryBasedSheerka):
|
||||
def test_i_can_filter_a_list_using_pipe(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept two as 2",
|
||||
"def concept three as 3",
|
||||
"add_to_memory('x', [one, two, three])"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
res = sheerka.evaluate_user_input("x | where(body=2)")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert isinstance(res[0].body, list)
|
||||
assert len(res[0].body) == 1
|
||||
assert sheerka.isinstance(res[0].body[0], "two")
|
||||
|
||||
res = sheerka.evaluate_user_input("x | where(__self=two)")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert isinstance(res[0].body, list)
|
||||
assert len(res[0].body) == 1
|
||||
assert sheerka.isinstance(res[0].body[0], "two")
|
||||
|
||||
def test_i_can_filter_using_sheerka_methods(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept number",
|
||||
"set_isa(one, number)",
|
||||
"add_to_memory('x', [one])"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
res = sheerka.evaluate_user_input("x | where('isa(self, number)')")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert isinstance(res[0].body, list)
|
||||
assert len(res[0].body) == 1
|
||||
assert sheerka.isinstance(res[0].body[0], "one")
|
||||
|
||||
def test_i_can_select_properties(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept two as 2",
|
||||
"def concept three as 3",
|
||||
"add_to_memory('x', [one, two, three])"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("x | select('id', 'name')")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == (("1001", "one"), ("1002", "two"), ("1003", "three"))
|
||||
|
||||
res = sheerka.evaluate_user_input("x | select(p1='id', p2='name')")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == ({"p1": "1001", "p2": "one"},
|
||||
{"p1": "1002", "p2": "two"},
|
||||
{"p1": "1003", "p2": "three"})
|
||||
|
||||
def test_i_can_collect_properties(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept isa from x is a y def_var x def_var y",
|
||||
"def concept plus from a plus b as a + b",
|
||||
"add_to_memory('x', [one, isa, plus])"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
res = sheerka.evaluate_user_input("x | props()")
|
||||
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, BuiltinConcepts.TO_DICT)
|
||||
assert res[0].body.body == {'isa': ['body', 'id', 'key', 'name', 'x', 'y'],
|
||||
'one': ['body', 'id', 'key', 'name'],
|
||||
'plus': ['a', 'b', 'body', 'id', 'key', 'name']}
|
||||
@@ -5,7 +5,7 @@ from evaluators.PythonEvaluator import PythonEvalError
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
|
||||
class TestSheerkaNonRegDisplay(TestUsingMemoryBasedSheerka):
|
||||
class TestSheerkaNonRegRules(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_i_can_apply_simple_rule(self):
|
||||
|
||||
Reference in New Issue
Block a user