Enhanced complex concepts handling
This commit is contained in:
+21
-10
@@ -735,7 +735,12 @@ class Sheerka(Concept):
|
||||
:param kwargs:
|
||||
:return:
|
||||
"""
|
||||
template = self.get(concept_key)
|
||||
if isinstance(concept_key, tuple):
|
||||
concept_key, concept_id = concept_key[0], concept_key[1]
|
||||
else:
|
||||
concept_id = None
|
||||
|
||||
template = self.get(concept_key, concept_id)
|
||||
|
||||
# manage concept not found
|
||||
if self.isinstance(template, BuiltinConcepts.UNKNOWN_CONCEPT) and \
|
||||
@@ -747,7 +752,7 @@ class Sheerka(Concept):
|
||||
|
||||
# if template is a list, it means that there a multiple concepts under the same key
|
||||
concepts = [self.new_from_template(t, concept_key, **kwargs) for t in template]
|
||||
return self.new(BuiltinConcepts.ENUMERATION, body=concepts)
|
||||
return concepts
|
||||
|
||||
def new_from_template(self, template, key, **kwargs):
|
||||
# manage singleton
|
||||
@@ -759,15 +764,15 @@ class Sheerka(Concept):
|
||||
concept.update_from(template)
|
||||
|
||||
# update the properties
|
||||
for key, v in kwargs.items():
|
||||
if key in concept.props:
|
||||
concept.set_prop(key, v)
|
||||
elif key in PROPERTIES_FOR_NEW:
|
||||
setattr(concept.metadata, key, v)
|
||||
elif hasattr(concept, key):
|
||||
setattr(concept, key, v)
|
||||
for k, v in kwargs.items():
|
||||
if k in concept.props:
|
||||
concept.set_prop(k, v)
|
||||
elif k in PROPERTIES_FOR_NEW:
|
||||
setattr(concept.metadata, k, v)
|
||||
elif hasattr(concept, k):
|
||||
setattr(concept, k, v)
|
||||
else:
|
||||
return self.new(BuiltinConcepts.UNKNOWN_PROPERTY, body=key, concept=concept)
|
||||
return self.new(BuiltinConcepts.UNKNOWN_PROPERTY, body=k, concept=concept)
|
||||
|
||||
# TODO : add the concept to the list of known concepts (self.instances)
|
||||
return concept
|
||||
@@ -830,6 +835,12 @@ class Sheerka(Concept):
|
||||
|
||||
return obj
|
||||
|
||||
def is_unknown(self, obj):
|
||||
if not isinstance(obj, Concept):
|
||||
return True
|
||||
|
||||
return obj.key == BuiltinConcepts.UNKNOWN_CONCEPT
|
||||
|
||||
def isinstance(self, a, b):
|
||||
"""
|
||||
return true if the concept a is an instance of the concept b
|
||||
|
||||
Reference in New Issue
Block a user