Fixed #100 : SheerkaAdmin: Add builtins() command

Fixed #99 : SheerkaQueryManager: I can manage contains predicate when filtering objects
Fixed #97 : ERROR: list indices must be integers or slices, not Concept
Fixed #96 : SequenceNodeParser: SequenceNodeParser must correctly handle concept definition
Fixed #95 : ResolveAmbiguity must not remove concepts that do not require evaluation
Fixed #94 : Concepts with the same key are lost when new ontology
Fixed #93 : Introduce BuiltinConcepts.EVAL_GLOBAL_TRUTH_REQUESTED
Fixed #92 : ExpressionParser: Implement compile_disjunctions()
Fixed #91 : Implement get_concepts_complexity(context, concepts, concept_parts)
Fixed #90 : ResolveAmbiguity : where predicate is not used to resolve ambiguity
Fixed #89 : ResolveAmbiguityEvaluator: Concepts embedded in ConceptNode are not resolved
Fixed #88: SyaNodeParser: Parse multiple parameters when some of the are not recognized
Fixed #87: SyaNodeParser : Parse the multiple parameters
This commit is contained in:
2021-07-31 08:52:00 +02:00
parent 7dcaa9c111
commit e69745adc8
70 changed files with 1561 additions and 455 deletions
+85 -1
View File
@@ -4,7 +4,7 @@ from core.builtin_concepts import BuiltinConcepts
from core.sheerka.services.SheerkaExecute import ParserInput
from core.tokenizer import TokenKind
from parsers.BaseExpressionParser import TrueifyVisitor, IsAQuestionVisitor, LeftPartNotFoundError, \
ParenthesisMismatchError
ParenthesisMismatchError, compile_disjunctions, NotNode, AndNode, OrNode
from parsers.BaseParser import UnexpectedEofParsingError, UnexpectedTokenParsingError
from parsers.LogicalOperatorParser import LogicalOperatorParser
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
@@ -12,6 +12,46 @@ from tests.parsers.parsers_utils import EXPR, OR, AND, NOT, \
get_expr_node_from_test_node
class DoNotCompareStartStopContextManager:
def __init__(self):
self.original_not_eq = None
self.original_and_eq = None
self.original_or_eq = None
@staticmethod
def not_eq(self, other):
if not isinstance(other, NotNode):
return False
return self.node == other.node
@staticmethod
def and_eq(self, other):
if not isinstance(other, AndNode):
return False
return self.parts == other.parts
@staticmethod
def or_eq(self, other):
if not isinstance(other, OrNode):
return False
return self.parts == other.parts
def __enter__(self):
self.original_not_eq = NotNode.__eq__
self.original_and_eq = AndNode.__eq__
self.original_or_eq = OrNode.__eq__
NotNode.__eq__ = self.not_eq
AndNode.__eq__ = self.and_eq
OrNode.__eq__ = self.or_eq
def __exit__(self, *args):
NotNode.__eq__ = self.original_not_eq
AndNode.__eq__ = self.original_and_eq
OrNode.__eq__ = self.original_or_eq
class TestLogicalOperatorParser(TestUsingMemoryBasedSheerka):
def init_parser(self):
@@ -175,6 +215,50 @@ class TestLogicalOperatorParser(TestUsingMemoryBasedSheerka):
assert IsAQuestionVisitor().visit(expr_node) == expected
@pytest.mark.parametrize("expression, expected", [
("a", [EXPR("a")]),
("a and b and c", [AND(EXPR("a"), EXPR("b"), EXPR("c"))]),
("a or b or c", [EXPR("a"),
EXPR("b"),
EXPR("c")]),
("a and b or c", [AND(EXPR("a"), EXPR("b")), EXPR("c")]),
("a or b and c", [EXPR("a"),
AND(EXPR("b"), EXPR("c"))]),
("(a or b) and c", [AND(EXPR("a"), EXPR("c")),
AND(EXPR("b"), EXPR("c"))]),
("a or (b or c) and d", [EXPR("a"),
AND(EXPR("b"), EXPR("d")),
AND(EXPR("c"), EXPR("d"))]),
("not a", [NOT(EXPR("a"))]),
("not (a and b)", [NOT(AND(EXPR("a"), EXPR("b")))]),
("not (a or b)", [AND(NOT(EXPR("a")), NOT(EXPR("b")))]),
("(a or b) and not (c or d)", [AND(EXPR("a"), NOT(EXPR("c")), NOT(EXPR("d"))),
AND(EXPR("b"), NOT(EXPR("c")), NOT(EXPR("d")))]),
("(a or b) or not (c or d)", [EXPR("a"),
EXPR("b"),
AND(NOT(EXPR("c")), NOT(EXPR("d")))]),
("(a and b) and not (c or d)", [AND(EXPR("a"), EXPR("b"), NOT(EXPR("c")), NOT(EXPR("d")))]),
("(a and b) or not (c or d)", [AND(EXPR("a"), EXPR("b")),
AND(NOT(EXPR("c")), NOT(EXPR("d")))]),
("a and (b and c)", [AND(EXPR("a"), EXPR("b"), EXPR("c"))]),
("a or (b or c)", [EXPR("a"),
EXPR("b"),
EXPR("c")]),
])
def test_i_can_compile_disjunction(self, expression, expected):
sheerka, context, parser = self.init_parser()
resolved_expected = [get_expr_node_from_test_node(expression, e) for e in expected]
expr_node = parser.parse(context, ParserInput(expression)).body.body
with DoNotCompareStartStopContextManager():
res = compile_disjunctions(expr_node)
assert res == resolved_expected
# @pytest.mark.parametrize("expression, expected", [
# ("foo", "foo"),
# ("one two", "one two"),