Implemented some enhancement request and fixed some bugs
Fixed #2 : Variables are not recognized when inside a rule token Fixed #15 : Rule: rete attributes are lost when a new ontology is created Fixed #14 : ReteNetwork: Format rules must not be added to Rete network Fixed #16 : DefConcept: Variables are not recognized when they are keyword arguments Fixed #4 : Comparison are not correctly set when comparison property is a concept Fixed #14 : Parser: merge FunctionParser.NamesNode and ExpressionParser.NamesNode Fixed #18 : Parser: Add SourceCodeNode test to UnrecognizedNodeParser Fixed #20 : At startup Number concept is saved in db a numerous number of time Fixed #21 : CacheManager: I can remove all elements from a ListIfNeededCache and fill it again Fixed #22 : CacheManager: I can remove all elements from a SetCache and fill it again Fixed #23 : HistoryManager: history() no longer works Fixed #24 : HistoryManager: history() no longer works after creating an exec rule Fixed #25 : SheerkaMemory: Use MemoryObject instead of sheerka.local Fixed #26 : Debugger: add the list all available services.. Fixed #27 : CONCEPTS_GRAMMARS_ENTRY does not seems to be in use any more Fixed #28 : Give order to services
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
from core.builtin_concepts import ParserResultConcept, BuiltinConcepts
|
||||
from core.concept import Concept, CC
|
||||
from core.tokenizer import Tokenizer, TokenKind
|
||||
from parsers.SequenceNodeParser import SequenceNodeParser
|
||||
from parsers.BaseNodeParser import ConceptNode, UnrecognizedTokensNode, scnode, cnode, \
|
||||
utnode, SyaAssociativity, CN, CNC, UTN, SourceCodeWithConceptNode, SCWC, SourceCodeNode
|
||||
utnode, CN, CNC, UTN, SourceCodeWithConceptNode, SCWC, SourceCodeNode
|
||||
from parsers.BnfNodeParser import BnfNodeParser
|
||||
from parsers.SequenceNodeParser import SequenceNodeParser
|
||||
from parsers.SyaNodeParser import SyaNodeParser
|
||||
from parsers.UnrecognizedNodeParser import UnrecognizedNodeParser
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import compute_expected_array, get_node
|
||||
|
||||
@@ -208,49 +207,64 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
[CNC("twenties", source="twenty two", unit="two")])
|
||||
assert res.body.concept.get_compiled()["b"].get_compiled()["b"][0].body.body == expected_nodes
|
||||
|
||||
# def test_i_can_validate_and_evaluate_a_concept_node_with_python(self):
|
||||
# sheerka, context, parser = self.init_parser()
|
||||
#
|
||||
# node = get_input_nodes_from(
|
||||
# concepts_map,
|
||||
# "one plus 1 + 1",
|
||||
# CNC("plus",
|
||||
# a=UTN("one "),
|
||||
# b=UTN("1 + 1")))[0]
|
||||
#
|
||||
# res = UnrecognizedNodeParser().validate_concept_node(context, node)
|
||||
#
|
||||
# assert res.status
|
||||
# assert res.body.concept == concepts_map["plus"]
|
||||
# assert res.body.concept.get_compiled()["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.get_compiled()["b"]) == 1
|
||||
# assert sheerka.isinstance(res.body.concept.get_compiled()["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
# assert res.body.concept.get_compiled()["b"][0].status
|
||||
# assert res.body.concept.get_compiled()["b"][0].who == "parsers.Python"
|
||||
# assert res.body.concept.get_compiled()["b"][0].body.source == "1 + 1"
|
||||
#
|
||||
# # # evaluate
|
||||
# # context = self.get_context(sheerka, eval_body=True)
|
||||
# # evaluated = sheerka.evaluate_concept(context, res.body.concept)
|
||||
# # assert evaluated.body == 3
|
||||
def test_i_can_validate_and_evaluate_a_concept_node_with_python(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
# def test_i_can_validate_and_evaluate_concept_when_bnf_concept(self):
|
||||
# sheerka, context, parser = self.init_parser()
|
||||
# node = get_concept_node(concepts_map, "one plus twenty one", "plus", "one", "twenty one")
|
||||
#
|
||||
# res = UnrecognizedNodeParser().validate_concept_node(context, node)
|
||||
#
|
||||
# assert res.status
|
||||
# assert res.body.concept == concepts_map["plus"]
|
||||
# assert res.body.concept.get_compiled()["a"] == concepts_map["one"]
|
||||
# assert len(res.body.concept.get_compiled()["b"]) == 1
|
||||
# assert res.body.concept.get_compiled()["b"][0].status
|
||||
# assert res.body.concept.get_compiled()["b"][0].who == "parsers.BnfNode"
|
||||
#
|
||||
# # evaluate
|
||||
# context = self.get_context(sheerka, eval_body=True)
|
||||
# evaluated = sheerka.evaluate_concept(context, res.body.concept)
|
||||
# assert evaluated.body == 22
|
||||
node = get_input_nodes_from(
|
||||
concepts_map,
|
||||
"one plus 1 + 1",
|
||||
CNC("plus",
|
||||
a=UTN("one "),
|
||||
b=UTN("1 + 1")))[0]
|
||||
|
||||
res = UnrecognizedNodeParser().validate_concept_node(context, node)
|
||||
|
||||
assert res.status
|
||||
concept_found = res.body.concept
|
||||
compiled = concept_found.get_compiled()
|
||||
assert concept_found == concepts_map["plus"]
|
||||
assert len(compiled["a"]) == 1
|
||||
assert sheerka.isinstance(compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert compiled["a"][0].body.body[0].concept.id == concepts_map["one"].id
|
||||
|
||||
assert len(compiled["b"]) == 1
|
||||
assert sheerka.isinstance(compiled["b"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert compiled["b"][0].status
|
||||
assert compiled["b"][0].who == "parsers.Python"
|
||||
assert compiled["b"][0].body.source == "1 + 1"
|
||||
|
||||
# # evaluate
|
||||
context = self.get_context(sheerka, eval_body=True)
|
||||
evaluated = sheerka.evaluate_concept(context, res.body.concept)
|
||||
assert evaluated.body == 3
|
||||
|
||||
def test_i_can_validate_and_evaluate_concept_when_bnf_concept(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
node = get_input_nodes_from(
|
||||
concepts_map,
|
||||
"one plus twenty one",
|
||||
CNC("plus",
|
||||
a=UTN("one "),
|
||||
b=UTN("twenty one")))[0]
|
||||
|
||||
res = UnrecognizedNodeParser().validate_concept_node(context, node)
|
||||
|
||||
assert res.status
|
||||
concept_found = res.body.concept
|
||||
compiled = concept_found.get_compiled()
|
||||
assert concept_found == concepts_map["plus"]
|
||||
assert len(compiled["a"]) == 1
|
||||
assert sheerka.isinstance(compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
assert compiled["a"][0].body.body[0].concept.id == concepts_map["one"].id
|
||||
|
||||
assert len(compiled["b"]) == 1
|
||||
assert compiled["b"][0].status
|
||||
assert compiled["b"][0].who == "parsers.Bnf"
|
||||
|
||||
# evaluate
|
||||
context = self.get_context(sheerka, eval_body=True)
|
||||
evaluated = sheerka.evaluate_concept(context, res.body.concept)
|
||||
assert evaluated.body == 22
|
||||
|
||||
def test_i_can_parse_and_evaluate_unrecognized_python_node(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
Reference in New Issue
Block a user