Search in sources :

Example 16 with Term

use of org.geotoolkit.sml.xml.v101.Term in project packages-jpl by SWI-Prolog.

the class TestJUnit method suite.

public static junit.framework.Test suite() {
    if (syntax.equals("traditional")) {
        JPL.setTraditional();
        Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "--traditional", "-q", "--home=../..", "--nosignals" });
    } else {
        Prolog.set_default_init_args(new String[] { "swipl.dll", "-x", startup, "-f", "none", "-g", "true", "-q", "--home=../..", "--nosignals" });
    }
    assertTrue((new Query("consult", new Term[] { new Atom(test_jpl) })).hasSolution());
    assertTrue((new Query("use_module(library(jpl))")).hasSolution());
    return new TestSuite(TestJUnit.class);
}
Also used : Query(org.jpl7.Query) TestSuite(junit.framework.TestSuite) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 17 with Term

use of org.geotoolkit.sml.xml.v101.Term in project packages-jpl by SWI-Prolog.

the class TestJUnit method testStackedQueries1.

public void testStackedQueries1() {
    StringBuffer sb = new StringBuffer();
    Query q = new Query("atom_chars(prolog, Cs), member(C, Cs)");
    Map<String, Term> soln;
    q.open();
    while ((soln = q.getSolution()) != null) {
        Atom a = (Atom) soln.get("C");
        if (Query.hasSolution("memberchk(?, [l,o,r])", new Term[] { a })) {
            // this
            // query
            // opens
            // and
            // closes
            // while
            // an
            // earlier
            // query
            // is
            // still
            // open
            sb.append(((Atom) soln.get("C")).name());
        }
    }
    // q will have been closed by the final
    assertTrue(!q.isOpen());
    // getSolution()
    assertEquals("rolo", sb.toString());
}
Also used : Query(org.jpl7.Query) Term(org.jpl7.Term) Atom(org.jpl7.Atom)

Example 18 with Term

use of org.geotoolkit.sml.xml.v101.Term 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 19 with Term

use of org.geotoolkit.sml.xml.v101.Term in project packages-jpl by SWI-Prolog.

the class TestJUnit method testInteger1.

public void testInteger1() {
    try {
        // long but not
        Term i = Query.oneSolution("I is 2**40").get("I");
        // int
        i.intValue();
        fail("intValue() of bigger-than-int value failed to throw an exception");
    } catch (JPLException e) {
        if (e.getMessage().endsWith("cannot represent value as an int")) {
        // OK: an appropriate exception was thrown
        } else {
            fail("intValue() of bigger-than-int value threw incorrect JPLException: " + e);
        }
    } catch (Exception e) {
        fail("intValue() of bigger-than-int value threw unexpected class of exception: " + e);
    }
}
Also used : JPLException(org.jpl7.JPLException) Term(org.jpl7.Term) PrologException(org.jpl7.PrologException) JPLException(org.jpl7.JPLException)

Example 20 with Term

use of org.geotoolkit.sml.xml.v101.Term 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

Term (org.jpl7.Term)86 Query (org.jpl7.Query)52 Variable (org.jpl7.Variable)29 Atom (org.jpl7.Atom)23 Compound (org.jpl7.Compound)23 Map (java.util.Map)19 BigInteger (java.math.BigInteger)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Integer (org.jpl7.Integer)4 Term (org.apache.cassandra.cql3.Term)3 MarshalException (org.apache.cassandra.serializers.MarshalException)3 JAXBElement (javax.xml.bind.JAXBElement)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 CodeType (org.geotoolkit.gml.xml.v311.CodeType)2 TimePositionType (org.geotoolkit.gml.xml.v311.TimePositionType)2 Capabilities (org.geotoolkit.sml.xml.v100.Capabilities)2 Classification (org.geotoolkit.sml.xml.v100.Classification)2 Classifier (org.geotoolkit.sml.xml.v100.Classifier)2