Fixed #100 : SheerkaAdmin: Add builtins() command
Fixed #99 : SheerkaQueryManager: I can manage contains predicate when filtering objects Fixed #97 : ERROR: list indices must be integers or slices, not Concept Fixed #96 : SequenceNodeParser: SequenceNodeParser must correctly handle concept definition Fixed #95 : ResolveAmbiguity must not remove concepts that do not require evaluation Fixed #94 : Concepts with the same key are lost when new ontology Fixed #93 : Introduce BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED Fixed #92 : ExpressionParser: Implement compile_disjunctions() Fixed #91 : Implement get_concepts_complexity(context, concepts, concept_parts) Fixed #90 : ResolveAmbiguity : where predicate is not used to resolve ambiguity Fixed #89 : ResolveAmbiguityEvaluator: Concepts embedded in ConceptNode are not resolved Fixed #88: SyaNodeParser: Parse multiple parameters when some of the are not recognized Fixed #87: SyaNodeParser : Parse the multiple parameters
This commit is contained in:
@@ -362,6 +362,7 @@ as:
|
||||
])
|
||||
def test_i_can_mix_concept_with_python_to_define_numbers(self, desc, definitions):
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.add_to_context(BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED)
|
||||
|
||||
for definition in definitions:
|
||||
sheerka.evaluate_user_input(definition)
|
||||
@@ -396,6 +397,7 @@ as:
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == 23
|
||||
sheerka.remove_fom_context(BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED)
|
||||
|
||||
def test_i_can_mix_bnf_and_isa(self):
|
||||
"""
|
||||
@@ -406,8 +408,8 @@ as:
|
||||
sheerka.evaluate_user_input("def concept one as 1")
|
||||
sheerka.evaluate_user_input("def concept two as 2")
|
||||
sheerka.evaluate_user_input("def concept number")
|
||||
sheerka.evaluate_user_input("set_isa(one, number)")
|
||||
sheerka.evaluate_user_input("set_isa(two, number)")
|
||||
sheerka.evaluate_user_input("global_truth(set_isa(one, number))")
|
||||
sheerka.evaluate_user_input("global_truth(set_isa(two, number))")
|
||||
sheerka.evaluate_user_input("def concept twenties from bnf 'twenty' number as 20 + number")
|
||||
|
||||
res = sheerka.evaluate_user_input("twenty one")
|
||||
@@ -443,6 +445,7 @@ as:
|
||||
|
||||
def test_i_can_mix_bnf_and_isa_2(self):
|
||||
sheerka = self.get_sheerka()
|
||||
sheerka.add_to_context(BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED)
|
||||
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
@@ -460,6 +463,7 @@ as:
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].body == 21
|
||||
sheerka.remove_fom_context(BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED)
|
||||
|
||||
def test_i_can_use_concepts_defined_with_from(self):
|
||||
sheerka = self.get_sheerka()
|
||||
@@ -565,7 +569,7 @@ as:
|
||||
"def concept plus_one from bnf number=n1 'plus_one' as n1 + 1",
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(definitions)
|
||||
sheerka = self.init_scenario(definitions, global_truth=True)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval two plus_one")
|
||||
assert len(res) == 1
|
||||
@@ -642,8 +646,6 @@ as:
|
||||
assert res[0].body == 21
|
||||
|
||||
def test_i_can_use_where_in_bnf(self):
|
||||
sheerka, context = self.init_test().unpack()
|
||||
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept two as 2",
|
||||
@@ -656,8 +658,8 @@ as:
|
||||
"def concept twenties from bnf twenty number where number <= 2 as twenty + number"
|
||||
]
|
||||
|
||||
for exp in init:
|
||||
sheerka.evaluate_user_input(exp)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
context = self.get_context(sheerka)
|
||||
|
||||
res = sheerka.evaluate_user_input("twenty one")
|
||||
assert len(res) == 1
|
||||
@@ -765,7 +767,7 @@ as:
|
||||
sheerka.evaluate_user_input("def concept two as 2")
|
||||
sheerka.evaluate_user_input("def concept twenties from bnf 'twenty' (one|two)=unit as 20 + unit")
|
||||
|
||||
res = sheerka.evaluate_user_input("set_isa(twenties, number)")
|
||||
res = sheerka.evaluate_user_input("global_truth(set_isa(twenties, number))")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
|
||||
@@ -946,7 +948,7 @@ as:
|
||||
"set_isa(twenties, number)",
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
|
||||
# simulate that sheerka was stopped and restarted
|
||||
sheerka.clear_bnf_definition()
|
||||
@@ -967,8 +969,8 @@ as:
|
||||
res = sheerka.evaluate_user_input("set_isa(last_created_concept(), number)")
|
||||
|
||||
assert res[0].status
|
||||
assert sheerka.isinstance(res[0].body, BuiltinConcepts.SUCCESS)
|
||||
assert sheerka.isa(sheerka.new("one"), sheerka.new("number"))
|
||||
assert sheerka.isinstance(res[0].body, "one")
|
||||
assert sheerka.isa(res[0].body, sheerka.new("number"))
|
||||
|
||||
def test_i_can_evaluate_sya_and_ret_concepts(self):
|
||||
init = [
|
||||
@@ -1001,7 +1003,7 @@ as:
|
||||
# Since command is a __COMMAND, the body is auto evaluated
|
||||
# and we return the body, not the concept
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
res = sheerka.evaluate_user_input("command")
|
||||
assert res[0].status
|
||||
assert res[0].body == "Executed !"
|
||||
@@ -1016,7 +1018,7 @@ as:
|
||||
"def concept x is a y as set_isa(x,y)",
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
res = sheerka.evaluate_user_input("question(one is a number)") # automatically evaluated
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
@@ -1042,7 +1044,7 @@ as:
|
||||
# So the first one should be picked.
|
||||
# the second concept 'one' 's value is an integer, to make sure that it won't be rejected because of its type
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
res = sheerka.evaluate_user_input("def concept x plus y where x is a number as x + y")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
@@ -1065,7 +1067,7 @@ as:
|
||||
"set_is_greater_than(BuiltinConcepts.PRECEDENCE, c:is_a:, c:q:, 'Sya')",
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
res = sheerka.evaluate_user_input("one is a number ?") # automatically evaluated
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
@@ -1133,7 +1135,7 @@ as:
|
||||
res = sheerka.evaluate_user_input("twenty one")
|
||||
assert len(res) > 1 # not recognized
|
||||
|
||||
sheerka.evaluate_user_input("set_isa(one, number)")
|
||||
sheerka.evaluate_user_input("global_truth(set_isa(one, number))")
|
||||
res = sheerka.evaluate_user_input("twenty one")
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
@@ -1252,9 +1254,9 @@ as:
|
||||
"def concept two",
|
||||
"def concept number",
|
||||
"def concept nb times from bnf number 'times'",
|
||||
"set_isa(two, number)",
|
||||
"set_isa(two, number)", # defined after 'nb times'
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
|
||||
res = sheerka.evaluate_user_input("two times")
|
||||
|
||||
@@ -1270,7 +1272,7 @@ as:
|
||||
"def concept cars",
|
||||
"def concept quantify x from bnf number x as set_attr(x, 'qty', number) ret x"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval two cars")
|
||||
|
||||
@@ -1287,7 +1289,7 @@ as:
|
||||
"def concept cars",
|
||||
"def concept quantify x from bnf number=n1 x as set_attr(x, 'qty', n1) ret x"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval two cars")
|
||||
|
||||
@@ -1317,7 +1319,7 @@ as:
|
||||
"def concept she ret memory('isa(self, female)')",
|
||||
"girl"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
context = self.get_context(sheerka)
|
||||
|
||||
res = sheerka.evaluate_user_input("set_attr(she, 'my_attr', 'my value')")
|
||||
@@ -1337,7 +1339,7 @@ as:
|
||||
"def concept x attribute y equals z as set_attr(x, y, z)",
|
||||
"girl"
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
context = self.get_context(sheerka)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval she attribute 'my_attr' equals 'my value'")
|
||||
@@ -1392,7 +1394,7 @@ as:
|
||||
"def concept qualify x from bnf adjective x as set_attr(x, c:adjective:, adjective) ret x",
|
||||
"eval a red short",
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
|
||||
res = sheerka.evaluate_user_input("what is the color of the short ?")
|
||||
assert len(res) == 1
|
||||
|
||||
@@ -13,6 +13,34 @@ class TestSheerkaNonRegMemory2(TestUsingMemoryBasedSheerka):
|
||||
|
||||
res = sheerka.evaluate_user_input("question(foo is a foo)")
|
||||
|
||||
# assert len(res) == 1
|
||||
# assert res[0].status
|
||||
# assert res[0].value
|
||||
assert len(res) == 1
|
||||
assert res[0].status
|
||||
assert res[0].value # value is True since 'x is a foo' was chosen
|
||||
|
||||
def test_i_can_select_the_correct_concept_vs_bnf(self):
|
||||
init = [
|
||||
"def concept one as 1",
|
||||
"def concept two as 2",
|
||||
"def concept twenties from bnf 'twenty' (one|two)=unit as 20 + unit",
|
||||
"def concept twenty two as 'specific occurrence'",
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("eval twenty one")
|
||||
assert res[0].value == 21
|
||||
|
||||
res = sheerka.evaluate_user_input("eval twenty two")
|
||||
assert res[0].value == "specific occurrence" # thanks to ExactConceptParser
|
||||
|
||||
def test_i_can_use_global_truth_when_calling_a_concept(self):
|
||||
init = [
|
||||
"def concept one",
|
||||
"def concept number",
|
||||
"def concept x is a y as set_isa(x, y)",
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
|
||||
res = sheerka.evaluate_user_input("global_truth(one is a number)")
|
||||
|
||||
assert res[0].status
|
||||
assert sheerka.isa(sheerka.new("one"), sheerka.new("number"))
|
||||
|
||||
@@ -85,7 +85,7 @@ class TestSheerkaNonRegFile(TestUsingFileBasedSheerka):
|
||||
"set_isa(thirty, number)",
|
||||
"def concept thirties from bnf thirty number where number < 10 as thirty + number",
|
||||
"set_isa(thirties, number)",
|
||||
])
|
||||
], global_truth=True)
|
||||
|
||||
sheerka = self.new_sheerka_instance()
|
||||
|
||||
|
||||
@@ -53,6 +53,45 @@ post : None
|
||||
ret : None
|
||||
vars : []
|
||||
props : {}
|
||||
"""
|
||||
|
||||
def test_i_can_display_multiple_concepts_description_when_concept_definition(self, capsys):
|
||||
init = [
|
||||
"def concept foo as 1",
|
||||
"def concept foo as 2 where True",
|
||||
]
|
||||
sheerka = self.init_scenario(init)
|
||||
capsys.readouterr()
|
||||
|
||||
sheerka.enable_process_return_values = True
|
||||
sheerka.evaluate_user_input("desc(c:foo:)")
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out == """id : 1001
|
||||
name : foo
|
||||
key : foo
|
||||
definition: None
|
||||
type : None
|
||||
hash : 16f7fbb8bc509b8c652edaf3d0c0457d15a37f0a862fbe03fa357b0c77249c46
|
||||
body : 1
|
||||
where : None
|
||||
pre : None
|
||||
post : None
|
||||
ret : None
|
||||
vars : []
|
||||
props : {}
|
||||
id : 1002
|
||||
name : foo
|
||||
key : foo
|
||||
definition: None
|
||||
type : None
|
||||
hash : e8dd1af1b6bc0eca0fb4a87a6fabb16655caa4b7a6ea9dbbd1f887757e6caf89
|
||||
body : 2
|
||||
where : True
|
||||
pre : None
|
||||
post : None
|
||||
ret : None
|
||||
vars : []
|
||||
props : {}
|
||||
"""
|
||||
|
||||
def test_i_can_describe_a_rule(self, capsys):
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestSheerkaNonRegPipeFunctions(TestUsingMemoryBasedSheerka):
|
||||
"add_to_memory('x', [one])"
|
||||
]
|
||||
|
||||
sheerka = self.init_scenario(init)
|
||||
sheerka = self.init_scenario(init, global_truth=True)
|
||||
res = sheerka.evaluate_user_input("x | where('isa(self, number)')")
|
||||
|
||||
assert len(res) == 1
|
||||
|
||||
Reference in New Issue
Block a user