Search in sources :

Example 51 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class Test method test_7.

static void test_7() {
    System.out.print("test 7...");
    String t7 = "r(f(X,X), Y)";
    Variable vX = new Variable("X");
    Variable vY = new Variable("Y");
    Query q7 = new Query("r", new Term[] { new Compound("f", new Term[] { vX, vX }), vY });
    Map<String, Term>[] solutions = q7.allSolutions();
    if (solutions.length != 2) {
        System.out.println(t7 + " failed:");
        System.out.println("\tExpected: 2 solutions");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    Term X = solutions[0].get("X");
    Term Y = solutions[0].get("Y");
    if (X != Y) {
        System.out.println(t7 + " failed:");
        System.out.println(Util.toString(solutions[0]));
        System.out.println("\tThe variables to which X and Y are bound in the first solution should be identical.");
    // System.exit(1);
    }
    X = solutions[1].get("X");
    Y = solutions[1].get("Y");
    if (X == Y) {
        System.out.println(t7 + " failed:");
        System.out.println(Util.toString(solutions[1]));
        System.out.println("\tThe variables to which X and Y are bound in the second solution should be distinct.");
    // System.exit(1);
    }
    if (X.equals(Y)) {
        System.out.println(t7 + " failed:");
        System.out.println(Util.toString(solutions[1]));
        System.out.println("\tThe variables to which X and Y are bound in the second solution should not be \"equal\".");
    // System.exit(1);
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Map(java.util.Map)

Example 52 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestGC method main.

public static void main(String[] argv) {
    int max;
    Query.hasSolution("consult('test.pl')");
    if (argv.length > 0)
        max = Integer.parseInt(argv[0]);
    else
        max = 10;
    System.out.println(max + " iterations");
    for (int i = 0; i < max; i++) {
        Query q = new Query("testpred", new Term[] { new Atom("a" + i) });
        q.oneSolution();
    }
    Query.hasSolution("stats");
}
Also used : Query(org.jpl7.Query) Atom(org.jpl7.Atom)

Example 53 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class Time method test_3.

static void test_3() {
    Variable Y = new Variable("Y");
    Query query = new Query("noop_nobind", new Term[] { tree, Y });
    System.out.print("noop_nobind");
    for (int i = 0; i < num_trials; ++i) {
        timer.start();
        query.hasSolution();
        timer.stop();
        data[3][i] = timer.getElapsedTimeInMillis();
        System.out.print(".");
    }
    System.out.println("done");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query)

Example 54 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class Time method test_1.

static void test_1() {
    Query query = new Query("traverse", new Term[] { tree });
    System.out.print("traverse");
    for (int i = 0; i < num_trials; ++i) {
        timer.start();
        query.hasSolution();
        timer.stop();
        data[1][i] = timer.getElapsedTimeInMillis();
        System.out.print(".");
    }
    System.out.println("done");
}
Also used : Query(org.jpl7.Query)

Example 55 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class FetchLongList method main.

public static void main(String[] args) {
    // Prolog.set_default_init_args(new String[] { "libpl.dll", "-f",
    // "D:/pcm/bin/pcm.ini", "-g", "pcm_2000" });
    Term t = (Term) ((new Query("findall(foo(N,bar),between(1,2308,N),L)")).oneSolution().get("L"));
    int i = 0;
    while (t.hasFunctor(".", 2)) {
        t = t.arg(2);
        i = i + 1;
    }
    System.err.println("got a list of " + i + " members");
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Aggregations

Query (org.jpl7.Query)56 Term (org.jpl7.Term)33 Variable (org.jpl7.Variable)23 Map (java.util.Map)18 Atom (org.jpl7.Atom)16 Compound (org.jpl7.Compound)16 Query (com.google.datastore.v1.Query)12 Handle (org.skife.jdbi.v2.Handle)12 Test (org.junit.Test)10 GqlQuery (com.google.datastore.v1.GqlQuery)7 Integer (org.jpl7.Integer)6 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 Datastore (com.google.datastore.v1.client.Datastore)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)4 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)3 Nullable (javax.annotation.Nullable)3