Search in sources :

Example 26 with Variable

use of org.flyte.api.v1.Variable 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 27 with Variable

use of org.flyte.api.v1.Variable 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)

Example 28 with Variable

use of org.flyte.api.v1.Variable in project packages-jpl by SWI-Prolog.

the class Test method test_6.

static void test_6() {
    System.out.print("test 6...");
    Variable X = new Variable("X");
    Query q6 = new Query("p", new Term[] { X, X });
    Term[] x_target = new Term[] { a };
    Map<String, Term>[] solutions = q6.allSolutions();
    if (solutions.length != 1) {
        System.out.println("p(X, X) failed:");
        System.out.println("\tExpected: 1 solution");
        System.out.println("\tGot:      " + solutions.length);
    // System.exit(1);
    }
    for (int i = 0; i < solutions.length; ++i) {
        Object x_binding = solutions[i].get("X");
        if (!x_binding.equals(x_target[i])) {
            System.out.println("p(X, X) failed:");
            System.out.println("\tExpected: " + x_target[i]);
            System.out.println("\tGot:      " + x_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 29 with Variable

use of org.flyte.api.v1.Variable 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 = 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 30 with Variable

use of org.flyte.api.v1.Variable in project packages-jpl by SWI-Prolog.

the class Family method run.

public void run() {
    Map<String, Term> solution;
    Variable X = new Variable("X");
    // --------------------------------------------------
    Query q2 = new Query("child_of", new Term[] { new Atom("joe"), new Atom("ralf") });
    System.err.println("child_of(joe,ralf) is " + (q2.hasSolution() ? "provable" : "not provable"));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Query q3 = new Query("descendent_of", new Term[] { new Atom("steve"), new Atom("ralf") });
    System.err.println("descendent_of(steve,ralf) is " + (q3.hasSolution() ? "provable" : "not provable"));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Query q4 = new Query("descendent_of", new Term[] { X, new Atom("ralf") });
    solution = q4.oneSolution();
    System.err.println("first solution of descendent_of(X, ralf)");
    System.err.println("X = " + solution.get(X.name));
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Map<String, Term>[] solutions = q4.allSolutions();
    System.err.println("all solutions of descendent_of(X, ralf)");
    for (int i = 0; i < solutions.length; i++) {
        System.err.println("X = " + solutions[i].get(X.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    System.err.println("each solution of descendent_of(X, ralf)");
    while (q4.hasMoreSolutions()) {
        solution = q4.nextSolution();
        System.err.println("X = " + solution.get(X.name));
    }
    new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    // --------------------------------------------------
    Variable Y = new Variable("Y");
    Query q5 = new Query("descendent_of", new Term[] { X, Y });
    System.err.println(id + ": each solution of descendent_of(X, Y)");
    while (q5.hasMoreSolutions()) {
        solution = q5.nextSolution();
        System.err.println(id + ": X = " + solution.get(X.name) + ", Y = " + solution.get(Y.name));
        new Query("sleep", new Term[] { new org.jpl7.Integer(delay) }).hasSolution();
    }
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Map(java.util.Map) Atom(org.jpl7.Atom)

Aggregations

Variable (ucar.nc2.Variable)78 IOException (java.io.IOException)41 Variable (org.jpl7.Variable)33 Query (org.jpl7.Query)32 Term (org.jpl7.Term)29 Array (ucar.ma2.Array)21 Attribute (ucar.nc2.Attribute)21 Compound (org.jpl7.Compound)19 NetcdfFile (ucar.nc2.NetcdfFile)18 Map (java.util.Map)17 Dimension (ucar.nc2.Dimension)17 InvalidRangeException (ucar.ma2.InvalidRangeException)16 ArrayList (java.util.ArrayList)15 Atom (org.jpl7.Atom)15 ArrayDouble (ucar.ma2.ArrayDouble)14 File (java.io.File)10 List (java.util.List)9 ArrayFloat (ucar.ma2.ArrayFloat)9 WritableRaster (java.awt.image.WritableRaster)8 HashMap (java.util.HashMap)8