Search in sources :

Example 6 with Variable

use of org.jpl7.Variable 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 7 with Variable

use of org.jpl7.Variable 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)

Example 8 with Variable

use of org.jpl7.Variable in project packages-jpl by SWI-Prolog.

the class Term method putTerms.

/**
 * This static method converts an array of Terms to a *consecutive* sequence of term_t objects. Note that the first
 * term_t object returned is a term_t class (structure); the succeeding term_t objects are consecutive references
 * obtained by incrementing the *value* field of the term_t.
 *
 * @param varnames_to_vars
 *            Map from variable names to JPL Variables.
 * @param args
 *            An array of org.jpl7.Term references.
 * @return consecutive term_t references (first of which is a structure)
 */
protected static term_t putTerms(Map<String, term_t> varnames_to_vars, Term[] args) {
    // First create a sequence of term_ts.
    // The 0th term_t will be a org.jpl7.fli.term_t.
    // Successive Prolog term_t references will reside in the Prolog engine, and can be obtained by term0.value+i.
    term_t term0 = Prolog.new_term_refs(args.length);
    // For each new term ref, construct a Prolog term by putting an appropriate Prolog type into the ref.
    long ith_term_t = term0.value;
    for (int i = 0; i < args.length; ++i, ++ith_term_t) {
        term_t term = new term_t();
        term.value = ith_term_t;
        // each subclass defines its own put()
        args[i].put(varnames_to_vars, term);
    }
    return term0;
}
Also used : org.jpl7.fli.term_t(org.jpl7.fli.term_t)

Example 9 with Variable

use of org.jpl7.Variable in project packages-jpl by SWI-Prolog.

the class TestJUnit method testIsJNull1.

public void testIsJNull1() {
    Term atNull = new Compound("@", new Term[] { new Atom("null") });
    Query q = new Query("=", new Term[] { new Variable("X"), atNull });
    assertTrue(q.oneSolution().get("X").isJNull());
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Compound(org.jpl7.Compound) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 10 with Variable

use of org.jpl7.Variable in project packages-jpl by SWI-Prolog.

the class Versions method main.

public static void main(String[] argv) {
    System.out.println("command line args: (" + argv.length + ")");
    for (int i = 0; i < argv.length; i++) {
        System.out.println("  argv[" + i + "]: " + argv[i]);
    }
    System.out.println();
    System.out.println("old (built in) default init args:");
    String[] defaultInitArgsOld = org.jpl7.JPL.getDefaultInitArgs();
    for (int i = 0; i < defaultInitArgsOld.length; i++) {
        System.out.println("  arg[" + i + "]: " + defaultInitArgsOld[i]);
    }
    System.out.println();
    String[] defaultInitArgsNew1;
    if (argv.length == 1 && argv[0].equals("traditional")) {
        defaultInitArgsNew1 = new String[] { "swipl", "-g", "true", "--nosignals", "--traditional" };
    } else {
        defaultInitArgsNew1 = new String[] { "swipl", "-g", "true", "--nosignals" };
    }
    org.jpl7.JPL.setDefaultInitArgs(defaultInitArgsNew1);
    System.out.println("new (stashed) default init args:");
    String[] defaultInitArgsNew2 = org.jpl7.JPL.getDefaultInitArgs();
    for (int i = 0; i < defaultInitArgsNew2.length; i++) {
        System.out.println("  arg[" + i + "]: " + defaultInitArgsNew2[i]);
    }
    System.out.println();
    if (!(new Query("consult", new Atom("jpl/test/Versions.pl"))).hasSolution()) {
        System.out.println("Warning: failed to consult Versions.pl");
        System.out.println();
    }
    // String swiplHome = ((Term) (new
    // Query("current_prolog_flag(home,Home)")).oneSolution().get("Home")).name();
    // System.out.println(" SWI-Prolog home dir: " + swiplHome );
    System.out.println("home1 = " + (new Atom("c:/swipl-7.1.26")).toString());
    Query q1 = new Query("current_prolog_flag", new Term[] { new Atom("home"), new Variable("Home") });
    Map<String, Term> h1 = q1.oneSolution();
    Term home = (Term) h1.get("Home");
    // System.out.println("Home = " + home.debugString());
    System.out.println("Home = " + home.toString());
    try {
        URL jarPathJpl = Class.forName("org.jpl7.JPL").getProtectionDomain().getCodeSource().getLocation();
        System.out.println("package jpl loaded from: " + jarPathJpl);
    } catch (ClassNotFoundException e) {
        System.out.println("org.jpl7.JPL not found");
    }
    String prologVersion = ((Term) (new Query("jpl_pl_lib_version(V)")).oneSolution().get("V")).name();
    System.out.println(" prolog library version: " + prologVersion);
    String javaVersion = org.jpl7.JPL.version_string();
    System.out.println("   java library version: " + javaVersion);
    String cVersion = org.jpl7.fli.Prolog.get_c_lib_version();
    System.out.println("      c library version: " + cVersion);
    System.out.println("      SWI Prolog syntax: " + org.jpl7.fli.Prolog.get_syntax());
    // if ( prologVersion.equals(javaVersion) &&
    // javaVersion.equals(cVersion) ) {
    // System.out.println("BINGO! you appear to have the same version of
    // each library installed");
    // } else {
    // System.out.println("WHOOPS! you appear not to have the same version
    // of each library installed");
    // }
    System.out.println();
}
Also used : Variable(org.jpl7.Variable) Query(org.jpl7.Query) Term(org.jpl7.Term) Atom(org.jpl7.Atom) URL(java.net.URL)

Aggregations

Query (org.jpl7.Query)25 Variable (org.jpl7.Variable)24 Term (org.jpl7.Term)23 Variable (ucar.nc2.Variable)23 IOException (java.io.IOException)20 Compound (org.jpl7.Compound)17 Atom (org.jpl7.Atom)12 ArrayDouble (ucar.ma2.ArrayDouble)11 Map (java.util.Map)9 Attribute (ucar.nc2.Attribute)6 Integer (org.jpl7.Integer)4 org.jpl7.fli.term_t (org.jpl7.fli.term_t)4 BigInteger (java.math.BigInteger)3 Dimension (ucar.nc2.Dimension)3 Group (ucar.nc2.Group)3 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 TikaException (org.apache.tika.exception.TikaException)2 TemporaryResources (org.apache.tika.io.TemporaryResources)2 TikaInputStream (org.apache.tika.io.TikaInputStream)2 Property (org.apache.tika.metadata.Property)2