Added empty string parser

This commit is contained in:
2019-11-15 17:49:37 +01:00
parent 2fbda533f1
commit 3a1dea19e8
7 changed files with 65 additions and 11 deletions
+26
View File
@@ -0,0 +1,26 @@
from core.builtin_concepts import BuiltinConcepts
from parsers.BaseParser import BaseParser
import logging
log = logging.getLogger(__name__)
class EmptyStringParser(BaseParser):
"""
To parse empty or blank strings
"""
def __init__(self):
BaseParser.__init__(self, "NullParser")
def parse(self, context, text):
sheerka = context.sheerka
if isinstance(text, str) and text.strip() == "" or \
isinstance(text, list) and text == [] or \
text is None:
log.debug(f"Recognized '{text}' as BuiltinConcepts.NOP.")
return sheerka.ret(self.name, True, sheerka.new(BuiltinConcepts.NOP))
log.debug(f"Failed to recognize '{text}'")
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.NOT_FOR_ME))
+2 -2
View File
@@ -28,7 +28,7 @@ class ExactConceptParser(BaseParser):
sheerka = context.sheerka
words = self.get_words(text)
if len(words) > self.MAX_WORDS_SIZE:
return ReturnValueConcept(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, obj=text))
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, obj=text))
recognized = False
for combination in self.combinations(words):
@@ -53,7 +53,7 @@ class ExactConceptParser(BaseParser):
return res
log.debug(f"Failed to recognize {words}")
return ReturnValueConcept(self.name, False, sheerka.new(BuiltinConcepts.UNKNOWN_CONCEPT, obj=text))
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.UNKNOWN_CONCEPT, obj=text))
@staticmethod
def get_words(text):