First implementation of questions management

This commit is contained in:
2020-08-14 08:16:33 +02:00
parent e84b394da2
commit 351c16f946
47 changed files with 1582 additions and 400 deletions
+76
View File
@@ -1015,6 +1015,82 @@ as:
assert res[0].status
assert res[0].body == "Executed !"
def test_i_can_manage_question(self):
init = [
"def concept one",
"def concept foo",
"def concept number",
"one isa number",
"def concept x is a y as isa(x,y) pre in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)",
"def concept x is a y as set_isa(x,y)",
]
sheerka = self.init_scenario(init)
res = sheerka.evaluate_user_input("question(one is a number)") # automatically evaluated
assert len(res) == 1
assert res[0].status
assert res[0].body
res = sheerka.evaluate_user_input("question(foo is a number)") # automatically evaluated
assert len(res) == 1
assert res[0].status
assert not res[0].body
def test_where_clause_implicitly_infer_to_question(self):
init = [
"def concept one as 1",
"def concept number",
"one isa number",
"def concept one as 10", # to make sure that it won't be rejected because of the cast
"def concept x is a y as isa(x,y) pre in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)",
"def concept x is a y as set_isa(x,y)",
]
# Explanations
# There are two concepts 'one'. The first one is tagged as a number while the second one is not
# 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)
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
assert sheerka.isinstance(res[0].body, BuiltinConcepts.NEW_CONCEPT)
# Let's check that the concept is correctly understood
res = sheerka.evaluate_user_input("eval one plus 2")
assert len(res) == 1
assert res[0].status
assert res[0].body == 3 # it means that the first 'one' was chosen
def test_i_can_manage_concept_that_refers_to_question(self):
init = [
"def concept one",
"def concept foo",
"def concept number",
"one isa number",
"def concept q from q ? as question(q)",
"def concept is_a from x is a y as isa(x,y) pre in_context(BuiltinConcepts.EVAL_QUESTION_REQUESTED)",
"set_is_greater_than(BuiltinConcepts.PRECEDENCE, c:is_a:, c:q:)"
]
sheerka = self.init_scenario(init)
res = sheerka.evaluate_user_input("one is a number ?") # automatically evaluated
assert len(res) == 1
assert res[0].status
assert res[0].body
res = sheerka.evaluate_user_input("foo is a number ?") # automatically evaluated
assert len(res) == 1
assert res[0].status
assert not res[0].body
# Sanity, when there is only one 'is a' concept. It's chosen regardless of the PRE condition
res = sheerka.evaluate_user_input("one is a number")
assert len(res) == 1
assert res[0].status
assert res[0].body
class TestSheerkaNonRegFile(TestUsingFileBasedSheerka):
def test_i_can_def_several_concepts(self):