Fixed #49 : working
This commit is contained in:
@@ -1085,40 +1085,10 @@ isinstance(var, Concept) and var.key == 'hello __var__0'""" + \
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'"]
|
||||
),
|
||||
(
|
||||
"recognize by name and variable sheerka",
|
||||
"recognize(__ret.body, greetings, a=sheerka)",
|
||||
"sheerka",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'",
|
||||
"#__x_01__|a|'__sheerka__'"]
|
||||
),
|
||||
(
|
||||
"recognize by name and str variable",
|
||||
"recognize(__ret.body, greetings, a='my friend')",
|
||||
"'my friend'",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'",
|
||||
"#__x_01__|a|'my friend'"]
|
||||
),
|
||||
(
|
||||
"recognize by name and concept variable",
|
||||
"recognize(__ret.body, greetings, a=foo)",
|
||||
"foo",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'",
|
||||
"#__x_01__|a.name|'foo'"]
|
||||
),
|
||||
(
|
||||
"recognize by name and add other conditions (str)",
|
||||
"recognize(__ret.body, greetings) and __ret.body.a == 'my friend'",
|
||||
"foo",
|
||||
"my friend",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
@@ -1128,12 +1098,12 @@ isinstance(var, Concept) and var.key == 'hello __var__0'""" + \
|
||||
(
|
||||
"recognize by name and add other conditions (sheerka)",
|
||||
"recognize(__ret.body, greetings) and __ret.body.a == sheerka",
|
||||
"foo",
|
||||
"sheerka",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'",
|
||||
"#__x_01__|a|'kodjo'"]
|
||||
"#__x_01__|a|'__sheerka__'"]
|
||||
),
|
||||
(
|
||||
"recognize by name and add other conditions (concept)",
|
||||
@@ -1143,8 +1113,21 @@ isinstance(var, Concept) and var.key == 'hello __var__0'""" + \
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|name|'greetings'",
|
||||
"#__x_01__|a|'kodjo'"]
|
||||
"#__x_01__|a|#__x_02__",
|
||||
"#__x_02__|__is_concept__|True",
|
||||
"#__x_02__|name|'foo'"]
|
||||
),
|
||||
(
|
||||
"recognize by instance",
|
||||
"recognize(__ret.body, hello sheerka)",
|
||||
"foo",
|
||||
["#__x_00__|__name__|'__ret'",
|
||||
"#__x_00__|body|#__x_01__",
|
||||
"#__x_01__|__is_concept__|True",
|
||||
"#__x_01__|key|'hello __var__0'",
|
||||
"#__x_01__|a|__sheerka__"]
|
||||
),
|
||||
|
||||
])
|
||||
def test_i_can_get_rete_conditions_from_recognized(self, test_name, expression, variable_name, expected_as_str):
|
||||
sheerka, context, greetings, foo = self.init_test().with_concepts(
|
||||
@@ -1173,7 +1156,7 @@ isinstance(var, Concept) and var.key == 'hello __var__0'""" + \
|
||||
rule.rete_disjunctions = conditions
|
||||
network.add_rule(rule)
|
||||
|
||||
variable = foo if variable_name == "foo" else variable_name
|
||||
variable = foo if variable_name == "foo" else sheerka if variable_name == "sheerka" else variable_name
|
||||
to_recognize = sheerka.new_from_template(greetings, greetings.key, a=variable)
|
||||
network.add_obj("__ret", ReturnValueConcept("Test", True, to_recognize))
|
||||
matches = list(network.matches)
|
||||
|
||||
@@ -134,7 +134,7 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_adding_obj_when_requested_attribute_is_not_found(self):
|
||||
"""
|
||||
When a rule with attribute constraint, we only add the requested attributes
|
||||
There is no error when an attribute does not exits
|
||||
"""
|
||||
network = ReteNetwork()
|
||||
ret = ReturnValueConcept("test", True, "value")
|
||||
@@ -218,6 +218,35 @@ class TestReteNetwork(TestUsingMemoryBasedSheerka):
|
||||
assert matches[0].pnode.rules == [rule]
|
||||
assert network.facts == {'f-00000': ret}
|
||||
|
||||
def test_i_can_add_obj_and_match_obj_when_value_is_sheerka(self):
|
||||
sheerka, context, greetings = self.init_concepts(
|
||||
Concept("greetings", definition="hello a", definition_type=DEFINITION_TYPE_DEF).def_var("a")
|
||||
)
|
||||
network = ReteNetwork()
|
||||
rule = RuleForTestingRete(AndConditions([Condition(V("ret"), "__name__", "__ret"),
|
||||
Condition(V("ret"), "body", V("body")),
|
||||
Condition(V("body"), "name", "greetings"),
|
||||
Condition(V("body"), "a", "__sheerka__"),
|
||||
]))
|
||||
network.add_rule(rule)
|
||||
|
||||
hello_concept = sheerka.new(greetings, a=sheerka)
|
||||
ret = ReturnValueConcept("test", True, hello_concept)
|
||||
network.add_obj("__ret", ret)
|
||||
|
||||
assert network.working_memory == {
|
||||
WME("f-00000", "__name__", "__ret"),
|
||||
WME("f-00000", "body", "f-00000.body"),
|
||||
WME("f-00000.body", "name", "greetings"),
|
||||
WME("f-00000.body", "a", "__sheerka__"),
|
||||
}
|
||||
|
||||
# sanity check that the WME produced match the condition
|
||||
matches = list(network.matches)
|
||||
assert len(matches) == 1
|
||||
assert matches[0].pnode.rules == [rule]
|
||||
assert network.facts == {'f-00000': ret}
|
||||
|
||||
def test_i_can_distinguish_objects_with_different_value(self):
|
||||
network = ReteNetwork()
|
||||
rule = RuleForTestingRete(AndConditions([
|
||||
|
||||
Reference in New Issue
Block a user