54e5681c5a
Fixed #110 : SheerkaDebugManager: add list_debug_settings Fixed #111 : SheerkaDebugManager: Implement ListDebugLogger Fixed #112 : SyaNodeParser: rewrite this parser Fixed #113 : Sheerka.: Add enable_parser_caching to disable parsers caching Fixed #114 : SyaNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #115 : BnfNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #116 : SequenceNodeParser : Implement fast cache to resolve unrecognized tokens requests Fixed #117 : ResolveMultiplePluralAmbiguityEvaluator: Resolve Multiple plural ambiguity
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
|
|
|
|
|
class TestSheerkaNonRegMemory2(TestUsingMemoryBasedSheerka):
|
|
|
|
def test_i_can_select_the_correct_concept_when_ambiguity(self):
|
|
init = [
|
|
"def concept foo",
|
|
"def concept x is a y pre is_question() as isa(x,y)",
|
|
"def concept x is a foo pre is_question() as isinstance(x, foo)",
|
|
]
|
|
sheerka = self.init_scenario(init)
|
|
|
|
res = sheerka.evaluate_user_input("question(foo is a foo)")
|
|
|
|
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"))
|
|
|
|
def test_i_can_get_sequence_when_evaluation_plural(self):
|
|
init = [
|
|
"def concept one",
|
|
"def concept two",
|
|
"def concept number",
|
|
"global_truth(set_isa(one, number))",
|
|
"global_truth(set_isa(two, number))",
|
|
]
|
|
sheerka = self.init_scenario(init)
|
|
|
|
res = sheerka.evaluate_user_input("eval numbers")
|
|
|
|
assert res[0].status
|
|
assert set(res[0].body) == {sheerka.new("one"), sheerka.new("two")}
|
|
|
|
def test_i_can_use_list_comprehension(self):
|
|
init = [
|
|
"def concept rex",
|
|
"def concept rantanplan",
|
|
"def concept dog",
|
|
"def concept x is a y as set_isa(x, y)",
|
|
]
|
|
sheerka = self.init_scenario(init)
|
|
|
|
res = sheerka.evaluate_user_input("global_truth([ x is a dog for x in [rex, rantanplan]])")
|
|
|
|
assert len(res) == 1
|
|
assert res[0].status
|
|
|
|
rex = sheerka.new("rex")
|
|
dog = sheerka.new("dog")
|
|
assert sheerka.isa(rex, dog)
|