Exemple #1
0
def test_prepare_rule__or_starting_with_not():
    from pyknow import Rule, InitialFact, NOT, Fact, OR, AND

    rule = Rule(OR(NOT(Fact(1)), NOT(Fact(2))))(lambda: None)

    assert list(utils.prepare_rule(rule)) == [
        OR(AND(InitialFact(), NOT(Fact(1))), AND(InitialFact(), NOT(Fact(2))))
    ]
Exemple #2
0
def test_prepare_rule__or_starting_with_not():
    from pyknow import Rule, InitialFact, NOT, Fact, OR, AND

    rule = Rule(OR(NOT(Fact(1)), NOT(Fact(2))))(lambda:None)

    assert list(utils.prepare_rule(rule)) == [OR(AND(InitialFact(),
                                                     NOT(Fact(1))),
                                                 AND(InitialFact(),
                                                     NOT(Fact(2))))]
Exemple #3
0
def test_prepare_rule_is_dnf():
    from pyknow import Rule, NOT, AND, OR, Fact
    from pyknow.matchers.rete.dnf import dnf

    rule = Rule(AND(Fact(0), NOT(OR(Fact(1), Fact(2)))))(lambda:None)

    assert list(utils.prepare_rule(rule)) == [Fact(0),
                                              NOT(Fact(1)),
                                              NOT(Fact(2))]
Exemple #4
0
def test_prepare_rule_is_dnf():
    from pyknow import Rule, NOT, AND, OR, Fact
    from pyknow.matchers.rete.dnf import dnf

    rule = Rule(AND(Fact(0), NOT(OR(Fact(1), Fact(2)))))(lambda: None)

    assert list(
        utils.prepare_rule(rule)) == [Fact(0),
                                      NOT(Fact(1)),
                                      NOT(Fact(2))]
Exemple #5
0
def test_prepare_rule__and_inside_rule():
    from pyknow import Rule, AND, Fact

    rule = Rule(AND(Fact(1), Fact(2)))(lambda:None)

    assert list(utils.prepare_rule(rule)) == [Fact(1), Fact(2)]
Exemple #6
0
def test_prepare_rule__rule_starting_with_not():
    from pyknow import Rule, InitialFact, NOT, Fact

    rule = Rule(NOT(Fact(1)))(lambda:None)

    assert list(utils.prepare_rule(rule)) == [InitialFact(), NOT(Fact(1))]
Exemple #7
0
def test_prepare_rule_empty():
    from pyknow import Rule, InitialFact

    rule = Rule()(lambda:None)

    assert list(utils.prepare_rule(rule)) == [InitialFact()]
Exemple #8
0
def test_prepare_rule__and_inside_rule():
    from pyknow import Rule, AND, Fact

    rule = Rule(AND(Fact(1), Fact(2)))(lambda: None)

    assert list(utils.prepare_rule(rule)) == [Fact(1), Fact(2)]
Exemple #9
0
def test_prepare_rule__rule_starting_with_not():
    from pyknow import Rule, InitialFact, NOT, Fact

    rule = Rule(NOT(Fact(1)))(lambda: None)

    assert list(utils.prepare_rule(rule)) == [InitialFact(), NOT(Fact(1))]
Exemple #10
0
def test_prepare_rule_empty():
    from pyknow import Rule, InitialFact

    rule = Rule()(lambda: None)

    assert list(utils.prepare_rule(rule)) == [InitialFact()]