Search in sources :

Example 11 with Query

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

the class TestJUnit method testHasMoreSolutions1.

public void testHasMoreSolutions1() {
    StringBuffer sb = new StringBuffer();
    Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
    Map<String, Term> soln;
    q.open();
    while (q.hasMoreSolutions()) {
        soln = q.nextSolution();
        sb.append(((Atom) soln.get("C")).name());
    }
    q.close();
    assertEquals("Query#hasMoreSolutions() + Query#nextSolution() work as intended", "prolog", sb.toString());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 12 with Query

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

the class TestJUnit method testJRef1.

public void testJRef1() {
    int i = 76543;
    Integer I = new Integer(i);
    Query q = new Query("jpl_call(?,intValue,[],I2)", new Term[] { Term.objectToJRef(I) });
    Term I2 = q.oneSolution().get("I2");
    assertTrue(I2.isInteger() && I2.intValue() == i);
}
Also used : Integer(org.jpl7.Integer) BigInteger(java.math.BigInteger) Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 13 with Query

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

the class TestJUnit method suite.

public static junit.framework.Test suite() {
    if (syntax.equals("traditional")) {
        JPL.setTraditional();
        Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "--traditional", "-q", "--home=../..", "--nosignals" });
    } else {
        Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "-q", "--home=../..", "--nosignals" });
    }
    assertTrue((new Query("consult", new Term[] { new Atom(test_jpl) })).hasSolution());
    assertTrue((new Query("use_module(library(jpl))")).hasSolution());
    return new TestSuite(TestJUnit.class);
}
Also used : Query(org.jpl7.Query) TestSuite(junit.framework.TestSuite) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 14 with Query

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

the class TestJUnit method testStackedQueries1.

public void testStackedQueries1() {
    StringBuffer sb = new StringBuffer();
    Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
    Map<String, Term> soln;
    q.open();
    while ((soln = q.getSolution()) != null) {
        Atom a = (Atom) soln.get("C");
        if (Query.hasSolution("memberchk(?, [l,o,r])", new Term[] { a })) {
            // this
            // query
            // opens
            // and
            // closes
            // while
            // an
            // earlier
            // query
            // is
            // still
            // open
            sb.append(((Atom) soln.get("C")).name());
        }
    }
    // q will have been closed by the final
    assertTrue(!q.isOpen());
    // getSolution()
    assertEquals("rolo", sb.toString());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 15 with Query

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

the class TestJUnit method testIsJNull1.

public void testIsJNull1() {
    Term atNull = new Compound("@", new Term[] { new Atom("null") });
    Query q = new Query("=", new Term[] { new Variable("X"), atNull });
    assertTrue(q.oneSolution().get("X").isJNull());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) 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