Search in sources :

Example 61 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testWouter1.

public void testWouter1() {
    // Wouter says this fails under OS X Mavericks
    // 10.9 x86-64
    // too big for an int
    long n = 7381783232223l;
    Compound term = new Compound("is", new Term[] { new Variable("X"), new org.jpl7.Integer(n) });
    Map<String, Term>[] solutions = new Query(term).allSolutions();
    assertEquals(1, solutions.length);
    Map<String, Term> solution = solutions[0];
    assertTrue(solution.containsKey("X"));
    Object result = solution.get("X");
    assertTrue(result instanceof org.jpl7.Integer);
    assertEquals(n, ((org.jpl7.Integer) result).longValue());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Integer(org.jpl7.Integer) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Map(java.util.Map)

Example 62 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testVariableBinding3.

public void testVariableBinding3() {
    Variable X = new Variable("X");
    Term lhs = new Compound("p", new Term[] { X, X });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    assertFalse("two references to the same (named) Variable cannot unify with differing atoms", new Query(goal).hasSolution());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 63 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testArrayToList1.

public void testArrayToList1() {
    Term l2 = Util.termArrayToList(new Term[] { new Atom("a"), new Atom("b"), new Atom("c"), new Atom("d"), new Atom("e") });
    Query q9 = new Query(new Compound("append", new Term[] { new Variable("Xs"), new Variable("Ys"), l2 }));
    assertTrue("append(Xs,Ys,[a,b,c,d,e]) has 6 solutions", q9.allSolutions().length == 6);
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 64 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testDontTellMeMode2.

public void testDontTellMeMode2() {
    final Query q = new Query("setof(_M,current_module(_M),_Ms),length(_Ms,N)");
    JPL.setDTMMode(false);
    assertTrue("not in dont-tell-me mode, setof(_M,current_module(_M),_Ms),length(_Ms,N) returns binding for three variables", q.oneSolution().keySet().size() == 3);
}
Also used : Query(org.jpl7.Query)

Example 65 with Query

use of org.skife.jdbi.v2.Query in project packages-jpl by SWI-Prolog.

the class TestJUnit method testOpenGetClose2.

public void testOpenGetClose2() {
    // we're not going to open this...
    Query q = new Query("dummy");
    try {
        // should throw exception (query not open)
        q.getSolution();
        // shouldn't get
        fail("getSolution() succeeds on unopened Query");
    // to here
    } catch (JPLException e) {
        // expected exception class
        if (e.getMessage().endsWith("Query is not open")) {
        // OK: an appropriate exception was thrown
        } else {
            fail("jpl.Query#getSolution() threw wrong JPLException: " + e);
        }
    } catch (Exception e) {
        fail("jpl.Query#getSolution() threw wrong exception class: " + e);
    }
}
Also used : Query(org.jpl7.Query) JPLException(org.jpl7.JPLException) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Aggregations

Query (org.jpl7.Query)56 Term (org.jpl7.Term)33 Variable (org.jpl7.Variable)23 Map (java.util.Map)18 Atom (org.jpl7.Atom)16 Compound (org.jpl7.Compound)16 Query (com.google.datastore.v1.Query)12 Handle (org.skife.jdbi.v2.Handle)12 Test (org.junit.Test)10 GqlQuery (com.google.datastore.v1.GqlQuery)7 Integer (org.jpl7.Integer)6 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 Datastore (com.google.datastore.v1.client.Datastore)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 List (java.util.List)4 SplitQueryFn (org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn)4 RunQueryRequest (com.google.datastore.v1.RunQueryRequest)3 Nullable (javax.annotation.Nullable)3