Improved PythonEvaluator when dealing with concept class
This commit is contained in:
@@ -13,6 +13,7 @@ from core.builtin_concepts import BuiltinConcepts, ErrorConcept, ReturnValueConc
|
||||
from core.concept import Concept, ConceptParts, PROPERTIES_FOR_NEW
|
||||
from core.sheerka.ExecutionContext import ExecutionContext
|
||||
from core.sheerka_logger import console_handler
|
||||
from core.tokenizer import Token, TokenKind
|
||||
from printer.SheerkaPrinter import SheerkaPrinter
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProvider, Event
|
||||
|
||||
@@ -489,6 +490,37 @@ class Sheerka(Concept):
|
||||
metadata = [(index_name, key), ("id", concept_id)] if concept_id else (index_name, key)
|
||||
return self._get_unknown(metadata)
|
||||
|
||||
def resolve(self, concept):
|
||||
if concept is None:
|
||||
return concept
|
||||
|
||||
# if the entry is a concept token, use its values.
|
||||
if isinstance(concept, Token):
|
||||
if concept.type != TokenKind.CONCEPT:
|
||||
return None
|
||||
concept = concept.value
|
||||
|
||||
# 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
|
||||
elif concept[0]:
|
||||
return found if self.is_known(found := self.get_by_name(concept[0])) else None
|
||||
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
|
||||
|
||||
return None
|
||||
|
||||
def has_id(self, concept_id):
|
||||
"""
|
||||
Returns True if a concept with this id exists in cache
|
||||
|
||||
Reference in New Issue
Block a user