Added first version of DebugManager. Implemented draft of the rule engine
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import pytest
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept, ConceptParts, DoNotResolve, CC, DEFINITION_TYPE_BNF
|
||||
from core.concept import Concept, ConceptParts, DoNotResolve, CC, DEFINITION_TYPE_BNF, NotInit
|
||||
from core.sheerka.services.SheerkaExecute import ParserInput
|
||||
from parsers.BaseNodeParser import CNC, UTN, CN
|
||||
from parsers.BnfNodeParser import StrMatch, TerminalNode, NonTerminalNode, Sequence, OrderedChoice, \
|
||||
Optional, ZeroOrMore, OneOrMore, ConceptExpression, UnOrderedChoice, BnfNodeParser
|
||||
from parsers.BnfParser import BnfParser
|
||||
from parsers.BnfDefinitionParser import BnfDefinitionParser
|
||||
|
||||
import tests.parsers.parsers_utils
|
||||
from tests.BaseTest import BaseTest
|
||||
@@ -137,11 +137,11 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
@staticmethod
|
||||
def update_bnf(context, concept):
|
||||
bnf_parser = BnfParser()
|
||||
res = bnf_parser.parse(context, concept.metadata.definition)
|
||||
bnf_parser = BnfDefinitionParser()
|
||||
res = bnf_parser.parse(context, concept.get_metadata().definition)
|
||||
if res.status:
|
||||
concept.bnf = res.value.value
|
||||
concept.metadata.definition_type = DEFINITION_TYPE_BNF
|
||||
concept.set_bnf(res.value.value)
|
||||
concept.get_metadata().definition_type = DEFINITION_TYPE_BNF
|
||||
else:
|
||||
raise Exception(res)
|
||||
return concept
|
||||
@@ -572,16 +572,16 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
assert concept_foo.body == NotInit
|
||||
assert concept_foo.get_compiled() == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.body == NotInit
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
}
|
||||
assert id(concept_bar.compiled[ConceptParts.BODY]) == id(concept_bar.compiled["foo"])
|
||||
assert id(concept_bar.get_compiled()[ConceptParts.BODY]) == id(concept_bar.get_compiled()["foo"])
|
||||
|
||||
def test_i_can_refer_to_other_concepts_with_body(self):
|
||||
my_map = {
|
||||
@@ -598,12 +598,12 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert len(concept_foo.compiled) == 0 # because there is a body defined in the metadata
|
||||
assert concept_foo.body == NotInit
|
||||
assert len(concept_foo.get_compiled()) == 0 # because there is a body defined in the metadata
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.body == NotInit
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
}
|
||||
@@ -625,19 +625,19 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0][0].concept
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
assert concept_foo.body == NotInit
|
||||
assert concept_foo.get_compiled() == {ConceptParts.BODY: DoNotResolve("one two")}
|
||||
|
||||
concept_bar = sequences[1][0].concept
|
||||
assert concept_bar.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.body == NotInit
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: concept_foo,
|
||||
"foo": concept_foo
|
||||
}
|
||||
|
||||
concept_baz = sequences[2][0].concept
|
||||
assert concept_baz.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_baz.compiled == {
|
||||
assert concept_baz.body == NotInit
|
||||
assert concept_baz.get_compiled() == {
|
||||
ConceptParts.BODY: concept_bar,
|
||||
"bar": concept_bar
|
||||
}
|
||||
@@ -655,21 +655,21 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
expected = [CN("bar", source="twenty two")]
|
||||
sequences = self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
concept_bar = sequences[0].concept
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("twenty two"),
|
||||
"foo": my_map["foo"],
|
||||
}
|
||||
assert concept_bar.compiled["foo"].compiled == {ConceptParts.BODY: DoNotResolve("twenty")}
|
||||
assert concept_bar.get_compiled()["foo"].get_compiled() == {ConceptParts.BODY: DoNotResolve("twenty")}
|
||||
|
||||
text = "thirty one"
|
||||
expected = [CN("bar", source="thirty one")]
|
||||
sequences = self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
concept_bar = sequences[0].concept
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("thirty one"),
|
||||
"foo": my_map["foo"],
|
||||
}
|
||||
assert concept_bar.compiled["foo"].compiled == {ConceptParts.BODY: DoNotResolve("thirty")}
|
||||
assert concept_bar.get_compiled()["foo"].get_compiled() == {ConceptParts.BODY: DoNotResolve("thirty")}
|
||||
|
||||
text = "thirty three"
|
||||
expected = [[CN("foo", source="thirty"), CN("three")], []]
|
||||
@@ -712,21 +712,21 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
sheerka, context, sequences = self.exec_get_concepts_sequences(my_map, text, expected)
|
||||
|
||||
concept_bar = sequences[0].concept
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("twenty two"),
|
||||
"foo": sheerka.new("foo"),
|
||||
}
|
||||
assert concept_bar.compiled["foo"].compiled == {} # as foo as a body
|
||||
assert concept_bar.get_compiled()["foo"].get_compiled() == {} # as foo as a body
|
||||
|
||||
text = "thirty one"
|
||||
expected = [CN("bar", source="thirty one")]
|
||||
sequences = self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
concept_bar = sequences[0].concept
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("thirty one"),
|
||||
"foo": sheerka.new("foo"),
|
||||
}
|
||||
assert concept_bar.compiled["foo"].compiled == {}
|
||||
assert concept_bar.get_compiled()["foo"].get_compiled() == {}
|
||||
|
||||
def test_i_can_mix_zero_and_more_and_reference_to_other_concepts(self):
|
||||
my_map = {
|
||||
@@ -738,13 +738,13 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
expected = [CN("bar", source="one two three")]
|
||||
sequences = self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
concept_bar = sequences[0].concept
|
||||
assert concept_bar.compiled == {
|
||||
assert concept_bar.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("one two three"),
|
||||
"foo": [my_map["foo"], my_map["foo"], my_map["foo"]]
|
||||
}
|
||||
assert concept_bar.compiled["foo"][0].compiled == {ConceptParts.BODY: DoNotResolve("one")}
|
||||
assert concept_bar.compiled["foo"][1].compiled == {ConceptParts.BODY: DoNotResolve("two")}
|
||||
assert concept_bar.compiled["foo"][2].compiled == {ConceptParts.BODY: DoNotResolve("three")}
|
||||
assert concept_bar.get_compiled()["foo"][0].get_compiled() == {ConceptParts.BODY: DoNotResolve("one")}
|
||||
assert concept_bar.get_compiled()["foo"][1].get_compiled() == {ConceptParts.BODY: DoNotResolve("two")}
|
||||
assert concept_bar.get_compiled()["foo"][2].get_compiled() == {ConceptParts.BODY: DoNotResolve("three")}
|
||||
|
||||
def test_i_can_parse_concept_reference_that_is_not_in_grammar(self):
|
||||
my_map = {
|
||||
@@ -763,7 +763,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
expected = [CN("foo", source="twenty one")]
|
||||
sequences = self.validate_get_concepts_sequences(my_map, text, expected)
|
||||
concept_foo = sequences[0].concept
|
||||
assert concept_foo.compiled == {
|
||||
assert concept_foo.get_compiled() == {
|
||||
ConceptParts.BODY: DoNotResolve("twenty one"),
|
||||
"unit": my_map["one"],
|
||||
}
|
||||
@@ -786,8 +786,8 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0].concept
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {'number': CC(my_map["number"], body=my_map["two"], two=my_map["two"]),
|
||||
assert concept_foo.body == NotInit
|
||||
assert concept_foo.get_compiled() == {'number': CC(my_map["number"], body=my_map["two"], two=my_map["two"]),
|
||||
ConceptParts.BODY: DoNotResolve(value='twenty two')}
|
||||
|
||||
text = "twenty one"
|
||||
@@ -796,8 +796,8 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
# explicit validations of the compiled
|
||||
concept_foo = sequences[0].concept
|
||||
assert concept_foo.body == BuiltinConcepts.NOT_INITIALIZED
|
||||
assert concept_foo.compiled == {'number': CC(my_map["number"], body=my_map["one"], one=my_map["one"]),
|
||||
assert concept_foo.body == NotInit
|
||||
assert concept_foo.get_compiled() == {'number': CC(my_map["number"], body=my_map["one"], one=my_map["one"]),
|
||||
ConceptParts.BODY: DoNotResolve(value='twenty one')}
|
||||
|
||||
@pytest.mark.parametrize("bar_expr, expected", [
|
||||
@@ -1241,7 +1241,7 @@ class TestBnfNodeParser(TestUsingMemoryBasedSheerka):
|
||||
sheerka, context, parser = self.init_parser(init_from_sheerka=True)
|
||||
sheerka.concepts_grammars.clear() # simulate restart
|
||||
for c in cmap.values():
|
||||
sheerka.get_by_id(c.id).bnf = None
|
||||
sheerka.get_by_id(c.id).set_bnf(None)
|
||||
|
||||
text = "thirty three"
|
||||
expected = CNC("thirties",
|
||||
|
||||
Reference in New Issue
Block a user