org.jpl7

## Class Query

- java.lang.Object
- - org.jpl7.Query

- All Implemented Interfaces:
    java.lang.Iterable<java.util.Map<java.lang.String,Term>>, java.util.Iterator<java.util.Map<java.lang.String,Term>>

      public class Query
      extends java.lang.Object
      implements java.lang.Iterable<java.util.Map<java.lang.String,Term>>, java.util.Iterator<java.util.Map<java.lang.String,Term>>

  A Query instance is created by an application in order to query the Prolog database (or to invoke a built-in predicate). It is initialised with a Compound (or Atom) denoting the goal which is to be called, and also contains assorted private state relating to solutions. In some future version, it may contain details of the module in which the goal is to be called.

  A Query is either open or closed: when closed, it has no connection to the Prolog system; when open, it is linked to an active goal within a Prolog engine.

  The Query class implements the Enumeration interface, through which one can obtain successive solutions. The Enumeration hasMoreElements() method returns true if the call or redo succeeded (otherwise false), and if the call or redo did succeed, the nextElement() method returns a Map representing variable bindings; the elements in the Map are Terms, indexed by the (String) names of the Variables with which they are associated. For example, if p(a) and p(b) are facts in the Prolog database, then the following is equivalent to printing all the solutions to the Prolog query p(X):

       Variable X = new Variable("X");
       Term arg[] = { X };
       Query q = new Query("p", arg);

       while (q.hasMoreElements()) {
              Term bound_to_x = ((Map) q.nextElement()).get("X");
              System.out.println(bound_to_x);
       }

  Make sure to close the Query (using the close() method) if you do not need any further solutions which it may have. It is safe (although redundant) to close a Query whose solutions are already exhausted, or which is already closed. To obtain just one solution from a Query, use the oneSolution() method. To obtain all solutions, use the allSolutions() method. To obtain at most N solutions, use the nSolutions() method. To determine merely whether the Query is provable, use the hasSolution() method (i.e. has at least one solution).

  Copyright (C) 2007 Paul Singleton

  Copyright (C) 1998 Fred Dushin

  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `contextModule`
    `protected Term` | `goal_` the Compound or Atom (but not Dict, Float, Integer or Variable) corresponding to the goal of this Query
    `protected java.lang.String` | `hostModule`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Query(java.lang.String text)` This constructor builds a Query from the given Prolog source text, "as is".
    `Query(java.lang.String text, Term arg)`
    `Query(java.lang.String text, Term[] args)` If text denotes an atom, this constructor is shorthand for new Query(new Compound(name,args)).
    `Query(Term t)` This constructor creates a Query whose goal is the specified Term.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.Map<java.lang.String,Term>[]` | `allSolutions()` calls the Query's goal to exhaustion and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `allSolutions(java.lang.String text)` This static method creates a Query from the given Prolog source text fragment, calls it to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `allSolutions(java.lang.String text, Term[] params)` If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying Term params, this static method replaces each questionmark symbol by its respective param, calls the resulting goal to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `allSolutions(Term goal)` This static method creates a Query whose goal is the given Term, calls it to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found).
    `void` | `close()` This method can be used to close an open query before its solutions are exhausted.
    `java.lang.String` | `getContext()` Returns the context module for this Query
    `long` | `getEngine()` Returns the engine attached to this query
    `java.util.Map<java.lang.String,Term>` | `getSolution()` Deprecated. use nextSolution()
    `java.util.Map<java.lang.String,Term>` | `getSolutionWithVarNames()` Deprecated.
    `java.util.Map<java.lang.String,Term>` | `getSubstWithNameVars()` Deprecated.
    `Term` | `goal()` Returns the Term (Atom or Compound) which is the goal of this Query
    `boolean` | `hasMoreElements()` This method implements part of the java.util.Enumeration interface.
    `boolean` | `hasMoreSolutions()` This method returns true if JPL was able to initiate a "call" of this Query within a Prolog engine.
    `boolean` | `hasNext()` This method is required by Iterator interface It is a wrapper for `hasMoreSolutions()`
    `boolean` | `hasSolution()` This method will attempt to call this Query's goal within an available Prolog engine.
    `static boolean` | `hasSolution(java.lang.String text)` This static method creates a Query from the given Prolog source text and calls it at most once, returning true if a solution was found, else false.
    `static boolean` | `hasSolution(java.lang.String text, Term[] params)` If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N params, each questionmark symbol is replaced by its corresponding arg to provide the new Query's goal: the resulting Query is called as described above.
    `static boolean` | `hasSolution(Term goal)` This static method creates a Query (whose goal is the specified Term) and calls it at most once, returning true if a solution was found, else false.
    `boolean` | `isOpen()` Whether the query is open.
    `java.util.Iterator<java.util.Map<java.lang.String,Term>>` | `iterator()` This method is required by Iterator interface a Query is its own Iterator
    `java.util.Map<java.lang.String,Term>` | `next()` This method is required by Iterator interface It is a wrapper for `nextSolution()`
    `java.lang.Object` | `nextElement()` This method implements part of the java.util.Enumeration interface.
    `java.util.Map<java.lang.String,Term>` | `nextSolution()` This method returns a java.util.Map, which represents a binding from the names of query variables to terms within the next solution.
    `java.util.Map<java.lang.String,Term>[]` | `nSolutions(long n)` calls the Query's goal to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `nSolutions(java.lang.String text, long n)` This static method creates a Query from the given Prolog source text fragment, calls it to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `nSolutions(java.lang.String text, Term[] params, long n)` If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying params, this static method replaces each questionmark symbol by its respective param, calls the resulting goal to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found).
    `static java.util.Map<java.lang.String,Term>[]` | `nSolutions(Term goal, long n)` This static method creates a Query whose goal is the given Term, calls it to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found).
    `java.util.Map<java.lang.String,Term>` | `oneSolution()` Returns the first solution, if any, as a (possibly empty) Map of variablename-to-term bindings, else null.
    `static java.util.Map<java.lang.String,Term>` | `oneSolution(java.lang.String text)` This static method creates a Query from the given Prolog source text fragment, and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Map, else null.
    `static java.util.Map<java.lang.String,Term>` | `oneSolution(java.lang.String text, Term[] params)` If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N params, each questionmark symbol is replaced by its respective param to provide the goal of this query: the resulting goal is then called (at most once) and the first solution, if there is one, is returned as a (possibly empty) Map, else null.
    `static java.util.Map<java.lang.String,Term>` | `oneSolution(Term goal)` This static method creates a Query (whose goal is the specified Term) and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Map, else null.
    `void` | `open()` This method returns true if JPL was able to initiate a "call" of this Query within the Prolog engine.
    `void` | `remove()` This method (required by Iterator interface) is a no-op
    `void` | `reset()` Reset the query to its start: closed and no solution found so far.
    `java.lang.String` | `toString()` Returns a crude String representation of a Query.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

    - ### Methods inherited from interface java.util.Iterator

      `forEachRemaining`

