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)])
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)])
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),
def test_testExplicitUnification2(): program = [p() <= [~q(X, b), not_eq(X, a)]] with pytest.raises(DatalogValidationException): match_relations(program, p(), [])
def test_testBinaryDisunificationFail1(): program = [p() <= [~q(a, b), not_eq(X, _)]] with pytest.raises(DatalogValidationException): match_relations(program, p(), [])
def test_testImpossibleBinaryDisunification2(): program = [p() <= [eq(Z, a), not_eq(X, Y), eq(a, X), eq(Z, Y)]] assert match_relations(program, p(), [])
def test_testImpossibleBinaryDisunification1(): assert match_relations([p() <= not_eq(a, a)], p(), [])
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()])