Example #1
0
def test_and_inside_and():
    from experta import Fact, Rule, AND
    from experta.matchers.rete.dnf import dnf

    input_ = AND(Fact(a=1), AND(Fact(a=3), Fact(a=4)))
    output = AND(Fact(a=1), Fact(a=3), Fact(a=4))
    assert dnf(input_) == output
Example #2
0
def test_or_inside_and():
    from experta import Fact, Rule, AND, OR
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(AND(Fact(a=1), OR(Fact(a=2), Fact(a=3))))
    output = Rule(OR(AND(Fact(a=1), Fact(a=2)), AND(Fact(a=1), Fact(a=3))))
    assert dnf(input_[0]) == output[0]
Example #3
0
def test_or_and_fact_inside_or():
    from experta import Fact, OR, Rule
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(OR(Fact(a=1), OR(Fact(a=2), Fact(a=3))))
    output = Rule(OR(Fact(a=1), Fact(a=2), Fact(a=3)))
    assert dnf(input_) == output
Example #4
0
def test_double_not_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=~~L(1)))
    output = Rule(Fact(a=L(1)))

    result = dnf(input_)
    assert result == output
Example #5
0
def test_or_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=L(1) | L(2), b=3))
    output = Rule(OR(Fact(a=L(1), b=3), Fact(a=L(2), b=3)))

    result = dnf(input_)
    assert set(result[0]) == set(output[0])
Example #6
0
def test_and_inside_rule():
    from experta import Fact, Rule, AND
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=1), AND(Fact(b=2), Fact(c=3)))
    output = Rule(Fact(a=1), Fact(b=2), Fact(c=3))

    result = dnf(input_)
    assert result == output
Example #7
0
def test_or_inside_or_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=L(1) | (L(2) | L(3))))
    output = Rule(OR(Fact(a=L(1)), Fact(a=L(2)), Fact(a=L(3))))

    result = dnf(input_)
    assert result == output
Example #8
0
def test_not_and_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=~(L(1) & L(2))))
    output = Rule(OR(Fact(a=~L(1)), Fact(a=~L(2))))

    result = dnf(input_)
    assert result == output
Example #9
0
def test_or_inside_or_inside_and():
    from experta import Fact, OR, AND, Rule
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(AND(Fact(b=1), OR(Fact(a=1), OR(Fact(a=3), Fact(a=4)))))
    output = Rule(
        OR(AND(Fact(b=1), Fact(a=1)), AND(Fact(b=1), Fact(a=3)),
           AND(Fact(b=1), Fact(a=4))))
    result = dnf(input_)
    assert result == output
Example #10
0
def test_and_inside_or_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.fieldconstraint import ANDFC
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=L(1) | (L(2) & L(3))))
    output = Rule(OR(Fact(a=L(1)), Fact(a=ANDFC(L(2), L(3)))))

    result = dnf(input_)
    assert result == output
Example #11
0
def test_not_or_inside_fact():
    from experta import Fact, OR, Rule, L
    from experta.fieldconstraint import ANDFC, NOTFC
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=~(L(1) | L(2))))
    output = Rule(Fact(a=ANDFC(NOTFC(L(1)), NOTFC(L(2)))))

    result = dnf(input_)
    assert result == output
Example #12
0
def test_multiple_or_inside_rule():
    from experta import Fact, OR, Rule, AND
    from experta.matchers.rete.dnf import dnf

    input_ = Rule(Fact(a=1), OR(Fact(b=1), Fact(b=2)),
                  OR(Fact(c=1), Fact(c=2)))
    output_ = Rule(
        OR(AND(Fact(a=1), Fact(b=1), Fact(c=1)),
           AND(Fact(a=1), Fact(b=1), Fact(c=2)),
           AND(Fact(a=1), Fact(b=2), Fact(c=1)),
           AND(Fact(a=1), Fact(b=2), Fact(c=2))))

    result = dnf(input_)
    assert result == output_