ExactConceptParser can now recognize concepts by their names
This commit is contained in:
@@ -491,8 +491,14 @@ class Sheerka(Concept):
|
||||
return self._get_unknown(metadata)
|
||||
|
||||
def resolve(self, concept):
|
||||
|
||||
def new_instances(concepts):
|
||||
if hasattr(concepts, "__iter__"):
|
||||
return [self.new_from_template(c, c.key) for c in concepts]
|
||||
return self.new_from_template(concepts, concepts.key)
|
||||
|
||||
if concept is None:
|
||||
return concept
|
||||
return None
|
||||
|
||||
# if the entry is a concept token, use its values.
|
||||
if isinstance(concept, Token):
|
||||
@@ -500,24 +506,34 @@ class Sheerka(Concept):
|
||||
return None
|
||||
concept = concept.value
|
||||
|
||||
if isinstance(concept, str) and \
|
||||
concept.startswith("c:") and \
|
||||
(tmp := core.utils.unstr_concept(concept)) != (None, None):
|
||||
concept = tmp
|
||||
|
||||
# if the entry is a tuple
|
||||
# concept[0] is the name
|
||||
# concept[1] is the id
|
||||
if isinstance(concept, tuple):
|
||||
if concept[1]:
|
||||
if self.is_known(found := self.get_by_id(concept[1])):
|
||||
return found
|
||||
instance = self.new_from_template(found, found.key)
|
||||
instance.metadata.is_evaluated = True
|
||||
return instance
|
||||
elif concept[0]:
|
||||
return found if self.is_known(found := self.get_by_name(concept[0])) else None
|
||||
if self.is_known(found := self.get_by_name(concept[0])):
|
||||
instances = new_instances(found)
|
||||
core.builtin_helpers.set_is_evaluated(instances)
|
||||
return instances
|
||||
else:
|
||||
return None
|
||||
|
||||
# otherwise search in db
|
||||
if isinstance(concept, str):
|
||||
if self.is_known(found := self.get_by_id(concept)):
|
||||
return found
|
||||
if self.is_known(found := self.get_by_name(concept)):
|
||||
return found
|
||||
instances = new_instances(found)
|
||||
core.builtin_helpers.set_is_evaluated(instances)
|
||||
return instances
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user