Search in sources :

Example 31 with Query

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

the class Test method test_5.

static void test_5() {
    System.out.print("test 5...");
    Variable X = new Variable("X");
    Variable Y = new Variable("Y");
    Query q5 = new Query("p", new Term[] { X, Y });
    Term[] x_target = new Term[] { a, a };
    Term[] y_target = new Term[] { a, b };
    Map<String, Term>[] solutions = q5.allSolutions();
    if (solutions.length != 2) {
        System.out.println("p(X, Y) failed:");
        System.out.println("\tExpected: 2 solutions");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    for (int i = 0; i < solutions.length; ++i) {
        Term x_binding = solutions[i].get("X");
        if (!x_binding.equals(x_target[i])) {
            System.out.println("p(X, Y) failed:");
            System.out.println("\tExpected: " + x_target[i]);
            System.out.println("\tGot:      " + x_binding);
        // System.exit(1);
        }
        Term y_binding = solutions[i].get("Y");
        if (!y_binding.equals(y_target[i])) {
            System.out.println("p( X, Y ) failed:");
            System.out.println("\tExpected: " + y_target[i]);
            System.out.println("\tGot:      " + y_binding);
        // System.exit(1);
        }
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 32 with Query

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

the class Test method test_4.

static void test_4() {
    System.out.print("test 4...");
    Variable X = new Variable("X");
    Query q4 = new Query("p", new Term[] { X });
    Term[] target = new Term[] { a, f_a, pair_a_b, new Variable("_") };
    Map<String, Term>[] solutions = q4.allSolutions();
    if (solutions.length != 4) {
        System.out.println("p(X) failed:");
        System.out.println("\tExpected: 4 solutions");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    for (int i = 0; i < solutions.length - 1; ++i) {
        Term binding = (Term) solutions[i].get("X");
        if (!binding.equals(target[i])) {
            System.out.println("p(X) failed");
            System.out.println("\tExpected: " + target[i]);
            System.out.println("\tGot:      " + binding);
        // System.exit(1);
        }
    }
    System.out.println("passed");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map)

Example 33 with Query

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

the class Time method test_2.

static void test_2() {
    Query query = new Query("noop", new Term[] { tree });
    System.out.print("noop");
    for (int i = 0; i < num_trials; ++i) {
        timer.start();
        query.oneSolution();
        timer.stop();
        data[2][i] = timer.getElapsedTimeInMillis();
        System.out.print(".");
    }
    System.out.println("done");
}
Also used : Query(org.jpl7.Query)

Example 34 with Query

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

the class Time method test_4.

static void test_4() {
    Variable Y = new Variable("Y");
    Query query = new Query("noop_bind", new Term[] { tree, Y });
    System.out.print("noop_bind");
    for (int i = 0; i < num_trials; ++i) {
        timer.start();
        query.oneSolution();
        timer.stop();
        data[4][i] = timer.getElapsedTimeInMillis();
        System.out.print(".");
    }
    System.out.println("done");
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query)

Example 35 with Query

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

the class Zahed method main.

public static void main(java.lang.String[] argv) {
    System.out.println("starting...");
    Compound goal1 = new Compound("consult", new Term[] { new Atom("zahed.pl") });
    Query q1 = new Query(goal1);
    if (!q1.hasSolution()) {
        System.out.println("consult('zahed.pl') failed");
        return;
    }
    Term t2 = new Compound("t", new Term[] { new Atom("v"), new Atom("[]"), new Atom("a") });
    Compound list2 = new Compound(".", new Term[] { t2, new Atom("[]") });
    Compound t1 = new Compound("t", new Term[] { new Atom("c"), new Atom("q"), new Atom("[]") });
    Compound list1 = new Compound(".", new Term[] { t1, list2 });
    Variable answer = new Variable("A");
    Compound goal2 = new Compound("gen", new Term[] { list1, answer });
    Query q2 = new Query(goal2);
    Map<String, Term> solution = q2.oneSolution();
    if (solution == null) {
        System.out.println("failed");
    } else {
        System.out.println(solution.get("A").toString());
    }
    System.out.println("finished");
}
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