예제 #1
0
def _swipy_to_list(term):
    elements = []
    list = swipy.swipy_copy_term_ref(term)

    head = swipy.swipy_new_term_ref()

    while swipy.swipy_get_list(list, head, list):
        elements.append(_read_swipy(head))

    return List(elements)
예제 #2
0
def gnu_test1(pl):
    #pl = GNUProlog()

    p = c_pred("p", 2)
    f = c_functor("t", 3)
    f1 = p("a", "b")

    pl.assertz(f1)

    X = c_var("X")
    Y = c_var("Y")

    query = p(X, Y)

    r = pl.has_solution(query)
    print("has solution", r)

    rv = pl.query(query)
    print("all solutions", rv)

    f2 = p("a", "c")
    pl.assertz(f2)

    rv = pl.query(query)
    print("all solutions after adding f2", rv)

    func1 = f(1, 2, 3)
    f3 = p(func1, "b")
    pl.assertz(f3)

    rv = pl.query(query)
    print("all solutions after adding structure", rv)

    l = List([1, 2, 3, 4, 5])

    member = c_pred("member", 2)

    query2 = member(X, l)

    rv = pl.query(query2)
    print("all solutions to list membership ", rv)

    r = c_pred("r", 2)
    f4 = r("a", l)
    f5 = r("a", "b")

    pl.asserta(f4)
    pl.asserta(f5)

    query3 = r(X, Y)

    rv = pl.query(query3)
    print("all solutions after adding list ", rv)

    del pl
예제 #3
0
    def test6():
        solver = SWIProlog()

        head = c_pred("head", 2)
        tail = c_pred("tail", 2)
        take_second = c_pred("take_second", 2)
        H = c_var("Head")
        T = c_var("Tail")
        X = c_var("X")
        Y = c_var("Y")

        hatm1 = head(Pair(H, T), H)
        tatm1 = tail(Pair(H, T), T)
        cl = (take_second(X,Y) <= tail(X, T) & head(T, Y))

        solver.assertz(hatm1)
        solver.assertz(tatm1)
        solver.assertz(cl)

        l = List([1,2,3,4,5])
        print(solver.query(take_second(l, X)))

        del solver
예제 #4
0
    def test1():
        pl = SWIProlog()

        p = c_pred("p", 2)
        f = c_functor("t", 3)
        f1 = p("a", "b")

        pl.assertz(f1)

        X = c_var("X")
        Y = c_var("Y")

        query = p(X, Y)

        r = pl.has_solution(query)
        print("has solution", r)

        rv = pl.query(query)
        print("all solutions", rv)

        f2 = p("a", "c")
        pl.assertz(f2)

        rv = pl.query(query)
        print("all solutions after adding f2", rv)

        func1 = f(1, 2, 3)
        f3 = p(func1, "b")
        pl.assertz(f3)

        rv = pl.query(query)
        print("all solutions after adding structure", rv)

        l = List([1, 2, 3, 4, 5])

        member = c_pred("member", 2)

        query2 = member(X, l)

        rv = pl.query(query2)
        print("all solutions to list membership ", rv)

        r = c_pred("r", 2)
        f4 = r("a", l)
        f5 = r("a", "b")

        pl.asserta(f4)
        pl.asserta(f5)

        query3 = r(X, Y)

        rv = pl.query(query3)
        print("all solutions after adding list ", rv)

        # Foreign predicates

        def hello(t):
            print("Foreign: Hello", t)

        hello_pred = pl.register_foreign(hello, 1)
        # print(hello_pred)

        f_query = hello_pred("a")

        pl.has_solution(f_query)

        del pl
예제 #5
0
def _pygp_to_list(term):
    elems = pygprolog.pygp_Rd_List(term)
    elems = [_read_pygp(x) for x in elems]

    return List(elems)
예제 #6
0
def _pyxsb_string_to_list(term: str):
    args = [
        _pyxsb_string_to_pylo(x)
        for x in _extract_arguments_from_compound(term)
    ]
    return List(args)
예제 #7
0
    def test7(limit=10):
        pl = XSBProlog("/Users/seb/Documents/programs/XSB")

        p = c_pred("p", 2)
        f = c_functor("t", 3)
        f1 = p("a", "b")

        pl.assertz(f1)

        X = c_var("X")
        Y = c_var("Y")

        query = p(X, Y)

        r = pl.has_solution(query)
        print("has solution", r)

        rv = pl.query(query, time_limit=limit)
        print("all solutions", rv)

        f2 = p("a", "c")
        pl.assertz(f2)

        rv = pl.query(query, time_limit=limit)
        print("all solutions after adding f2", rv)

        func1 = f(1, 2, 3)
        f3 = p(func1, "b")
        pl.assertz(f3)

        rv = pl.query(query, time_limit=limit)
        print("all solutions after adding structure", rv)

        l = List([1, 2, 3, 4, 5])

        member = c_pred("member", 2)
        pl.use_module("lists", predicates=[member])

        query2 = member(X, l)

        rv = pl.query(query2, time_limit=limit)
        print("all solutions to list membership ", rv)

        r = c_pred("r", 2)
        f4 = r("a", l)
        f5 = r("a", "b")

        pl.asserta(f4)
        pl.asserta(f5)

        query3 = r(X, Y)

        rv = pl.query(query3, time_limit=limit)
        print("all solutions after adding list ", rv)

        q = c_pred("q", 2)
        cl = (q("X", "Y") <= r("X", "Y") & r("X", "Z"))

        pl.assertz(cl)
        query4 = q("X", "Y")
        rv = pl.query(query4, time_limit=limit)
        print("all solutions to q: ", rv)

        del pl
예제 #8
0
print("all solutions", rv)

f2 = p("a", "c")
pl.assertz(f2)

rv = pl.query(query)
print("all solutions after adding f2", rv)

func1 = f(1, 2, 3)
f3 = p(func1, "b")
pl.assertz(f3)

rv = pl.query(query)
print("all solutions after adding structure", rv)

l = List([1, 2, 3, 4, 5])

member = global_context.get_predicate("member", 2)

query2 = member(X, l)

rv = pl.query(query2)
print("all solutions to list membership ", rv)

r = global_context.get_predicate("r", 2)
f4 = r("a", l)
f5 = r("a", "b")

pl.asserta(f4)
pl.asserta(f5)