Search in sources :

Example 1 with Term

use of org.jpl7.Term in project packages-jpl by SWI-Prolog.

the class FamilyMT method run.

public void run() {
    Map<String, Term> solution;
    // Variable X = new Variable("X");
    // 
    Query q2 = new Query("child_of(joe,ralf)");
    System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
    new Query("sleep(?)", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // 
    Query q3 = new Query("descendent_of(steve,ralf)");
    System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
    delay();
    // 
    Query q4 = new Query("descendent_of(X, ralf)");
    solution = q4.oneSolution();
    System.err.println("first solution of descendent_of(X, ralf)");
    System.err.println("X = " + solution.get("X"));
    delay();
    // 
    Map<String, Term>[] solutions = q4.allSolutions();
    System.err.println("all solutions of descendent_of(X, ralf)");
    for (int i = 0; i < solutions.length; i++) {
        System.err.println("X = " + solutions[i].get("X"));
    }
    delay();
    // 
    System.err.println("each solution of descendent_of(X, ralf)");
    while (q4.hasMoreSolutions()) {
        solution = q4.nextSolution();
        System.err.println("X = " + solution.get("X"));
    }
    delay();
    // 
    Query q5 = new Query("descendent_of(X, Y)");
    System.err.println(id + ": each solution of descendent_of(X, Y)");
    while (q5.hasMoreSolutions()) {
        solution = q5.nextSolution();
        System.err.println(id + ": X = " + solution.get("X") + ", Y = " + solution.get("Y"));
        delay();
    }
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 2 with Term

use of org.jpl7.Term in project packages-jpl by SWI-Prolog.

the class Test method test_3.

static void test_3() {
    System.out.print("test 3...");
    Query q3 = new Query("p", new Term[] { pair_a_b });
    if (!q3.hasSolution()) {
        System.out.println("p(a-b) failed");
    // System.exit(1);
    }
    System.out.println("passed");
}
Also used : Query(org.jpl7.Query)

Example 3 with Term

use of org.jpl7.Term in project packages-jpl by SWI-Prolog.

the class Test method test_9.

static void test_9() {
    System.out.print("test 9...");
    String t9 = "bagof(X-Y, p(X,Y), XYs)";
    Map<String, Term>[] solutions = Query.allSolutions(t9);
    if (solutions.length != 1) {
        System.out.println(t9 + " failed:");
        System.out.println("\tExpected: 1 solution");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    Term term = solutions[0].get("XYs");
    if (!term.isListPair()) {
        System.out.println(t9 + " failed:");
        System.out.println("\tExpected: XYs to be a List");
        System.out.println("\tGot:      " + term);
    // System.exit(1);
    }
    if (!term.equals(test_9_solution)) {
        System.out.println(t9 + " failed:");
        System.out.println("\tExpected: " + test_9_solution);
        System.out.println("\tGot:      " + term);
    // System.exit(1);
    }
    System.out.println("passed");
}
Also used : Term(org.jpl7.Term) Map(java.util.Map)

Example 4 with Term

use of org.jpl7.Term in project packages-jpl by SWI-Prolog.

the class Test method test_6.

static void test_6() {
    System.out.print("test 6...");
    Variable X = new Variable("X");
    Query q6 = new Query("p", new Term[] { X, X });
    Term[] x_target = new Term[] { a };
    Map<String, Term>[] solutions = q6.allSolutions();
    if (solutions.length != 1) {
        System.out.println("p(X, X) failed:");
        System.out.println("\tExpected: 1 solution");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    for (int i = 0; i < solutions.length; ++i) {
        Object x_binding = solutions[i].get("X");
        if (!x_binding.equals(x_target[i])) {
            System.out.println("p(X, X) failed:");
            System.out.println("\tExpected: " + x_target[i]);
            System.out.println("\tGot:      " + x_binding);
        // System.exit(1);
        }
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 5 with Term

use of org.jpl7.Term in project packages-jpl by SWI-Prolog.

the class Test method test_5.

static void test_5() {
    System.out.print("test 5...");
    Variable X = new Variable("X");
    Variable Y = new Variable("Y");
    Query q5 = new Query("p", new Term[] { X, Y });
    Term[] x_target = new Term[] { a, a };
    Term[] y_target = new Term[] { a, b };
    Map<String, Term>[] solutions = q5.allSolutions();
    if (solutions.length != 2) {
        System.out.println("p(X, Y) failed:");
        System.out.println("\tExpected: 2 solutions");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    for (int i = 0; i < solutions.length; ++i) {
        Term x_binding = solutions[i].get("X");
        if (!x_binding.equals(x_target[i])) {
            System.out.println("p(X, Y) failed:");
            System.out.println("\tExpected: " + x_target[i]);
            System.out.println("\tGot:      " + x_binding);
        // System.exit(1);
        }
        Term y_binding = solutions[i].get("Y");
        if (!y_binding.equals(y_target[i])) {
            System.out.println("p( X, Y ) failed:");
            System.out.println("\tExpected: " + y_target[i]);
            System.out.println("\tGot:      " + y_binding);
        // System.exit(1);
        }
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Aggregations

Term (org.jpl7.Term)62 Query (org.jpl7.Query)42 Variable (org.jpl7.Variable)24 Atom (org.jpl7.Atom)21 Compound (org.jpl7.Compound)21 Map (java.util.Map)12 BigInteger (java.math.BigInteger)6 Integer (org.jpl7.Integer)6 org.jpl7.fli.term_t (org.jpl7.fli.term_t)4 Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 PrologException (org.jpl7.PrologException)3 JPLException (org.jpl7.JPLException)2 IntHolder (org.jpl7.fli.IntHolder)2 URL (java.net.URL)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TestSuite (junit.framework.TestSuite)1 DoubleHolder (org.jpl7.fli.DoubleHolder)1 Int64Holder (org.jpl7.fli.Int64Holder)1 ObjectHolder (org.jpl7.fli.ObjectHolder)1