Search in sources :

Example 31 with Variable

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

the class Variable method put.

/**
 * To put a Variable, we must check whether a (non-anonymous) variable with
 * the same name has already been put in the Term. If one has, then the
 * corresponding Prolog variable has been stashed in the varnames_to_vars
 * Map, keyed by the Variable name, so we can look it up and reuse it (this
 * way, the sharing of variables in the Prolog term reflects the sharing of
 * Variable names in the Term. Otherwise, if this Variable name has not
 * already been seen in the Term, then we put a new Prolog variable and add
 * it into the Map (keyed by this Variable name).
 *
 * @param varnames_to_vars
 *            A Map from variable names to Prolog variables.
 * @param term
 *            A (previously created) term_t which is to be set to a (new or
 *            reused) Prolog variable.
 */
protected final void put(Map<String, term_t> varnames_to_vars, term_t term) {
    term_t var;
    // if this var is anonymous or as yet unseen, put a new Prolog variable
    if (this.name.equals("_") || (var = (term_t) varnames_to_vars.get(this.name)) == null) {
        this.term_ = term;
        // i.e. first var in is #0
        this.index = varnames_to_vars.size();
        // etc.
        Prolog.put_variable(term);
        if (!this.name.equals("_")) {
            varnames_to_vars.put(this.name, term);
        }
    } else {
        this.term_ = var;
        Prolog.put_term(term, var);
    }
}
Also used : org.jpl7.fli.term_t(org.jpl7.fli.term_t)

Example 32 with Variable

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

Example 33 with Variable

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

the class Query method get1.

private final boolean get1() {
    // close the query;
    if (Prolog.next_solution(qid)) {
        return true;
    } else {
        // if failure was due to throw/1, build exception term and
        // throw it
        term_t exception_term_t = Prolog.exception(qid);
        if (exception_term_t.value != 0L) {
            Term exception_term = Term.getTerm(new HashMap<term_t, Variable>(), exception_term_t);
            close();
            throw new PrologException(exception_term);
        } else {
            close();
            return false;
        }
    }
}
Also used : org.jpl7.fli.term_t(org.jpl7.fli.term_t)

Example 34 with Variable

use of org.jpl7.Variable in project bioformats by openmicroscopy.

the class NetCDFServiceImpl method parseAttributesAndVariables.

// -- Helper methods --
/**
 * Recursively parses attribute and variable paths, filling
 * <code>attributeList</code> and <code>variableList</code>.
 * @param groups List of groups to recursively parse.
 */
private void parseAttributesAndVariables(List<Group> groups) {
    for (Group group : groups) {
        String groupName = group.getName();
        List<Attribute> attributes = group.getAttributes();
        for (Attribute attribute : attributes) {
            String attributeName = attribute.getName();
            if (!groupName.endsWith("/"))
                attributeName = "/" + attributeName;
            attributeList.add(groupName + attributeName);
        }
        List<Variable> variables = group.getVariables();
        for (Variable variable : variables) {
            String variableName = variable.getName();
            if (!groupName.endsWith("/"))
                variableName = "/" + variableName;
            variableList.add(variableName);
        }
        groups = group.getGroups();
        parseAttributesAndVariables(groups);
    }
}
Also used : Group(ucar.nc2.Group) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute)

Example 35 with Variable

use of org.jpl7.Variable in project bioformats by openmicroscopy.

the class NetCDFServiceImpl method getVariableAttributes.

/* (non-Javadoc)
   * @see loci.formats.NetCDFService#getVariableAttributes(java.lang.String)
   */
@Override
public Hashtable<String, Object> getVariableAttributes(String name) {
    String groupName = getDirectory(name);
    String variableName = getName(name);
    Group group = getGroup(groupName);
    Variable variable = group.findVariable(variableName);
    Hashtable<String, Object> toReturn = new Hashtable<String, Object>();
    if (variable != null) {
        List<Attribute> attributes = variable.getAttributes();
        for (Attribute attribute : attributes) {
            toReturn.put(attribute.getName(), arrayToString(attribute.getValues()));
        }
    }
    return toReturn;
}
Also used : Group(ucar.nc2.Group) Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) Hashtable(java.util.Hashtable)

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