예제 #1
0
def test_testRulesWithBinaryDisunifiers():
    program = [
        tc(X, Y) <= edge(X, Y),
        tc(X, Y) <= [edge(X, Z), tc(Z, Y)],
        edge(a, b),
        edge(b, c),
        edge(c, c),
        edge(c, d),
        noncycle(X, Y) <= [not_eq(X, Y), tc(X, Y)],
        beginsNotAtC(X, Y) <= [tc(X, Y), not_eq(c, X)],
        noC(X, Y) <= [edge(X, Y), not_eq(X, c),
                      not_eq(Y, c)],
        noC(X, Y) <= [noC(X, Z), noC(Z, Y)],
    ]

    ans = match_relations(program)
    assert ans(
        noncycle(X, Y),
        [
            noncycle(a, b),
            noncycle(a, c),
            noncycle(a, d),
            noncycle(b, c),
            noncycle(b, d),
            noncycle(c, d),
        ],
    )
    assert ans(
        beginsNotAtC(X, Y),
        [
            beginsNotAtC(a, b),
            beginsNotAtC(a, c),
            beginsNotAtC(a, d),
            beginsNotAtC(b, c),
            beginsNotAtC(b, d),
        ],
    )
    assert ans(noC(X, Y), [noC(a, b)])
예제 #2
0
def test_testBinaryDisunificationFail2():
    program = [p(X) <= [q(X), not_eq(Y, _)], q(a)]
    with pytest.raises(DatalogValidationException):
        match_relations(program, p(X), [])


# def test_gt():
#     age = relation("age")
#     senior = relation("senior")
#     program = [
#         age("John", 28),
#         age("Mary", 40),
#         age("Dad", 60),
#         age("Mom", 70),
#         senior(X, Y) <= [age(X, Y), gt(Y, 59)]
#     ]
#     ans = match_relations(program)
#     assert ans(senior(X, Y), [age("Dad", 60), age("Mom", 70)])
예제 #3
0
mayra = "mayra"
noe = "noe"
odell = "odell"
reanna = "reanna"
sona = "sona"
terra = "terra"
ursula = "ursula"
virgilio = "virgilio"

related_data = [
    siblings(X, Y) <=
    [person(X),
     person(Y),
     parent_of(Z, X),
     parent_of(Z, Y),
     not_eq(X, Y)],
    ancestor(X, Y) <= [person(X), person(Y),
                       parent_of(X, Y)],
    ancestor(X, Z) <=
    [person(X), person(Y),
     parent_of(X, Y), ancestor(Y, Z)],
    related(X, Y) <= ancestor(X, Y),
    related(X, Y) <= ancestor(Y, X),
    related(X, Y) <= siblings(X, Y),
    related(X, Y) <= [ancestor(
        Z, X), ancestor(Z, Y), not_eq(X, Y)],
    same_generation(X, Y) <= [parent_of(
        Z, X), parent_of(Z, Y), not_eq(X, Y)],
    same_generation(X, Y) <=
    [same_generation(U, V),
     parent_of(U, X),
예제 #4
0
def test_testExplicitUnification2():
    program = [p() <= [~q(X, b), not_eq(X, a)]]
    with pytest.raises(DatalogValidationException):
        match_relations(program, p(), [])
예제 #5
0
def test_testBinaryDisunificationFail1():
    program = [p() <= [~q(a, b), not_eq(X, _)]]
    with pytest.raises(DatalogValidationException):
        match_relations(program, p(), [])
예제 #6
0
def test_testImpossibleBinaryDisunification2():
    program = [p() <= [eq(Z, a), not_eq(X, Y), eq(a, X), eq(Z, Y)]]
    assert match_relations(program, p(), [])
예제 #7
0
def test_testImpossibleBinaryDisunification1():
    assert match_relations([p() <= not_eq(a, a)], p(), [])
예제 #8
0
def test_testBinaryDisunificationNoAtom():
    program = [p() <= not_eq(a, b), q() <= [not_eq(X, Y), eq(X, a), eq(Y, b)]]
    ans = match_relations(program)
    assert ans(p(), [p()])
    assert ans(q(), [q()])