Example #1
0
def test_evaluate_bounded_projection_function():
    yp = YP()
    yp.assert_fact(yp.atom('cat'), [yp.atom('tom')])
    V1 = yp.variable()
    q = yp.query('cat', [V1])
    r = yp.evaluate_bounded(q, (lambda x: V1.get_value()))
    assert r == [yp.atom('tom')]
Example #2
0
def test_setup_yp():
    yp = YP()
    yp.assert_fact(yp.atom('cat'), [yp.atom('tom')])
    V1 = yp.variable()
    args = [V1]
    q = yp.query('cat', args)
    r = [[v.get_value() for v in args] for r in q]
    assert r == [[yp.atom('tom')]]
Example #3
0
def test_assert_facts_concurrently():
    yp1 = YP()
    yp2 = YP()
    yp1.assert_fact(yp1.atom('fact'), [yp1.atom('red')])
    yp2.assert_fact(yp2.atom('fact'), [yp2.atom('blue')])
    X1 = yp1.variable()
    q1 = yp1.query('fact', [X1])
    X2 = yp2.variable()
    q2 = yp2.query('fact', [X2])
    r1 = [X1.get_value() for r in q1]
    r2 = [X2.get_value() for r in q2]
    assert r1 != r2
Example #4
0
def test_match_example_horizontal_vertical():
    yp = YP()
    X = yp.variable()
    Y = yp.variable()
    X1 = yp.variable()
    Y1 = yp.variable()
    # vertical(seg(point(X,Y),point(X,Y1))).
    yp.assert_fact(yp.atom('vertical'), [
        yp.functor('seg',
                   [yp.functor('point', [X, Y]),
                    yp.functor('point', [X, Y1])])
    ])
    # horizontal(seg(point(X,Y),point(X1,Y))).
    yp.assert_fact(yp.atom('horizontal'), [
        yp.functor('seg',
                   [yp.functor('point', [X, Y]),
                    yp.functor('point', [X1, Y])])
    ])

    # q0 = yp.match_dynamic(yp.atom('vertical'), [
    q0 = yp.query('vertical', [
        yp.functor('seg',
                   [yp.functor('point', [1, 1]),
                    yp.functor('point', [1, 2])])
    ])

    # q1 = yp.match_dynamic(yp.atom('vertical'), [
    q1 = yp.query('vertical', [
        yp.functor('seg',
                   [yp.functor('point', [1, 1]),
                    yp.functor('point', [2, Y])])
    ])

    # q2 = yp.match_dynamic(yp.atom('horizontal'), [
    q2 = yp.query('horizontal', [
        yp.functor('seg',
                   [yp.functor('point', [1, 1]),
                    yp.functor('point', [2, Y])])
    ])

    r0 = list(q0)
    r1 = list(q1)
    r2 = [Y.get_value() for r in q2]

    assert r0 == [False]
    assert r1 == []
    assert r2 == [1]