Fixed #68: Implement SheerkaQL
Fixed #70: SheerkaFilterManager : Pipe functions Fixed #71: SheerkaFilterManager : filter_objects Fixed #75: SheerkaMemory: Enhance memory() to use the filtering capabilities Fixed #76: SheerkaEvaluateConcept: Concepts that modify the state of the system must not be evaluated during question
This commit is contained in:
+37
-10
@@ -7,6 +7,7 @@ from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts, DEFINITION_TYPE_BNF, concept_part_value
|
||||
from core.global_symbols import NotInit, NotFound, CURRENT_OBJ
|
||||
from core.rule import Rule
|
||||
from core.tokenizer import Tokenizer
|
||||
from core.utils import as_bag
|
||||
from parsers.BaseNodeParser import SourceCodeNode, ConceptNode, UnrecognizedTokensNode, SourceCodeWithConceptNode, \
|
||||
RuleNode, VariableNode
|
||||
@@ -313,15 +314,15 @@ def only_parsers_results(context, return_values):
|
||||
parents=return_values)
|
||||
|
||||
|
||||
def evaluate(context,
|
||||
source,
|
||||
evaluators="all",
|
||||
desc=None,
|
||||
eval_body=True,
|
||||
eval_where=True,
|
||||
is_question=False,
|
||||
expect_success=False,
|
||||
stm=None):
|
||||
def evaluate_from_source(context,
|
||||
source,
|
||||
evaluators="all",
|
||||
desc=None,
|
||||
eval_body=True,
|
||||
eval_where=True,
|
||||
is_question=False,
|
||||
expect_success=False,
|
||||
stm=None):
|
||||
"""
|
||||
|
||||
:param context:
|
||||
@@ -338,7 +339,13 @@ def evaluate(context,
|
||||
|
||||
sheerka = context.sheerka
|
||||
desc = desc or f"Eval '{source}'"
|
||||
with context.push(BuiltinConcepts.EVALUATE_SOURCE, source, desc=desc) as sub_context:
|
||||
hints_to_reset = {
|
||||
BuiltinConcepts.EVAL_BODY_REQUESTED,
|
||||
BuiltinConcepts.EVAL_WHERE_REQUESTED,
|
||||
BuiltinConcepts.EVAL_UNTIL_SUCCESS_REQUESTED,
|
||||
BuiltinConcepts.EVAL_QUESTION_REQUESTED,
|
||||
}
|
||||
with context.push(BuiltinConcepts.EVALUATE_SOURCE, source, desc=desc, reset_hints=hints_to_reset) as sub_context:
|
||||
if eval_body:
|
||||
sub_context.protected_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
|
||||
@@ -804,6 +811,26 @@ def get_inner_body(context, concept):
|
||||
return concept.body
|
||||
|
||||
|
||||
def get_possible_variables_from_concept(context, concept):
|
||||
"""
|
||||
Given concept definition,
|
||||
gives the variables of the concept that can be considered as a parameter in another function
|
||||
>>> gpvfc = get_possible_variables_from_concept
|
||||
>>> assert gpvfc(Concept("a plus b").def_var("a").def_var("b")) == {"a", "b"}
|
||||
>>> assert gpvfc(Concept("twenties", definition="twenty (one|two)=n").def_var("n")) == set()
|
||||
:param context:
|
||||
:param concept:
|
||||
:return:
|
||||
"""
|
||||
if len(concept.name) <= 1:
|
||||
return set()
|
||||
|
||||
concept_name = [t.str_value for t in Tokenizer(concept.name, yield_eof=False)]
|
||||
names = [v_value or v_name for v_name, v_value in concept.get_metadata().variables if v_name in concept_name]
|
||||
possible_vars = filter(lambda x: context.sheerka.is_not_a_concept_name(x), names)
|
||||
return set(possible_vars)
|
||||
|
||||
|
||||
class CreateObjectIdentifiers:
|
||||
"""
|
||||
Class that creates unique identifiers for Concept or Rule objects
|
||||
|
||||
Reference in New Issue
Block a user