Fixed minor issues and enhancements
This commit is contained in:
@@ -72,6 +72,9 @@ def expect_one(context, return_values):
|
||||
sheerka.new(BuiltinConcepts.IS_EMPTY, body=return_values),
|
||||
parents=return_values)
|
||||
|
||||
if len(return_values) == 1:
|
||||
return return_values[0]
|
||||
|
||||
successful_results = [item for item in return_values if item.status]
|
||||
number_of_successful = len(successful_results)
|
||||
# total_items = len(return_values)
|
||||
@@ -113,7 +116,7 @@ def expect_one(context, return_values):
|
||||
return sheerka.ret(
|
||||
context.who,
|
||||
False,
|
||||
return_values[0],
|
||||
return_values[0].body,
|
||||
parents=return_values)
|
||||
else:
|
||||
# test if only one evaluator in error
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import core.utils
|
||||
from core.builtin_concepts import BuiltinConcepts, ErrorConcept
|
||||
from core.concept import Concept
|
||||
from sdp.sheerkaDataProvider import SheerkaDataProviderDuplicateKeyError
|
||||
|
||||
BNF_NODE_PARSER_CLASS = "parsers.BnfNodeParser_Old.BnfNodeParser"
|
||||
BASE_NODE_PARSER_CLASS = "parsers.BaseNodeParser.BaseNodeParser"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.builtin_helpers import expect_one
|
||||
from core.builtin_helpers import expect_one, only_successful
|
||||
from core.concept import Concept, DoNotResolve, ConceptParts, InfiniteRecursionResolved
|
||||
|
||||
CONCEPT_EVALUATION_STEPS = [
|
||||
@@ -71,6 +71,11 @@ class SheerkaEvaluateConcept:
|
||||
:param logger:
|
||||
:return:
|
||||
"""
|
||||
def is_only_successful(r):
|
||||
# return False
|
||||
return context.sheerka.isinstance(r, BuiltinConcepts.RETURN_VALUE) and \
|
||||
context.sheerka.isinstance(r.body, BuiltinConcepts.ONLY_SUCCESSFUL)
|
||||
|
||||
steps = [BuiltinConcepts.BEFORE_PARSING, BuiltinConcepts.PARSING, BuiltinConcepts.AFTER_PARSING]
|
||||
for part_key in ConceptParts:
|
||||
if part_key in concept.compiled:
|
||||
@@ -88,7 +93,8 @@ class SheerkaEvaluateConcept:
|
||||
to_parse = self.sheerka.ret(context.who, True,
|
||||
self.sheerka.new(BuiltinConcepts.USER_INPUT, body=source))
|
||||
res = self.sheerka.execute(sub_context, to_parse, steps)
|
||||
concept.compiled[part_key] = res
|
||||
only_success = only_successful(sub_context, res)
|
||||
concept.compiled[part_key] = only_success.body.body if is_only_successful(only_success) else res
|
||||
sub_context.add_values(return_values=res)
|
||||
|
||||
for var_name, default_value in concept.metadata.variables:
|
||||
@@ -106,7 +112,8 @@ class SheerkaEvaluateConcept:
|
||||
to_parse = self.sheerka.ret(context.who, True,
|
||||
self.sheerka.new(BuiltinConcepts.USER_INPUT, body=default_value))
|
||||
res = self.sheerka.execute(context, to_parse, steps)
|
||||
concept.compiled[var_name] = res
|
||||
only_success = only_successful(sub_context, res)
|
||||
concept.compiled[var_name] = only_success.body.body if is_only_successful(only_success) else res
|
||||
sub_context.add_values(return_values=res)
|
||||
|
||||
# Updates the cache of concepts when possible
|
||||
@@ -114,6 +121,7 @@ class SheerkaEvaluateConcept:
|
||||
self.sheerka.get_by_id(concept.id).compiled = concept.compiled
|
||||
|
||||
def resolve(self, context, to_resolve, current_prop, current_concept, force_evaluation):
|
||||
|
||||
if isinstance(to_resolve, DoNotResolve):
|
||||
return to_resolve.value
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class ExactConceptParser(BaseParser):
|
||||
Tries to recognize a single concept
|
||||
"""
|
||||
|
||||
MAX_WORDS_SIZE = 3
|
||||
MAX_WORDS_SIZE = 6
|
||||
|
||||
def __init__(self, max_word_size=None, **kwargs):
|
||||
BaseParser.__init__(self, "ExactConcept", 80)
|
||||
@@ -36,7 +36,9 @@ class ExactConceptParser(BaseParser):
|
||||
|
||||
if len(words) > (self.max_word_size or self.MAX_WORDS_SIZE):
|
||||
context.log(f"Max words reached. Stopping.", self.name)
|
||||
return sheerka.ret(self.name, False, sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, body=parser_input))
|
||||
too_long = sheerka.new(BuiltinConcepts.CONCEPT_TOO_LONG, body=parser_input)
|
||||
body = sheerka.new(BuiltinConcepts.NOT_FOR_ME, body=parser_input, reason=too_long)
|
||||
return sheerka.ret(self.name, False, body)
|
||||
|
||||
recognized = [] # keep track of the concepts founds
|
||||
for combination in self.combinations(words):
|
||||
|
||||
Reference in New Issue
Block a user