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:
2021-07-31 08:52:00 +02:00
parent 7dcaa9c111
commit e69745adc8
70 changed files with 1561 additions and 455 deletions
+81
View File
@@ -709,6 +709,65 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
self.compare_results(res, expected_sequences, cmap, expression)
@pytest.mark.parametrize("expression, expected", [
("suffixed2 a b", ['a', 'b', "suffixed2"]),
("suffixed3 a b c", ['a', 'b', 'c', "suffixed3"]),
("a b prefixed2", ['a', 'b', "prefixed2"]),
("a b c prefixed3", ['a', 'b', 'c', "prefixed3"]),
("start2 a b stop", ['a', 'b', "start2"]),
("start3 a b c stop", ['a', 'b', 'c', "start3"]),
])
def test_i_can_post_fix_when_multiple_parameters_are_expected(self, expression, expected):
concepts_map = {
"a": Concept("a"),
"b": Concept("b"),
"c": Concept("c"),
"suffixed2": Concept("suffixed2 x y").def_var("x").def_var("y"),
"suffixed3": Concept("suffixed3 x y z").def_var("x").def_var("y").def_var("z"),
"prefixed2": Concept("x y prefixed2").def_var("x").def_var("y"),
"prefixed3": Concept("x y z prefixed3").def_var("x").def_var("y").def_var("z"),
"start2": Concept("start2 x y stop").def_var("x").def_var("y"),
"start3": Concept("start3 x y z stop").def_var("x").def_var("y").def_var("z"),
}
sheerka, context, parser = self.init_parser(concepts_map, None)
res = parser.infix_to_postfix(context, ParserInput(expression))
expected_array = compute_expected_array(concepts_map, expression, expected)
assert len(res) == 1
transformed_out = get_test_obj(res[0].out, expected_array)
assert transformed_out == expected_array
@pytest.mark.parametrize("expression, expected", [
("suffixed3 x y z", ['x', 'y', 'z', "suffixed3"]),
("suffixed3 a y z", ['a', 'y', 'z', "suffixed3"]),
("suffixed3 x a z", ['x ', 'a', ' z', "suffixed3"]), # this one was not managed by the second chance
("suffixed3 x y a", ['x', 'y', 'a', "suffixed3"]),
("x y z prefixed3", ['x', 'y', 'z', "prefixed3"]),
("a y z prefixed3", ['a', 'y', 'z', "prefixed3"]),
("x a z prefixed3", ['x ', 'a', ' z', "prefixed3"]),
("x y a prefixed3", ['x', 'y', 'a', "prefixed3"]),
("start3 x y z stop", ['x', 'y', 'z', "start3"]),
("start3 a y z stop", ['a', 'y', 'z', "start3"]),
("start3 x a z stop", ['x ', 'a', ' z ', "start3"]),
("start3 x y a stop", ['x', 'y', 'a', "start3"]),
])
def test_i_can_post_fix_when_multiple_parameters_are_expected_but_unrecognized_tokens(self, expression, expected):
concepts_map = {
"a": Concept("a"),
"suffixed3": Concept("suffixed3 x y z").def_var("x").def_var("y").def_var("z"),
"prefixed3": Concept("x y z prefixed3").def_var("x").def_var("y").def_var("z"),
"start3": Concept("start3 x y z stop").def_var("x").def_var("y").def_var("z"),
}
sheerka, context, parser = self.init_parser(concepts_map, None)
res = parser.infix_to_postfix(context, ParserInput(expression))
expected_array = compute_expected_array(concepts_map, expression, expected)
assert len(res) == 1
transformed_out = get_test_obj(res[0].out, expected_array)
assert transformed_out == expected_array
@pytest.mark.parametrize("expression, expected", [
("(", ("(", 0)),
("one plus ( 1 + ", ("(", 4)),
@@ -1080,6 +1139,28 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
assert isinstance(concept_plus_b[0].body.body, PythonNode)
assert concept_suffixed_a == cmap["two"]
@pytest.mark.parametrize("text, expected", [
("suffixed3 a b c", [("x", "a"), ("y", "b"), ("z", "c")]),
("a b c prefixed3", [("x", "a"), ("y", "b"), ("z", "c")]),
("start3 a b c stop", [("x", "a"), ("y", "b"), ("z", "c")]),
])
def test_i_can_parse_when_multiple_parameters_are_expected(self, text, expected):
concepts_map = {
"a": Concept("a"),
"b": Concept("b"),
"c": Concept("c"),
"suffixed3": Concept("suffixed3 x y z").def_var("x").def_var("y").def_var("z"),
"prefixed3": Concept("x y z prefixed3").def_var("x").def_var("y").def_var("z"),
"start3": Concept("start3 x y z stop").def_var("x").def_var("y").def_var("z"),
}
sheerka, context, parser = self.init_parser(concepts_map, None)
res = parser.parse(context, ParserInput(text))
lexer_nodes = res.body.body
assert res.status
assert lexer_nodes[0].concept.get_metadata().variables == expected
@pytest.mark.parametrize("text", [
"function(suffixed one)",
"function(one plus two mult three)",