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:
@@ -86,15 +86,46 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_isa(self):
|
||||
sheerka, context, blue, color = self.init_concepts(Concept("blue"), Concept("color"))
|
||||
|
||||
assert not sheerka.isa(blue, color)
|
||||
|
||||
sheerka.set_isa(context, blue, color)
|
||||
assert sheerka.isa(blue, color)
|
||||
blue_instance = sheerka.new("blue")
|
||||
assert not sheerka.isa(blue_instance, color)
|
||||
|
||||
sheerka.set_isa(context, blue_instance, color)
|
||||
assert sheerka.isa(blue_instance, color)
|
||||
|
||||
# isa tests the id of a concept, not it's content
|
||||
another_color_instance_but_with_a_body = sheerka.new(color, body="a body")
|
||||
assert sheerka.isa(blue, another_color_instance_but_with_a_body)
|
||||
assert sheerka.isa(blue_instance, another_color_instance_but_with_a_body)
|
||||
|
||||
# isa, when EVAL_GLOBAL_TRUTH_REQUESTED is not activated, only affect the current concept
|
||||
another_blue_instance = sheerka.new("blue")
|
||||
assert not sheerka.isa(another_blue_instance, color)
|
||||
|
||||
# when EVAL_GLOBAL_TRUTH_REQUESTED is not activated, color is not a set
|
||||
assert not sheerka.isinset(blue_instance, color)
|
||||
assert not sheerka.isaset(context, color)
|
||||
|
||||
def test_isa_global_truth(self):
|
||||
sheerka, context, blue, color = self.init_concepts(Concept("blue"), Concept("color"))
|
||||
|
||||
blue_instance = sheerka.new("blue")
|
||||
assert not sheerka.isa(blue_instance, color)
|
||||
assert not sheerka.isaset(context, color)
|
||||
assert not sheerka.isinset(blue_instance, color)
|
||||
|
||||
context.add_to_private_hints(BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED)
|
||||
|
||||
sheerka.set_isa(context, blue_instance, color)
|
||||
assert sheerka.isa(blue_instance, color)
|
||||
assert sheerka.isaset(context, color)
|
||||
assert sheerka.isinset(blue_instance, color)
|
||||
|
||||
# all blue instances are now a color
|
||||
another_blue_instance = sheerka.new("blue")
|
||||
assert sheerka.isa(another_blue_instance, color)
|
||||
assert sheerka.isaset(context, color)
|
||||
assert sheerka.isinset(another_blue_instance, color)
|
||||
|
||||
def test_isaset(self):
|
||||
sheerka, context, group, foo = self.init_concepts(Concept("group"), Concept("foo"))
|
||||
@@ -246,13 +277,28 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
|
||||
foo = sheerka.new(foo.key) # new instance
|
||||
sheerka.set_isa(context, foo, all_foo)
|
||||
sheerka.set_isa(context, foo, all_bar)
|
||||
|
||||
assert foo.get_prop(BuiltinConcepts.ISA) == {all_foo, all_bar}
|
||||
assert sheerka.isa(foo, all_foo)
|
||||
assert sheerka.isa(foo, all_bar)
|
||||
|
||||
def test_a_concept_can_be_in_multiple_sets_when_global_truth_is_activated(self):
|
||||
sheerka, context, foo, all_foo, all_bar = self.init_test(global_truth=True).with_concepts(
|
||||
Concept("foo"),
|
||||
Concept("all_foo"),
|
||||
Concept("all_bar"),
|
||||
create_new=True).unpack()
|
||||
|
||||
foo = sheerka.new(foo.key) # new instance
|
||||
sheerka.set_isa(context, foo, all_foo)
|
||||
foo = sheerka.new(foo.key) # new instance
|
||||
sheerka.set_isa(context, foo, all_bar)
|
||||
|
||||
assert foo.get_prop(BuiltinConcepts.ISA) == {all_foo, all_bar}
|
||||
assert sheerka.isa(foo, all_foo)
|
||||
assert sheerka.isa(foo, all_bar)
|
||||
|
||||
assert sheerka.isinset(foo, all_foo)
|
||||
assert sheerka.isinset(foo, all_bar)
|
||||
assert sheerka.isaset(context, all_foo)
|
||||
@@ -270,6 +316,25 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
Concept("baz"),
|
||||
)
|
||||
|
||||
sheerka.set_isa(context, foo, bar)
|
||||
sheerka.set_isa(context, bar, baz)
|
||||
|
||||
assert sheerka.isa(foo, bar)
|
||||
assert sheerka.isa(bar, baz)
|
||||
assert sheerka.isa(foo, baz)
|
||||
|
||||
def test_i_can_manage_isa_transitivity_when_global_truth_is_activated(self):
|
||||
"""
|
||||
if foo isa bar and bar isa baz, then foo isa baz
|
||||
:return:
|
||||
"""
|
||||
|
||||
sheerka, context, foo, bar, baz = self.init_test(global_truth=True).with_concepts(
|
||||
Concept("foo"),
|
||||
Concept("bar"),
|
||||
Concept("baz"),
|
||||
).unpack()
|
||||
|
||||
sheerka.set_isa(context, sheerka.new("foo"), bar)
|
||||
sheerka.set_isa(context, sheerka.new("bar"), baz)
|
||||
|
||||
@@ -278,11 +343,11 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
assert sheerka.isa(sheerka.new("foo"), baz)
|
||||
|
||||
def test_i_cannot_manage_isa_transitivity_when_using_body(self):
|
||||
sheerka, context, one, another_one, number = self.init_concepts(
|
||||
sheerka, context, one, another_one, number = self.init_test(global_truth=True).with_concepts(
|
||||
"one",
|
||||
Concept("another one", body="one"),
|
||||
"number"
|
||||
)
|
||||
).unpack()
|
||||
|
||||
sheerka.set_isa(context, sheerka.new("one"), number)
|
||||
|
||||
@@ -290,7 +355,10 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
assert not sheerka.isa(another_one, number) # Correct this misbehaviour when BuiltinConcepts.IS is implemented
|
||||
|
||||
def test_concepts_in_group_cache_is_updated(self):
|
||||
sheerka, context, one, two, number = self.init_concepts("one", "two", "number")
|
||||
sheerka, context, one, two, number = self.init_test(global_truth=True).with_concepts(
|
||||
"one",
|
||||
"two",
|
||||
"number").unpack()
|
||||
|
||||
sheerka.set_isa(context, sheerka.new("one"), number)
|
||||
|
||||
@@ -315,12 +383,12 @@ class TestSheerkaIsAManager(TestUsingMemoryBasedSheerka):
|
||||
assert number.id not in sheerka.get_concepts_bnf_definitions()
|
||||
|
||||
def test_i_can_get_and_set_isa_when_multiple_ontology_layers(self):
|
||||
sheerka, context, foo, group1, group2 = self.init_concepts(
|
||||
sheerka, context, foo, group1, group2 = self.init_test(global_truth=True).with_concepts(
|
||||
Concept("foo"),
|
||||
Concept("group1"),
|
||||
Concept("group2"),
|
||||
cache_only=False
|
||||
)
|
||||
).unpack()
|
||||
|
||||
sheerka.set_isa(context, foo, group1)
|
||||
|
||||
@@ -401,10 +469,10 @@ class TestSheerkaSetsManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka):
|
||||
}
|
||||
|
||||
def test_i_can_set_isa(self):
|
||||
sheerka, context, foo, bar, group = self.init_test().with_concepts("foo",
|
||||
"bar",
|
||||
"group",
|
||||
).unpack()
|
||||
sheerka, context, foo, bar, group = self.init_test(global_truth=True).with_concepts("foo",
|
||||
"bar",
|
||||
"group",
|
||||
).unpack()
|
||||
|
||||
# nothing was previously in ISA
|
||||
foo = sheerka.new(foo.key)
|
||||
|
||||
Reference in New Issue
Block a user