Fixed #109 : Mix python and concept. List comprehension

Fixed #110 : SheerkaDebugManager: add list_debug_settings
Fixed #111 : SheerkaDebugManager: Implement ListDebugLogger
Fixed #112 : SyaNodeParser: rewrite this parser
Fixed #113 : Sheerka.: Add enable_parser_caching to disable parsers caching
Fixed #114 : SyaNodeParser : Implement fast cache to resolve unrecognized tokens requests
Fixed #115 : BnfNodeParser : Implement fast cache to resolve unrecognized tokens requests
Fixed #116 : SequenceNodeParser : Implement fast cache to resolve unrecognized tokens requests
Fixed #117 : ResolveMultiplePluralAmbiguityEvaluator: Resolve Multiple plural ambiguity
This commit is contained in:
2021-09-06 11:51:50 +02:00
parent 71d1b1d1ca
commit 54e5681c5a
57 changed files with 5179 additions and 3125 deletions
+39 -17
View File
@@ -1,14 +1,22 @@
import ast
from core.builtin_concepts import ReturnValueConcept, BuiltinConcepts, ParserResultConcept
from core.builtin_concepts import BuiltinConcepts, ParserResultConcept, ReturnValueConcept
from core.concept import Concept
from evaluators.BaseEvaluator import BaseEvaluator
from parsers.BaseParser import BaseParser
from parsers.PythonParser import PythonNode
from parsers.BaseNodeParser import ConceptNode
from parsers.ExactConceptParser import ExactConceptParser
from parsers.PythonParser import PythonNode, PythonParser
from parsers.SequenceNodeParser import SequenceNodeParser
from parsers.SyaNodeParser import SyaNodeParser
reduced_requested = ReturnValueConcept("Sheerka", True, Concept(name=BuiltinConcepts.REDUCE_REQUESTED,
key=BuiltinConcepts.REDUCE_REQUESTED))
sequence = SequenceNodeParser()
sya = SyaNodeParser()
exact = ExactConceptParser()
python = PythonParser()
def ret_val(value="value", who="who", status=True):
"""
@@ -21,7 +29,7 @@ def ret_val(value="value", who="who", status=True):
return ReturnValueConcept(who, status, value)
def p_ret_val(value="value", parser="parser", status=True):
def p_ret_val(value="value", parser=exact, status=True):
"""
ReturnValueConcept from parser
:param value:
@@ -29,7 +37,7 @@ def p_ret_val(value="value", parser="parser", status=True):
:param status:
:return:
"""
return ReturnValueConcept(BaseParser.get_name(parser), status, value)
return ReturnValueConcept(parser.name, status, value)
def e_ret_val(value="value", evaluator="evaluator", status=True):
@@ -43,7 +51,7 @@ def e_ret_val(value="value", evaluator="evaluator", status=True):
return ReturnValueConcept(BaseEvaluator.PREFIX + evaluator, status, value)
def p_ret_val_false(value="value", parser="parser"):
def p_ret_val_false(value="value", parser=exact):
"""
Failed ReturnValueConcept from parser
:param value:
@@ -53,7 +61,7 @@ def p_ret_val_false(value="value", parser="parser"):
return p_ret_val(value, parser, status=False)
def p_ret_val_true(value="value", parser="parser"):
def p_ret_val_true(value="value", parser=exact):
"""
Successful ReturnValueConcept from parser
:param value:
@@ -63,24 +71,24 @@ def p_ret_val_true(value="value", parser="parser"):
return p_ret_val(value, parser, status=True)
def e_ret_val_false(value="value", parser="parser"):
def e_ret_val_false(value="value", evaluator="evaluator"):
"""
Failed ReturnValueConcept from evaluator
:param value:
:param parser:
:param evaluator:
:return:
"""
return e_ret_val(value, parser, status=False)
return e_ret_val(value, evaluator, status=False)
def e_ret_val_true(value="value", parser="parser"):
def e_ret_val_true(value="value", evaluator="evaluator"):
"""
Successful ReturnValueConcept from evaluator
:param value:
:param parser:
:param evaluator:
:return:
"""
return e_ret_val(value, parser, status=True)
return e_ret_val(value, evaluator, status=True)
def e_ret_val_new(key, evaluator="evaluator", status=True, **kwargs):
@@ -96,7 +104,7 @@ def e_ret_val_new(key, evaluator="evaluator", status=True, **kwargs):
return e_ret_val(body, evaluator, status)
def pr_ret_val(value, parser="parser", source=None, status=True):
def pr_ret_val(value, parser=exact, source=None, status=True):
"""
ParserResult ReturnValue
eg: ReturnValue with a ParserResult
@@ -107,7 +115,7 @@ def pr_ret_val(value, parser="parser", source=None, status=True):
:return:
"""
source = source or (value.name if isinstance(value, Concept) else "source")
parser_result = ParserResultConcept(BaseParser.get_name(parser), source=source, value=value)
parser_result = ParserResultConcept(parser, source=source, value=value)
return p_ret_val(value=parser_result, parser=parser, status=status)
@@ -117,8 +125,14 @@ def python_ret_val(source):
:param source:
:return:
"""
python_node = PythonNode(source.strip(), ast.parse(source.strip(), f"<source>", 'eval'))
return pr_ret_val(python_node, parser="Python", source=source)
python_node = PythonNode(source.lstrip(), ast.parse(source.strip(), f"<source>", 'eval'))
return pr_ret_val(python_node, parser=python, source=source)
def cnode_ret_val(concept, source=None, parser=sya):
source = source or concept.name
cnode = ConceptNode(concept, 0, 0, source=source)
return pr_ret_val([cnode], parser=parser, source=source)
def new_concept(key, **kwargs):
@@ -129,3 +143,11 @@ def new_concept(key, **kwargs):
res.get_hints().is_evaluated = True
return res
def new_plural(name):
name_stripped_s = name.lstrip("s")
single = Concept(name_stripped_s)
concept = Concept(key=name, name=name, id=f"{name}:{BuiltinConcepts.PLURAL}", is_builtin=False, is_unique=False)
concept.set_prop(BuiltinConcepts.PLURAL, single)
return concept