Refactord Concept class to regroup all builtins properties into a ConceptMetadata class
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
|
||||
from parsers.BaseParser import BaseParser
|
||||
from core.tokenizer import Tokenizer, Keywords, TokenKind
|
||||
from core.concept import Concept
|
||||
from core.concept import Concept, VARIABLE_PREFIX
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -28,7 +28,7 @@ class ExactConceptParser(BaseParser):
|
||||
sheerka = context.sheerka
|
||||
words = self.get_words(text)
|
||||
if len(words) > self.MAX_WORDS_SIZE:
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, obj=text))
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, body=text))
|
||||
|
||||
recognized = False
|
||||
for combination in self.combinations(words):
|
||||
@@ -44,8 +44,8 @@ class ExactConceptParser(BaseParser):
|
||||
for concept in concepts:
|
||||
# update the properties if needed
|
||||
for i, token in enumerate(combination):
|
||||
if token.startswith(Concept.PROPERTY_PREFIX):
|
||||
index = int(token[len(Concept.PROPERTY_PREFIX):])
|
||||
if token.startswith(VARIABLE_PREFIX):
|
||||
index = int(token[len(VARIABLE_PREFIX):])
|
||||
concept.set_prop_by_index(index, words[i])
|
||||
res.append(ReturnValueConcept(self.name, True, concept))
|
||||
log.debug(f"Recognized '{text}' as '{concept}'")
|
||||
@@ -55,7 +55,7 @@ class ExactConceptParser(BaseParser):
|
||||
return res
|
||||
|
||||
log.debug(f"Failed to recognize {words}")
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.UNKNOWN_CONCEPT, obj=text))
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.UNKNOWN_CONCEPT, body=text))
|
||||
|
||||
@staticmethod
|
||||
def get_words(text):
|
||||
@@ -111,7 +111,7 @@ class ExactConceptParser(BaseParser):
|
||||
for i in indices:
|
||||
value = pool[i]
|
||||
if value not in vars:
|
||||
vars[pool[i]] = f"{Concept.PROPERTY_PREFIX}{k}"
|
||||
vars[pool[i]] = f"{VARIABLE_PREFIX}{k}"
|
||||
k += 1
|
||||
|
||||
# create tuple
|
||||
|
||||
Reference in New Issue
Block a user