Fixed #61 : SheerkaDebugManager: Add get_value()

Fixed #60 : Hash error when ReturnValue is a list of list
Fixed #59 : Implement smart_get()
Fixed #58 : SheerkaPromptCompleter: Cannot parse concept token
Fixed #57 : SheerkaPrompt: Add concept autocompletion
Fixed #56 : automatically backup command
Fixed #54 : I can record execution status
Fixed #53 : ConceptManager: modify_concept fails
This commit is contained in:
2021-04-09 15:47:32 +02:00
parent 6cda2686fb
commit dd3d8f4abe
37 changed files with 1055 additions and 191 deletions
+169 -1
View File
@@ -840,7 +840,8 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
assert sheerka.isinstance(res.body, BuiltinConcepts.SUCCESS)
assert sheerka.get_property(foo_instance, BuiltinConcepts.ASSOCIATIVITY) == SyaAssociativity.Left
res = sheerka.set_property(context, foo_instance, sheerka.new(BuiltinConcepts.ASSOCIATIVITY), SyaAssociativity.Right)
res = sheerka.set_property(context, foo_instance, sheerka.new(BuiltinConcepts.ASSOCIATIVITY),
SyaAssociativity.Right)
assert res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.SUCCESS)
assert sheerka.get_property(foo_instance, BuiltinConcepts.ASSOCIATIVITY) == SyaAssociativity.Right
@@ -1235,6 +1236,173 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
assert sheerka.chicken_and_eggs.get(two.id) == {one.id, two.id, three.id}
assert sheerka.chicken_and_eggs.get(three.id) == {one.id, two.id, three.id}
def test_i_can_smart_get_attr_when_the_value_is_known(self):
sheerka, context = self.init_concepts()
foo = Concept("foo")
prop = Concept("property")
bar = Concept("bar")
sheerka.set_attr(foo, prop, bar)
assert sheerka.smart_get_attr(foo, prop) == bar
def test_i_can_smart_get_attr_when_simple_isa(self):
sheerka, context, adjective, color, red, table = self.init_concepts("adjective",
"color",
"red",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
color_instance = sheerka.new(color, body=red)
adjective_instance = sheerka.new(adjective, body=color_instance)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, adjective, adjective_instance)
assert sheerka.smart_get_attr(table_instance, color) == color_instance
assert sheerka.objvalue(sheerka.smart_get_attr(table_instance, color)) == red
def test_i_can_smart_get_when_multiple_levels_of_isa(self):
sheerka, context, adjective, color, reddish, red, table = self.init_concepts("adjective",
"color",
"reddish",
"red",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, reddish, color)
sheerka.set_isa(context, red, reddish)
reddish_instance = sheerka.new(reddish, body=red)
color_instance = sheerka.new(color, body=reddish_instance)
adjective_instance = sheerka.new(adjective, body=color_instance)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, adjective, adjective_instance)
assert sheerka.smart_get_attr(table_instance, reddish_instance) == reddish_instance
assert sheerka.objvalue(sheerka.smart_get_attr(table_instance, color)) == red
def test_i_can_smart_get_when_multiple_values(self):
sheerka, context, adjective, color, red, blue, table = self.init_concepts("adjective",
"color",
"red",
"blue",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
sheerka.set_isa(context, blue, color)
table_instance = sheerka.new(table)
# add red color
red_color_instance = sheerka.new(color, body=red)
red_adjective_instance = sheerka.new(adjective, body=red_color_instance)
sheerka.set_attr(table_instance, adjective, red_adjective_instance)
# add blue color
blue_color_instance = sheerka.new(color, body=blue)
blue_adjective_instance = sheerka.new(adjective, body=blue_color_instance)
sheerka.set_attr(table_instance, adjective, blue_adjective_instance)
res = sheerka.smart_get_attr(table_instance, color)
assert res == [red_color_instance, blue_color_instance]
def test_i_can_smart_get_when_ancestor_is_asked(self):
sheerka, context, adjective, color, red, table = self.init_concepts("adjective",
"color",
"red",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
color_instance = sheerka.new(color, body=red)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, color, color_instance)
assert sheerka.smart_get_attr(table_instance, adjective) == color_instance
def test_i_can_smart_get_when_ancestor_is_asked_and_multiple_values(self):
sheerka, context, adjective, color, red, size, large, table = self.init_concepts("adjective",
"color",
"red",
"size",
"large",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
sheerka.set_isa(context, size, adjective)
sheerka.set_isa(context, large, size)
table_instance = sheerka.new(table)
color_instance = sheerka.new(color, body=red)
sheerka.set_attr(table_instance, color, color_instance)
size_instance = sheerka.new(size, body=large)
sheerka.set_attr(table_instance, size, size_instance)
assert sheerka.smart_get_attr(table_instance, adjective) == [color_instance, size_instance]
def test_i_can_smart_get_when_direct_value_takes_precedence_over_child_value(self):
sheerka, context, adjective, color, red, blue, table = self.init_concepts("adjective",
"color",
"red",
"blue",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
color_instance = sheerka.new(color, body=red)
adjective_instance = sheerka.new(adjective, body=color_instance)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, adjective, adjective_instance)
sheerka.set_attr(table_instance, color, blue) # set direct color value
assert sheerka.smart_get_attr(table_instance, color) == blue
def test_i_can_smart_get_when_direct_value_takes_precedence_over_ancestor_value(self):
sheerka, context, adjective, color, red, blue, table = self.init_concepts("adjective",
"color",
"red",
"blue",
"table",
create_new=True)
sheerka.set_isa(context, color, adjective)
sheerka.set_isa(context, red, color)
color_instance = sheerka.new(color, body=red)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, color, color_instance)
sheerka.set_attr(table_instance, adjective, blue) # set direct color value
assert sheerka.smart_get_attr(table_instance, adjective) == blue
def test_i_cannot_smart_get_attr_if_value_is_unknown_and_attribute_not_a_concept(self):
sheerka, context = self.init_concepts()
foo = Concept("foo")
res = sheerka.smart_get_attr(foo, "attribute")
assert sheerka.isinstance(res, BuiltinConcepts.NOT_FOUND)
def test_i_cannot_smart_get_attr_if_value_is_unknown_and_no_isa(self):
sheerka, context, adjective, color, red, table = self.init_concepts("adjective",
"color",
"red",
"table",
create_new=True)
# sheerka.set_isa(context, color, adjective) # color is not defined as an adjective
sheerka.set_isa(context, red, color)
color_instance = sheerka.new(color, body=red)
adjective_instance = sheerka.new(adjective, body=color_instance)
table_instance = sheerka.new(table)
sheerka.set_attr(table_instance, adjective, adjective_instance)
res = sheerka.smart_get_attr(table_instance, color)
assert sheerka.isinstance(res, BuiltinConcepts.NOT_FOUND)
class TestSheerkaConceptManagerUsingFileBasedSheerka(TestUsingFileBasedSheerka):
def test_i_can_add_several_concepts(self):