use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class FamilyMT method main.
public static void main(String[] argv) {
Query q1 = new Query("consult(family)");
System.err.println("consult " + (q1.hasSolution() ? "succeeded" : "failed"));
for (int i = 0; i < 20; i++) {
System.out.println("spawning client[" + i + "]");
new FamilyMT(i).start();
}
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class Test method test_2.
static void test_2() {
System.out.print("test 2...");
Query q2 = new Query("p", new Term[] { f_a });
if (!q2.hasSolution()) {
System.out.println("p(f(a)) failed");
// System.exit(1);
}
System.out.println("passed");
}
use of org.jpl7.Query in project packages-jpl by SWI-Prolog.
the class Test method test_11.
static void test_11() {
System.out.print("test 11...");
Term tuple = new Compound("t", new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
try {
Variable X = new Variable("X");
Query q11 = new Query("tuple", new Term[] { X });
Term result = q11.oneSolution().get("X");
if (result == null || !result.equals(tuple)) {
System.out.println("failed:");
System.out.println("\tresult: " + result);
System.out.println("\ttuple: " + tuple);
// System.exit(1);
}
if (result.arg(1) == null || !result.arg(1).equals(new Atom("a"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(1): " + result.arg(1));
// System.exit(1);
}
if (result.arg(2) == null || !result.arg(2).equals(new Atom("b"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(2): " + result.arg(2));
// System.exit(1);
}
if (result.arg(5) == null || !result.arg(5).equals(new Atom("e"))) {
System.out.println("failed:");
System.out.println("\tresult.arg(5): " + result.arg(5));
// System.exit(1);
}
// arg0(6) throws an exception, as I'd expect it to...
// if ( ((Compound)result).arg( 7 ) != null ){
// System.out.println( "failed:" );
// System.out.println( "\t((Compound)result).arg( 7 ): " + ((Compound)result).arg( 7 ) );
// System.out.println( "\tshould be null" );
// System.exit( 1 );
// }
} catch (PrologException e) {
System.out.println("failed");
e.printStackTrace();
// System.exit(1);
}
System.out.println("passed");
}
use of org.jpl7.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");
}
use of org.jpl7.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");
}
Aggregations