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:
@@ -1169,7 +1169,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
:return:
|
||||
"""
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear() # to simulate restart
|
||||
sheerka.clear_bnf_definition() # to simulate restart
|
||||
text = "one thousand"
|
||||
|
||||
one = CC("one", body=DoNotResolve("one"))
|
||||
@@ -1195,7 +1195,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
:return:
|
||||
"""
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear() # to simulate restart
|
||||
sheerka.clear_bnf_definition() # to simulate restart
|
||||
text = "fifty one thousand"
|
||||
|
||||
one = CC("one", body=DoNotResolve("one"))
|
||||
@@ -1233,7 +1233,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_i_can_parse_one_hundred_thousand(self):
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear() # to simulate restart
|
||||
sheerka.clear_bnf_definition() # to simulate restart
|
||||
|
||||
text = "one hundred thousand"
|
||||
res = parser.parse(context, ParserInput(text))
|
||||
@@ -1244,7 +1244,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_i_can_parse_hundreds_like_expression(self):
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear()
|
||||
sheerka.clear_bnf_definition() # to simulate restart
|
||||
|
||||
text = "three hundred and thirty two"
|
||||
three = CC("three", body=DoNotResolve("three"))
|
||||
@@ -1280,7 +1280,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
def test_i_can_parse_bnf_concept_mixed_with_isa_after_restart(self):
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear() # simulate restart
|
||||
sheerka.clear_bnf_definition() # to simulate restart
|
||||
for c in cmap.values():
|
||||
sheerka.get_by_id(c.id).set_bnf(None)
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import pytest
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.rule import Rule
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from parsers.BaseNodeParser import SCN, SCWC, CN, UTN, CNC, RN
|
||||
from parsers.FunctionParser import FunctionParser, FN
|
||||
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
from tests.parsers.parsers_utils import compute_expected_array
|
||||
|
||||
|
||||
@@ -968,7 +968,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
def test_i_can_debug(self, expression, expected_debugs):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
sheerka.set_debug(context, True)
|
||||
sheerka.debug_var(context, "Sya")
|
||||
sheerka.set_debug_var(context, "Sya")
|
||||
res = parser.infix_to_postfix(context, ParserInput(expression))
|
||||
|
||||
assert len(res) == len(expected_debugs)
|
||||
@@ -983,7 +983,7 @@ class TestSyaNodeParser(TestUsingMemoryBasedSheerka):
|
||||
def test_i_can_debug_can_pop_using_star(self, settings):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
sheerka.set_debug(context, True)
|
||||
sheerka.debug_var(context, settings)
|
||||
sheerka.set_debug_var(context, settings)
|
||||
res = parser.infix_to_postfix(context, ParserInput("one plus two mult three"))
|
||||
|
||||
debug = [str(di) for di in res[0].debug]
|
||||
|
||||
@@ -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