use of org.jpl7.Term in project packages-jpl by SWI-Prolog.
the class Test method test_4.
static void test_4() {
System.out.print("test 4...");
Variable X = new Variable("X");
Query q4 = new Query("p", new Term[] { X });
Term[] target = new Term[] { a, f_a, pair_a_b, new Variable("_") };
Map<String, Term>[] solutions = q4.allSolutions();
if (solutions.length != 4) {
System.out.println("p(X) failed:");
System.out.println("\tExpected: 4 solutions");
System.out.println("\tGot: " + solutions.length);
// System.exit(1);
}
for (int i = 0; i < solutions.length - 1; ++i) {
Term binding = (Term) solutions[i].get("X");
if (!binding.equals(target[i])) {
System.out.println("p(X) failed");
System.out.println("\tExpected: " + target[i]);
System.out.println("\tGot: " + binding);
// System.exit(1);
}
}
System.out.println("passed");
}
use of org.jpl7.Term 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.Term 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.Term 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.Term in project packages-jpl by SWI-Prolog.
the class Term method putTerms.
/**
* This static method converts an array of Terms to a *consecutive* sequence of term_t objects. Note that the first
* term_t object returned is a term_t class (structure); the succeeding term_t objects are consecutive references
* obtained by incrementing the *value* field of the term_t.
*
* @param varnames_to_vars
* Map from variable names to JPL Variables.
* @param args
* An array of org.jpl7.Term references.
* @return consecutive term_t references (first of which is a structure)
*/
protected static term_t putTerms(Map<String, term_t> varnames_to_vars, Term[] args) {
// First create a sequence of term_ts.
// The 0th term_t will be a org.jpl7.fli.term_t.
// Successive Prolog term_t references will reside in the Prolog engine, and can be obtained by term0.value+i.
term_t term0 = Prolog.new_term_refs(args.length);
// For each new term ref, construct a Prolog term by putting an appropriate Prolog type into the ref.
long ith_term_t = term0.value;
for (int i = 0; i < args.length; ++i, ++ith_term_t) {
term_t term = new term_t();
term.value = ith_term_t;
// each subclass defines its own put()
args[i].put(varnames_to_vars, term);
}
return term0;
}
Aggregations