Search in sources :

Example 6 with Query

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

the class Time method test_2.

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

Example 7 with Query

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

the class Time method test_4.

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

Example 8 with Query

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

the class Zahed method main.

public static void main(java.lang.String[] argv) {
    System.out.println("starting...");
    Compound goal1 = new Compound("consult", new Term[] { new Atom("zahed.pl") });
    Query q1 = new Query(goal1);
    if (!q1.hasSolution()) {
        System.out.println("consult('zahed.pl') failed");
        return;
    }
    Term t2 = new Compound("t", new Term[] { new Atom("v"), new Atom("[]"), new Atom("a") });
    Compound list2 = new Compound(".", new Term[] { t2, new Atom("[]") });
    Compound t1 = new Compound("t", new Term[] { new Atom("c"), new Atom("q"), new Atom("[]") });
    Compound list1 = new Compound(".", new Term[] { t1, list2 });
    Variable answer = new Variable("A");
    Compound goal2 = new Compound("gen", new Term[] { list1, answer });
    Query q2 = new Query(goal2);
    Map<String, Term> solution = q2.oneSolution();
    if (solution == null) {
        System.out.println("failed");
    } else {
        System.out.println(solution.get("A").toString());
    }
    System.out.println("finished");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 9 with Query

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

the class Query method close.

/**
 * This method can be used to close an open query before its solutions are
 * exhausted. It is called automatically when solutions are exhausted.
 * Calling close() on an already closed Query has no effect.
 * <p>
 *
 * Here is one way to get the first three solutions to a Query:
 *
 * <pre>
 * Query q = new Query(predicate, args);
 * Map&lt;String, Term&gt; sub1 = q.nextSolution();
 * Map&lt;String, Term&gt; sub2 = q.nextSolution();
 * Map&lt;String, Term&gt; sub3 = q.nextSolution();
 * q.close();
 * </pre>
 * <p>
 */
public final void close() {
    if (!open) {
        // it is not an error to attempt to close a closed Query
        return;
    }
    if (Prolog.thread_self() == -1) {
        throw new JPLException("no engine is attached to this thread");
    }
    if (Prolog.current_engine().value != engine.value) {
        throw new JPLException("this Query's engine is not that which is attached to this thread");
    }
    qid_t topmost = Prolog.current_query();
    if (topmost.value != this.qid.value) {
        throw new JPLException("this Query (" + this.hashCode() + ":" + this.toString() + ") is not topmost (" + topmost.hashCode() + ":" + topmost.toString() + ") within its engine[" + engine.value + "]");
    }
    Prolog.close_query(qid);
    // for tidiness
    qid = null;
    org.jpl7.fli.Prolog.discard_foreign_frame(fid);
    // for tidiness
    fid = null;
    if (Prolog.current_query() == null) {
        // only Query open in this engine?
        if (Prolog.current_engine_is_pool()) {
            // this (Query's) engine is
            // from the pool?
            Prolog.release_pool_engine();
        // System.out.println("JPL releasing engine[" + engine.value +
        // "]");
        } else {
        // System.out.println("JPL leaving engine[" + engine.value +
        // "]");
        }
    } else {
    // System.out.println("JPL retaining engine[" + engine.value + "]
    }
    // this Query is now closed
    open = false;
    // this Query, being closed, is no longer associated with
    engine = null;
// any Prolog engine
}
Also used : org.jpl7.fli.qid_t(org.jpl7.fli.qid_t)

Example 10 with Query

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

the class Family method main.

public static void main(String[] argv) {
    Query q1 = new Query("consult", new Term[] { new Atom("jpl/test/family.pl") });
    System.err.println("consult " + (q1.hasSolution() ? "succeeded" : "failed"));
    for (int i = 0; i < 20; i++) {
        System.out.println("spawning client[" + i + "]");
        new Family(i).start();
    }
}
Also used : Query(org.jpl7.Query) 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