Пример #1
0
def test_testRulesWithBinaryUnifiers():

    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),
        cycle(X) <= [eq(X, Y), tc(X, Y)],
        beginsAtC(X, Y) <= [tc(X, Y), eq(c, X)],
    ]
    ans = match_relations(program)
    assert ans(cycle(X), [cycle(c)])
    assert ans(beginsAtC(X, Y), [beginsAtC(c, c), beginsAtC(c, d)])
Пример #2
0
def test_testBinaryUnificationNoAtom():
    program = [
        p(X, b) <= eq(X, a),
        p(b, Y) <= eq(Y, a),
        p(X, Y) <= [eq(X, c), eq(Y, d)],
        p(X, X) <= eq(X, c),
        p(X, Y) <= [eq(X, d), eq(Y, X)],
        p(X, Y) <= [eq(X, Y), eq(X, e)],
    ]

    ans = match_relations(program)
    assert ans(p(X, Y), [p(a, b), p(b, a), p(c, d), p(c, c), p(d, d), p(e, e)])
    program = program + [q(X, Y) <= p(X, Y)]
    ans = match_relations(program)
    assert ans(q(X, Y), [q(a, b), q(b, a), q(c, d), q(c, c), q(d, d), q(e, e)])
Пример #3
0
def test_testNegatedNoPositiveAtom():
    program = [p(a) <= ~q(a), p(b) <= [~q(X), eq(X, b)]]
    assert match_relations(program, p(X), [p(a), p(b)])
Пример #4
0
def test_testExplicitUnification1():
    program = [p() <= [~q(X, b), eq(X, a)]]
    assert match_relations(program, p(), [p()])
Пример #5
0
def test_testImpossibleBinaryUnification2():
    assert match_relations([p() <= [eq(
        Z, b), eq(X, Y), eq(a, X), eq(Z, Y)]], p(), [])
Пример #6
0
def testImpossibleBinaryUnification1():
    assert match_relations([p() <= eq(a, b)], p(), [])
Пример #7
0
def testUselessBinaryUnification():
    program = [p(X) <= [q(X), eq(X, Y)], q(a), p(b) <= eq(X, _)]
    ans = match_relations(program)
    with pytest.raises(DatalogValidationException):
        ans(p(X), [])
Пример #8
0
def test_testImpossibleBinaryDisunification3():
    program = [p() <= [q(X), eq(X, X)]]
    ans = match_relations(program)
    assert ans(p(), [])
Пример #9
0
def test_testImpossibleBinaryDisunification2():
    program = [p() <= [eq(Z, a), not_eq(X, Y), eq(a, X), eq(Z, Y)]]
    assert match_relations(program, p(), [])
Пример #10
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()])