Improved PythonEvaluator when dealing with concept class
This commit is contained in:
@@ -2,7 +2,7 @@ import core.builtin_helpers
|
||||
from cache.SetCache import SetCache
|
||||
from core.ast.nodes import python_to_concept
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts
|
||||
from core.concept import Concept, ConceptParts, ensure_concept
|
||||
from core.sheerka.services.sheerka_service import BaseService
|
||||
|
||||
GROUP_PREFIX = 'All_'
|
||||
@@ -36,6 +36,7 @@ class SheerkaSetsManager(BaseService):
|
||||
"""
|
||||
|
||||
context.log(f"Setting concept {concept} is a {concept_set}", who=self.NAME)
|
||||
ensure_concept(concept, concept_set)
|
||||
|
||||
if BuiltinConcepts.ISA in concept.metadata.props and concept_set in concept.metadata.props[BuiltinConcepts.ISA]:
|
||||
return self.sheerka.ret(
|
||||
@@ -61,9 +62,7 @@ class SheerkaSetsManager(BaseService):
|
||||
"""
|
||||
|
||||
context.log(f"Adding concept {concept} to set {concept_set}", who=self.NAME)
|
||||
|
||||
assert concept.id
|
||||
assert concept_set.id
|
||||
ensure_concept(concept, concept_set)
|
||||
|
||||
set_elements = self.sheerka.cache_manager.get(self.CONCEPTS_GROUPS_ENTRY, concept_set.id)
|
||||
if set_elements and concept.id in set_elements:
|
||||
@@ -79,6 +78,7 @@ class SheerkaSetsManager(BaseService):
|
||||
"""Adding multiple concepts at the same time"""
|
||||
|
||||
context.log(f"Adding concepts {concepts} to set {concept_set}", who=self.NAME)
|
||||
ensure_concept(concept_set)
|
||||
already_in_set = []
|
||||
for concept in concepts:
|
||||
res = self.add_concept_to_set(context, concept, concept_set)
|
||||
@@ -103,6 +103,8 @@ class SheerkaSetsManager(BaseService):
|
||||
:return:
|
||||
"""
|
||||
|
||||
ensure_concept(concept)
|
||||
|
||||
def _get_set_elements(sub_concept):
|
||||
if not self.isaset(context, sub_concept):
|
||||
return self.sheerka.new(BuiltinConcepts.NOT_A_SET, body=concept)
|
||||
@@ -151,8 +153,9 @@ class SheerkaSetsManager(BaseService):
|
||||
if isinstance(a, BuiltinConcepts): # common KSI error ;-)
|
||||
raise SyntaxError("Remember that the first parameter of isinstance MUST be a concept")
|
||||
|
||||
if not (isinstance(a, Concept) and isinstance(b, Concept)):
|
||||
return False
|
||||
ensure_concept(a, b)
|
||||
# if not (isinstance(a, Concept) and isinstance(b, Concept)):
|
||||
# return False
|
||||
|
||||
# TODO, first check the 'isa' property of a
|
||||
if not (a.id and b.id):
|
||||
@@ -163,6 +166,7 @@ class SheerkaSetsManager(BaseService):
|
||||
|
||||
def isa(self, a, b):
|
||||
|
||||
ensure_concept(a, b)
|
||||
if BuiltinConcepts.ISA not in a.metadata.props:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user