Search in sources :

Example 46 with Query

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

the class Family method main.

public static void main(String[] argv) {
    // JPL.setTraditional();
    // 
    // only because we call e.g. jpl_pl_syntax/1 below
    Query.hasSolution("use_module(library(jpl))");
    Term swi = Query.oneSolution("current_prolog_flag(version_data,Swi)").get("Swi");
    System.out.println("swipl.version = " + swi.arg(1) + "." + swi.arg(2) + "." + swi.arg(3));
    System.out.println("swipl.syntax = " + Query.oneSolution("jpl_pl_syntax(Syntax)").get("Syntax"));
    System.out.println("swipl.home = " + Query.oneSolution("current_prolog_flag(home,Home)").get("Home").name());
    System.out.println("jpl.jar = " + JPL.version_string());
    System.out.println("jpl.dll = " + org.jpl7.fli.Prolog.get_c_lib_version());
    System.out.println("jpl.pl = " + Query.oneSolution("jpl_pl_lib_version(V)").get("V").name());
    // 
    String t1 = "consult('family.pl')";
    System.out.println(t1 + " " + (Query.hasSolution(t1) ? "succeeded" : "failed"));
    // 
    String t2 = "child_of(joe, ralf)";
    System.out.println(t2 + " is " + (Query.hasSolution(t2) ? "provable" : "not provable"));
    // 
    String t3 = "descendent_of(steve, ralf)";
    System.out.println(t3 + " is " + (Query.hasSolution(t3) ? "provable" : "not provable"));
    // 
    String t4 = "descendent_of(X, ralf)";
    System.out.println("first solution of " + t4 + ": X = " + Query.oneSolution(t4).get("X"));
    Map<String, Term>[] ss4 = Query.allSolutions(t4);
    System.out.println("all solutions of " + t4);
    for (int i = 0; i < ss4.length; i++) {
        System.out.println("X = " + ss4[i].get("X"));
    }
    System.out.println("each solution of " + t4);
    Query q4 = new Query(t4);
    while (q4.hasMoreSolutions()) {
        Map<String, Term> s4 = q4.nextSolution();
        System.out.println("X = " + s4.get("X"));
    }
    // 
    String t5 = "descendent_of(X,Y)";
    Query q5 = new Query(t5);
    System.out.println("each solution of " + t5);
    while (q5.hasMoreSolutions()) {
        Map<String, Term> s5 = q5.nextSolution();
        System.out.println("X = " + s5.get("X") + ", Y = " + s5.get("Y"));
    }
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 47 with Query

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

the class SemWeb method main.

public static void main(String[] argv) {
    String t1 = "use_module(library('semweb/rdf_db'))";
    System.out.println(t1 + " " + (Query.hasSolution(t1) ? "succeeded" : "failed"));
    // 
    String t2 = "rdf_load('test.rdf')";
    System.out.println(Query.hasSolution(t2) ? "loaded" : "load failed");
    // 
    String t3 = "rdf(S,P,O)";
    Query q3 = new Query(t3);
    while (q3.hasMoreSolutions()) {
        Map<String, Term> s3 = q3.nextSolution();
        System.out.println("{" + s3.get("S") + ", " + s3.get("P") + ", " + s3.get("O") + "}");
    }
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term)

Example 48 with Query

use of org.skife.jdbi.v2.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();
    }
}
Also used : Query(org.jpl7.Query)

Example 49 with Query

use of org.skife.jdbi.v2.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");
}
Also used : Query(org.jpl7.Query)

Example 50 with Query

use of org.skife.jdbi.v2.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");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) PrologException(org.jpl7.PrologException) 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 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