Enhanced sheerka.update_concept() logs

This commit is contained in:
2019-12-27 11:33:16 +01:00
parent 26daae4acf
commit 21da87393f
5 changed files with 49 additions and 20 deletions
+13 -3
View File
@@ -1,10 +1,9 @@
import logging
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts
from parsers.BaseParser import BaseParser
from core.tokenizer import Tokenizer, Keywords, TokenKind
from core.concept import VARIABLE_PREFIX
import logging
log = logging.getLogger(__name__)
class ExactConceptParser(BaseParser):
@@ -24,10 +23,13 @@ class ExactConceptParser(BaseParser):
:param text:
:return:
"""
context.log(self.verbose_log, f"Parsing '{text}'", self.name)
res = []
sheerka = context.sheerka
words = self.get_words(text)
if len(words) > self.MAX_WORDS_SIZE:
context.log(self.verbose_log, f"Max words reached. Stopping.", self.name)
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, body=text))
recognized = False
@@ -42,11 +44,19 @@ class ExactConceptParser(BaseParser):
concepts = result.body if sheerka.isinstance(result, BuiltinConcepts.ENUMERATION) else [result]
for concept in concepts:
context.log(self.verbose_log, f"Recognized concept {concept}.", self.name)
# update the properties if needed
for i, token in enumerate(combination):
if token.startswith(VARIABLE_PREFIX):
index = int(token[len(VARIABLE_PREFIX):])
concept.set_prop_by_index(index, words[i])
if self.verbose_log.isEnabledFor(logging.DEBUG):
prop_name = list(concept.props.keys())[index]
context.log(
self.verbose_log,
f"Added property {index}: {prop_name}='{words[i]}'.",
self.name)
res.append(ReturnValueConcept(
self.name,
True,