- - ### Field Detail

    - #### goal_

          protected final Term goal_

      the Compound or Atom (but not Dict, Float, Integer or Variable) corresponding to the goal of this Query

    - #### hostModule

          protected final java.lang.String hostModule

      See Also:
        Constant Field Values

    - #### contextModule

          protected final java.lang.String contextModule

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Query

          public Query(Term t)

      This constructor creates a Query whose goal is the specified Term. The Query is initially closed. NB Creating an instance of the Query class does not result in a call to a Prolog engine. NB The goal can be a Compound or an Atom (Atom extends Compound), but cannot be an instance of jpl.Float, jpl.Integer or jpl.Variable.
      Parameters:
        `t` - the goal of this Query; must be Atom or Compound
      Throws:
        `JPLException` - if term provided is not of right sort Atom or Compound

    - #### Query

          public Query(java.lang.String text)

      This constructor builds a Query from the given Prolog source text, "as is". Throws PrologException containing error(syntax_error(_),_) if text is invalid.
      Parameters:
        `text` - the complete Prolog source text of this Query
      Throws:
        `PrologException` - containing error(syntax_error(_),_) if text is invalid as a term.
        `JPLException` - if term provided is not of right sort Atom or Compound

    - #### Query

          public Query(java.lang.String text,
                       Term[] args)

      If text denotes an atom, this constructor is shorthand for new Query(new Compound(name,args)). If text denotes a term containing N placehholder symbols ? and there are N args, each ? is replaced by its corresponding arg to provide the new Query's goal.
      Parameters:
        `text` - the name of the principal functor of this Query's goal
        `args` - the arguments of this Query's goal

    - #### Query

          public Query(java.lang.String text,
                       Term arg)

  - ### Method Detail

    - #### goal

          public final Term goal()

      Returns the Term (Atom or Compound) which is the goal of this Query
      Returns:
        a Term representing the goal of this Query

    - #### getContext

          public final java.lang.String getContext()

      Returns the context module for this Query
      Returns:
        a String representing the context in which the goal will be run

    - #### iterator

          public java.util.Iterator<java.util.Map<java.lang.String,Term>> iterator()

      This method is required by Iterator interface a Query is its own Iterator
      Specified by:
        `iterator` in interface `java.lang.Iterable<java.util.Map<java.lang.String,Term>>`
      See Also:
        `Iterable.iterator()`

    - #### hasNext

          public boolean hasNext()

      This method is required by Iterator interface It is a wrapper for `hasMoreSolutions()`
      Specified by:
        `hasNext` in interface `java.util.Iterator<java.util.Map<java.lang.String,Term>>`
      See Also:
        `Iterator.hasNext()`

    - #### next

          public java.util.Map<java.lang.String,Term> next()

      This method is required by Iterator interface It is a wrapper for `nextSolution()`
      Specified by:
        `next` in interface `java.util.Iterator<java.util.Map<java.lang.String,Term>>`
      See Also:
        `Iterator.next()`

    - #### remove

          public void remove()

      This method (required by Iterator interface) is a no-op
      Specified by:
        `remove` in interface `java.util.Iterator<java.util.Map<java.lang.String,Term>>`
      See Also:
        `Iterator.remove()`

    - #### hasMoreElements

          public final boolean hasMoreElements()

      This method implements part of the java.util.Enumeration interface. It is a wrapper for `hasMoreSolutions()`.
      Returns:
        true if the Prolog query yields a (or another) solution, else false.

    - #### nextElement

          public final java.lang.Object nextElement()

      This method implements part of the java.util.Enumeration interface. It is a wrapper for `nextSolution()`

      Returns:
        A Map representing a substitution.

    - #### isOpen

          public final boolean isOpen()

      Whether the query is open.
      Returns:
        true if the query is open, otherwise false.

    - #### getEngine

          public final long getEngine()

      Returns the engine attached to this query
      Returns:
        a long number representing the id of the SWI Prolog engine used in this query

    - #### hasMoreSolutions

          public final boolean hasMoreSolutions()

      This method returns true if JPL was able to initiate a "call" of this Query within a Prolog engine. It is designed to be used with the nextSolution() method to retrieve one or more substitutions in the form of Maps. To iterate through all the solutions to a Query, for example, one might write

           Query q = // obtain Query reference
           while (q.hasMoreSolutions()) {
               Map solution = q.nextSolution();
               // process solution...
           }

      Returns:
        true if the Prolog query succeeds; otherwise false.

    - #### open

          public final void open()

      This method returns true if JPL was able to initiate a "call" of this Query within the Prolog engine. It is designed to be used with the getSolution() and close() methods to retrieve one or more substitutions in the form of Maps.

           Query q = // obtain Query reference
           Map soln;
           q.open();
           while ((soln = q.getSolution()) != null) {
                // process solution...
           }

      If this method is called on an already-open Query, or if the query cannot be set up for whatever reason, then a JPLException will be thrown.

    - #### reset

          public final void reset()

      Reset the query to its start: closed and no solution found so far. This will allow a query to re-start

    - #### getSolution

          @Deprecated
          public final java.util.Map<java.lang.String,Term> getSolution()

      Deprecated. use nextSolution()
      Returns the next solution of the query
      Returns:
        the binding representing the next solution

    - #### getSubstWithNameVars

          @Deprecated
          public final java.util.Map<java.lang.String,Term> getSubstWithNameVars()

      Deprecated.
      Used to be used only by Utils.textToTerm but code has been integrated there already
      Returns:
        a substituion from variable names to terms

    - #### nextSolution

          public final java.util.Map<java.lang.String,Term> nextSolution()

      This method returns a java.util.Map, which represents a binding from the names of query variables to terms within the next solution.

      For example, if a Query has an occurrence of a jpl.Variable, say, named "X", one can obtain the Term bound to "X" in the solution by looking up "X" in the Map.

           Variable x = new Variable("X");
           Query q = // obtain Query reference (with x in the Term array)
           while (q.hasMoreSolutions()) {
               Map solution = q.nextSolution();
               // make t the Term bound to "X" in the solution
               Term t = (Term) solution.get("X");
               // ...
           }

      Programmers should be careful to call this method after checking that there is indeed a solution, via method hasMoreSolutions().
      Returns:
        A Map representing a substitution of the next solution.
      Throws:
        `JPLException` - if Query is not open.
        `java.util.NoSuchElementException` - if there are no more new solutions.

    - #### getSolutionWithVarNames

          @Deprecated
          public final java.util.Map<java.lang.String,Term> getSolutionWithVarNames()

      Deprecated.
      Deprecated. Used to be used only in the context of Term.textToTerm() but a better solution has been implemented there and hence does not require this difficult method anymore. Left it for reference. This is called with query atom_to_term(Atom, Term, Bindings) https://www.swi-prolog.org/pldoc/doc_for?object=atom_to_term/3 and we aim to return the Term version of Atom but with the name of the variables inside, not thir anonymous _ references. To do so we extract the names from Bindings and we plugged them into the Term So, we assume the last argument of the current querry is a Binding list of the form [Name=Var,..], that is a list containing variable names to actual Prolog variable references, like ['S'=_4518, 'P'=_4520]. E.g., atom_to_term('hello(a, X, Y)', T, B) T = hello(a, _1, _2) B = [ 'X' = _1, 'Y' = _2] The whole point is to return a JPL Term but having NAMED variables, that is returning the Compound Term hello(a, X, Y) where X and Y are JPL Variables (with names "X" and "Y")
      Returns:
        a Term with the variables with names

    - #### close

          public final void close()

      This method can be used to close an open query before its solutions are exhausted. It is called automatically when solutions are exhausted. Calling close() on an already closed Query has no effect.

      Here is one way to get the first three solutions to a Query:

           Query q = new Query(predicate, args);
           Map<String, Term> sub1 = q.nextSolution();
           Map<String, Term> sub2 = q.nextSolution();
           Map<String, Term> sub3 = q.nextSolution();
           q.close();

    - #### allSolutions

          public final java.util.Map<java.lang.String,Term>[] allSolutions()

      calls the Query's goal to exhaustion and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found).
      Returns:
        an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found) NB in JPL 1.0.1, this method (inconsistently) returned null when a Query had no solutions; in JPL 2.x onwards it returns an empty array (thus the length of the array is, in every case, the quantity of solutions).

        NB in JPL 1.0.1, bindings were keyed (awkwardly) by Variable instances; in JPL 2.x onwards they are keyed by the (String) names of variables, which is consistent with the Term type being just a concrete syntax for terms (and hence queries).

    - #### allSolutions

          public static final java.util.Map<java.lang.String,Term>[] allSolutions(Term goal)

      This static method creates a Query whose goal is the given Term, calls it to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found). Throws JPLException if goal is neither a jpl.Atom nor a jpl.Compound.
      Parameters:
        `goal` - the goal of this Query
      Returns:
        an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found)

    - #### allSolutions

          public static final java.util.Map<java.lang.String,Term>[] allSolutions(java.lang.String text)

      This static method creates a Query from the given Prolog source text fragment, calls it to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found). Throws PrologException containing error(syntax_error(_),_) if text is invalid.
      Parameters:
        `text` - a Prolog source text fragment denoting a goal
      Returns:
        an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found)

    - #### allSolutions

          public static final java.util.Map<java.lang.String,Term>[] allSolutions(java.lang.String text,
                                                                                  Term[] params)

      If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying Term params, this static method replaces each questionmark symbol by its respective param, calls the resulting goal to exhaustion, and returns an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found). Otherwise, if text denotes an atom, this static method creates a Query where text is the name of the goal and params are the args; the resulting goal is then called as above. This letter mode is redundant, deprecated (informally), and retained only for backward compatibility.
      Parameters:
        `text` - the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters
        `params` - terms to be substituted for the respective questionmarks in the query text
      Returns:
        an array of zero or more Maps of zero or more variablename-to-term bindings (each Map represents a solution, in the order in which they were found)

    - #### nSolutions

          public final java.util.Map<java.lang.String,Term>[] nSolutions(long n)

      calls the Query's goal to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found).
      Parameters:
        `n` - the number of solutions to cover
      Returns:
        an array of Maps (possibly none), each of which is a solution (in the order in which they were found) of the Query; at most 'n' solutions will be found and returned. NB in JPL 1.0.1, this method (inconsistently) returned null when a Query had no solutions; in JPL 2.x onwards it returns an empty array (thus the length of the array is, in every case, the quantity of solutions).

        NB in JPL 1.0.1, bindings were keyed (awkwardly) by Variable instances; in JPL 2.x onwards they are keyed by the (String) names of variables, which is consistent with the Term type being just a concrete syntax for terms (and hence queries).

    - #### nSolutions

          public static final java.util.Map<java.lang.String,Term>[] nSolutions(Term goal,
                                                                                long n)

      This static method creates a Query whose goal is the given Term, calls it to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found). Throws JPLException if goal is neither a jpl.Atom nor a jpl.Compound.
      Parameters:
        `goal` - the goal of this Query
        `n` - the number of solutions to cover
      Returns:
        an array of up to the the first n binding solutions

    - #### nSolutions

          public static final java.util.Map<java.lang.String,Term>[] nSolutions(java.lang.String text,
                                                                                long n)

      This static method creates a Query from the given Prolog source text fragment, calls it to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found). Throws PrologException containing error(syntax_error(_),_) if text is invalid.
      Parameters:
        `text` - a Prolog source text fragment denoting a goal
        `n` - the number of solutions to cover
      Returns:
        an array of up to the the first n binding solutions

    - #### nSolutions

          public static final java.util.Map<java.lang.String,Term>[] nSolutions(java.lang.String text,
                                                                                Term[] params,
                                                                                long n)

      If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N accompanying params, this static method replaces each questionmark symbol by its respective param, calls the resulting goal to exhaustion or until N solutions are found, whichever is sooner, and returns an array containing (as possibly empty Maps of variablename-to-term bindings) every found solution (in the order in which they were found). Otherwise, if text denotes an atom, this static method creates a Query where text is the name of the goal and params are the args; the resulting goal is then called as above. This latter mode is redundant, deprecated (informally), and retained only for backward compatibility.
      Parameters:
        `text` - the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters
        `params` - terms to be substituted for the respective questionmarks in the query text
        `n` - the number of solutions to cover
      Returns:
        an array of up to the the first n binding solutions

    - #### oneSolution

          public final java.util.Map<java.lang.String,Term> oneSolution()

      Returns the first solution, if any, as a (possibly empty) Map of variablename-to-term bindings, else null. This method will throw a JPLException if this Query is already open (and the Query will remain open as before). Otherwise, upon return, the Query will be closed.
      Returns:
        the first solution, if the query has one, as a (possibly empty) Map. If the return value is null, this means that the Query has no solutions.

    - #### oneSolution

          public static final java.util.Map<java.lang.String,Term> oneSolution(Term goal)

      This static method creates a Query (whose goal is the specified Term) and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Map, else null. The goal can be a jpl.Atom or a jpl.Compound, but cannot be an instance of jpl.Float, jpl.Integer or jpl.Variable.
      Parameters:
        `goal` - the goal of this Query
      Returns:
        binding of the first solution

    - #### oneSolution

          public static final java.util.Map<java.lang.String,Term> oneSolution(java.lang.String text)

      This static method creates a Query from the given Prolog source text fragment, and calls it at most once, returning the first solution, if there is one, as a (possibly empty) Map, else null. Throws PrologException containing error(syntax_error(_),_) if text is invalid.
      Parameters:
        `text` - a Prolog source text fragment denoting a goal
      Returns:
        binding of the first solution

    - #### oneSolution

          public static final java.util.Map<java.lang.String,Term> oneSolution(java.lang.String text,
                                                                               Term[] params)

      If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N params, each questionmark symbol is replaced by its respective param to provide the goal of this query: the resulting goal is then called (at most once) and the first solution, if there is one, is returned as a (possibly empty) Map, else null. Otherwise, if text denotes an atom, this static method creates a Query where text is the name of the goal and params are the args; the resulting goal is then called as above. This latter mode is redundant, deprecated (informally), and retained only for backward compatibility.
      Parameters:
        `text` - the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters
        `params` - terms to be substituted for the respective questionmarks in the query text
      Returns:
        binding of the first solution

    - #### hasSolution

          public final boolean hasSolution()

      This method will attempt to call this Query's goal within an available Prolog engine.
      Returns:
        the provability of the Query, i.e. 'true' if it has at least one solution, 'false' if the call fails without finding a solution.

        Only the first solution (if there is one) will be found; any bindings will be discarded, and the Query will be closed.

        This method will throw a JPLException if this Query is already open.

    - #### hasSolution

          public static final boolean hasSolution(Term goal)

      This static method creates a Query (whose goal is the specified Term) and calls it at most once, returning true if a solution was found, else false. The goal can be a jpl.Atom or a jpl.Compound, but cannot be an instance of jpl.Float, jpl.Integer or jpl.Variable.
      Parameters:
        `goal` - the goal of this Query
      Returns:
        true iff the query can be proved

    - #### hasSolution

          public static final boolean hasSolution(java.lang.String text)

      This static method creates a Query from the given Prolog source text and calls it at most once, returning true if a solution was found, else false. Throws PrologException containing error(syntax_error(_),_) if text is invalid.
      Parameters:
        `text` - the goal of this Query, as Prolog source text
      Returns:
        true iff the query can be proved

    - #### hasSolution

          public static final boolean hasSolution(java.lang.String text,
                                                  Term[] params)

      If text denotes (in traditional Prolog source syntax) a term containing N questionmark (?) symbols and there are N params, each questionmark symbol is replaced by its corresponding arg to provide the new Query's goal: the resulting Query is called as described above. Otherwise, if text denotes an atom, this static method creates a Query where text is the name of its goal and args are its args; it then calls this goal (at most once) and returns true if a solution was found, else false. This latter mode is redundant, deprecated (informally), and retained only for backward compatibility.
      Parameters:
        `text` - the Prolog source text of a goal, in which questionmarks are regarded as substitutible parameters
        `params` - terms to be substituted for the respective questionmarks in the query text
      Returns:
        true iff the query can be proved

    - #### toString

          public java.lang.String toString()

      Returns a crude String representation of a Query.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        a crude String representation of a Query