Search in sources :

Example 86 with Term

use of org.geotoolkit.sml.xml.v100.Term 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.subsToString(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.subsToString(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.subsToString(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");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Map(java.util.Map)

Example 87 with Term

use of org.geotoolkit.sml.xml.v100.Term in project packages-jpl by SWI-Prolog.

the class PrologMT method run.

/**
 * Run a Java thread with a Prolog engine attached during the life time
 *  of the thread.  The thread must call Prolog.destroy_engine() before
 *  terminating.  Eventually we would like to make that optional, but I
 *  have not yet found a way to get notified in time. We can get a
 *  notification using the destruction function of a pthread local key,
 *  but that is called after the thread died and we can no longer do
 *  Prolog's thread cleanup magic.  Currently we use this to print
 *  a message telling you forgot to call Prolog.destroy_engine()
 */
public void run() {
    Map<String, Term> solution;
    Prolog.create_engine();
    // new Query("welcome").hasSolution();
    // new Query("time(rtest_chats("+chats+"))").hasSolution();
    new Query("rtest_chats(" + chats + ")").hasSolution();
    Prolog.destroy_engine();
// System.out.println("Done");
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 88 with Term

use of org.geotoolkit.sml.xml.v100.Term in project packages-jpl by SWI-Prolog.

the class PrologMT method pid.

public static int pid() {
    Map<String, Term> solution;
    Query q = new Query("current_prolog_flag(pid, PID)");
    solution = q.oneSolution();
    return solution.get("PID").intValue();
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 89 with Term

use of org.geotoolkit.sml.xml.v100.Term in project packages-jpl by SWI-Prolog.

the class Test_Report method ReportPrologFlags.

@Test
public void ReportPrologFlags() {
    StringBuffer sb = new StringBuffer();
    Query q = new Query("current_prolog_flag(X, Y)");
    q.open();
    while (q.hasMoreSolutions()) {
        Map<String, Term> sol = q.nextSolution();
        System.out.println(String.format("\t Value of %s: %s", sol.get("X").toString(), sol.get(("Y").toString())));
    }
    q.close();
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Test(org.junit.Test)

Example 90 with Term

use of org.geotoolkit.sml.xml.v100.Term in project packages-jpl by SWI-Prolog.

the class Test_String method testStringXput1.

// /////////////////////////////////////////////////////////////////////////////
// SUPPORTING CODE
// /////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////
// TESTS
// /////////////////////////////////////////////////////////////////////////////
@Test
public void testStringXput1() {
    Term a = Query.oneSolution("string_concat(foo,bar,S)").get("S");
    assertEquals("foobar", a.name());
    assertEquals("string", a.atomType());
}
Also used : Term(org.jpl7.Term) Test(org.junit.Test)

Aggregations

Term (org.jpl7.Term)86 Query (org.jpl7.Query)52 Variable (org.jpl7.Variable)29 Atom (org.jpl7.Atom)23 Compound (org.jpl7.Compound)23 Map (java.util.Map)19 BigInteger (java.math.BigInteger)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Integer (org.jpl7.Integer)4 Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 JAXBElement (javax.xml.bind.JAXBElement)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 CodeType (org.geotoolkit.gml.xml.v311.CodeType)2 TimePositionType (org.geotoolkit.gml.xml.v311.TimePositionType)2 Capabilities (org.geotoolkit.sml.xml.v100.Capabilities)2 Classification (org.geotoolkit.sml.xml.v100.Classification)2 Classifier (org.geotoolkit.sml.xml.v100.Classifier)2