Search in sources :

Example 96 with Query

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

the class Masstest method predQuery.

public void predQuery() {
    String st = "diagnose_declaration(1,[(sp, 'prefix', [('arg1', '+', 'list', 'Liste1'), ('arg2', '+', 'list', 'Liste2')])], DecMap, ErrorList)";
    Query stQuery = new Query(st);
    String errString = stQuery.oneSolution().get("ErrorList").toString();
    System.out.println("errString=" + errString);
}
Also used : Query(org.jpl7.Query)

Example 97 with Query

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

the class SyntaxError method main.

public static void main(String[] argv) {
    Query q = new Query("syntax)error");
    System.err.println(q.hasSolution() ? "yes" : "no");
}
Also used : Query(org.jpl7.Query)

Example 98 with Query

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

the class TestJUnit method testHasMoreElements1.

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

Example 99 with Query

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

the class TestJUnit method testGetSolution2.

public void testGetSolution2() {
    // this query has no solutions
    Query q = new Query("fail");
    // this opens the query
    q.open();
    // this finds no solution, and closes the query
    q.getSolution();
    try {
        // this call is invalid, as the query is closed
        q.getSolution();
        // shouldn't get to here
        fail("jpl.Query#getSolution() shoulda thrown JPLException");
    } catch (JPLException e) {
        // in detail?
        if (e.getMessage().endsWith("Query is not open")) {
        // ...which
        // should throw
        // a
        // JPLException
        // like this
        // OK: an appropriate exception was thrown
        } else {
            fail("jpl.Query#getSolution() threw incorrect JPLException: " + e);
        }
    } catch (Exception e) {
        fail("jpl.Query#getSolution() threw wrong class of exception: " + e);
    }
}
Also used : Query(org.jpl7.Query) JPLException(org.jpl7.JPLException) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Example 100 with Query

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

the class TestJUnit method testVariableBinding1.

public void testVariableBinding1() {
    Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("Y") });
    Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
    Term goal = new Compound("=", new Term[] { lhs, rhs });
    Map<String, Term> soln = new Query(goal).oneSolution();
    assertTrue("two Variables with different names can bind to distinct atoms", soln != null && (soln.get("X")).name().equals("a") && (soln.get("Y")).name().equals("b"));
}
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)88 Term (org.jpl7.Term)52 Variable (org.jpl7.Variable)32 Query (org.hypertrace.entity.data.service.v1.Query)31 Map (java.util.Map)28 Test (org.junit.jupiter.api.Test)23 Atom (org.jpl7.Atom)21 Compound (org.jpl7.Compound)18 Test (org.junit.Test)18 Filter (org.hypertrace.core.documentstore.Filter)16 Query (com.google.datastore.v1.Query)14 AttributeFilter (org.hypertrace.entity.data.service.v1.AttributeFilter)14 GqlQuery (com.google.datastore.v1.GqlQuery)7 ArrayList (java.util.ArrayList)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Entity (org.hypertrace.entity.data.service.v1.Entity)6 Integer (org.jpl7.Integer)6 Query (org.molgenis.emx2.Query)6 IOException (java.io.IOException)5 Collections (java.util.Collections)5