Fixed #48 : RelationalExpressionParser: Implement relational operator parser

Fixed #49 : ExpressionParser: Implement ExpressionParser
Fixed #50 : Implement ReteConditionExprVisitor
Fixed #51 : Implement PythonConditionExprVisitor
Fixed #52 : SheerkaConceptManager: I can get and set concept property
This commit is contained in:
2021-03-23 11:35:10 +01:00
parent f8e47e2b38
commit 6cda2686fb
25 changed files with 1083 additions and 978 deletions
+40 -6
View File
@@ -5,7 +5,7 @@ from core.builtin_concepts import BuiltinConcepts
from core.builtin_helpers import ensure_bnf
from core.concept import PROPERTIES_TO_SERIALIZE, Concept, DEFINITION_TYPE_DEF, get_concept_attrs, \
DEFINITION_TYPE_BNF
from core.global_symbols import NotInit, NotFound
from core.global_symbols import NotInit, NotFound, SyaAssociativity
from core.sheerka.services.SheerkaConceptManager import SheerkaConceptManager, NoModificationFound, ForbiddenAttribute, \
UnknownAttribute, CannotRemoveMeta, ValueNotFound, ConceptIsReferenced, NoFirstTokenError
from parsers.BnfNodeParser import Sequence, StrMatch, ConceptExpression, OrderedChoice, Optional, ZeroOrMore, OneOrMore, \
@@ -320,13 +320,13 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
def test_i_can_modify_add_a_property(self):
sheerka, context, one, foo = self.init_concepts("one", Concept("foo", props={BuiltinConcepts.ISA: {"value"}}))
res = sheerka.modify_concept(context, foo, to_add={"props": {BuiltinConcepts.ISA: "value2",
res = sheerka.modify_concept(context, foo, to_add={"props": {BuiltinConcepts.ISA: {"value2"},
BuiltinConcepts.HASA: one}})
assert res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.NEW_CONCEPT)
assert res.body.body.get_prop(BuiltinConcepts.ISA) == {"value", "value2"}
assert res.body.body.get_prop(BuiltinConcepts.HASA) == {sheerka.new("one")}
assert res.body.body.get_prop(BuiltinConcepts.ISA) == {"value2"}
assert res.body.body.get_prop(BuiltinConcepts.HASA) == sheerka.new("one")
def test_i_can_modify_remove_a_property(self):
sheerka, context, foo = self.init_concepts(
@@ -382,7 +382,7 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
to_add = {"meta": {"body": "metadata value"},
"variables": {"var_name": "default value"},
"props": {BuiltinConcepts.ISA: bar}}
"props": {BuiltinConcepts.ISA: {bar}}}
res = sheerka.modify_concept(context, foo, to_add)
new_concept = res.body.body
@@ -656,7 +656,7 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
to_add = {
"meta": {"body": "a body"},
"props": {BuiltinConcepts.ISA: "bar"},
"props": {BuiltinConcepts.ISA: {"bar"}},
"variables": {"c": "value"}
}
to_remove = {
@@ -826,6 +826,40 @@ class TestSheerkaConceptManager(TestUsingMemoryBasedSheerka):
assert sheerka.isinstance(res.body, BuiltinConcepts.SUCCESS)
assert sheerka.get_attr(foo, prop) == [bar, baz, qux]
def test_i_can_get_and_set_property(self):
sheerka, context, foo, prop, bar = self.init_concepts("foo", "property", "bar")
foo_instance = sheerka.new(foo)
res = sheerka.set_property(context, foo_instance, prop, bar)
assert res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.SUCCESS)
assert sheerka.get_property(foo_instance, prop) == bar
res = sheerka.set_property(context, foo_instance, BuiltinConcepts.ASSOCIATIVITY, SyaAssociativity.Left)
assert res.status
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)
assert res.status
assert sheerka.isinstance(res.body, BuiltinConcepts.SUCCESS)
assert sheerka.get_property(foo_instance, BuiltinConcepts.ASSOCIATIVITY) == SyaAssociativity.Right
# by default, the concept itself is not modified
new_foo = sheerka.new(foo)
not_found = sheerka.get_property(new_foo, prop)
assert sheerka.isinstance(not_found, BuiltinConcepts.NOT_FOUND)
assert not_found.body == {"#concept": new_foo, "#prop": prop}
# I can modify the concept itself
another_foo_instance = sheerka.new(foo)
res = sheerka.set_property(context, another_foo_instance, prop, bar, all_concepts=True)
assert res.status
assert sheerka.get_property(another_foo_instance, prop) == bar
new_foo = sheerka.new(foo)
assert sheerka.get_property(new_foo, prop) == bar
def test_i_cannot_remove_a_concept_which_has_reference(self):
sheerka, context, one, twenty_one = self.init_test().with_concepts(
Concept("one"),