Search in sources :

Example 41 with Query

use of org.jpl7.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 42 with Query

use of org.jpl7.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 43 with Query

use of org.jpl7.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)

Example 44 with Query

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

the class AddWithThreads method testThreadedAdds.

public void testThreadedAdds() {
    latch = new CountDownLatch(4);
    final AddWithThreads[] addTasks = { new AddWithThreads("a", latch), new AddWithThreads("b", latch), new AddWithThreads("c", latch), new AddWithThreads("d", latch) };
    // System.out.println("Starting threads...");
    for (int i = 0; i < addTasks.length; i++) {
        addTasks[i].start();
    }
    try {
        // System.out.println("Latch is waiting");
        assertTrue("Timed out waiting for action to execute", latch.await(20, TimeUnit.SECONDS));
    // System.out.println("Latch has been flipped");
    } catch (final InterruptedException e) {
        fail("Waiting thread was interrupted: " + e);
    }
    for (int i = 0; i < AddWithThreads.REPS; i++) {
        for (int j = 0; j < addTasks.length; j++) {
            Query query = new Query(addTasks[j].getNamespace() + "(test('" + i + "'))");
            // System.out.println("query: " + query);
            // boolean ret = query.hasMoreElements();
            query.close();
        }
    }
}
Also used : Query(org.jpl7.Query) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 45 with Query

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

the class Family method run.

public void run() {
    Map<String, Term> solution;
    Variable X = new Variable("X");
    // --------------------------------------------------
    Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("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", new Term[] { new Atom("steve"), new Atom("ralf") });
    System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf") });
    solution = q4.oneSolution();
    System.err.println("first solution of descendent_of(X, ralf)");
    System.err.println("X = " + solution.get(X.name));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    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.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    System.err.println("each solution of descendent_of(X, ralf)");
    while (q4.hasMoreSolutions()) {
        solution = q4.nextSolution();
        System.err.println("X = " + solution.get(X.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Variable Y = new Variable("Y");
    Query q5 = new Query("descendent_of", new Term[] { 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.name) + ", Y = " + solution.get(Y.name));
        new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    }
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map) Atom(org.jpl7.Atom)

Aggregations

Query (org.jpl7.Query)56 Term (org.jpl7.Term)33 Variable (org.jpl7.Variable)23 Atom (org.jpl7.Atom)16 Compound (org.jpl7.Compound)16 Map (java.util.Map)13 Query (com.google.datastore.v1.Query)12 Test (org.junit.Test)8 GqlQuery (com.google.datastore.v1.GqlQuery)7 Integer (org.jpl7.Integer)6 Datastore (com.google.datastore.v1.client.Datastore)4 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)4 Entity (com.google.datastore.v1.Entity)3 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)3 BigInteger (java.math.BigInteger)3 PrologException (org.jpl7.PrologException)3 PartitionId (com.google.datastore.v1.PartitionId)2 DeleteEntity (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.DeleteEntity)2 JPLException (org.jpl7.JPLException)2 Handle (org.skife.jdbi.v2.Handle)2