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");
}
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");
}
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");
}
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<String, Term> sub1 = q.nextSolution();
* Map<String, Term> sub2 = q.nextSolution();
* Map<String, Term> 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
}
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();
}
}
Aggregations