se.sics.jasper
Interface Prolog

All Known Implementing Classes:
SICStus

public interface Prolog

The class SICStus and an inner class in Jasper inherit from this interface. These methods should be used to call SICStus runtime in both multi threaded and single threaded mode. When using the Prolog-Java interface in single thread mode, the methods of this interface are preferred over the old methods of the class SICStus.


Method Summary
 Term consFunctor(java.lang.String functor, Term[] args)
          Creates a term initialized to a compound term.
 Term consList(Term head, Term tail)
          Creates a term initialized to a list with given head and tail.
 se.sics.jasper.Server getServer()
          For internal use by Jasper.
 Term listFromString(java.lang.String str)
          Creates a term initialized to a list of character codes from a Java String.
 Term newObjectTerm(java.lang.Object obj)
          Creates a term initialized to a *global* reference to a Java object.
 Term newTerm()
          Creates a null-term (i.e.
 Term newTerm(double d)
          Creates a term initialized to a Prolog float.
 Term newTerm(float f)
          Creates a term initialized to a Prolog float.
 Term newTerm(int i)
          Creates a term initialized to a Prolog integer from a Java int.
 Term newTerm(long j)
          Creates a term initialized to a Prolog integer from a Java long.
 Term newTerm(java.lang.String a)
          Creates a term initialized to a Prolog atom.
 Term newTerm(java.lang.String functor, Term[] args)
          Creates a term initialized to a Prolog compound term.
 Term newTerm(Term t)
          Creates a term initialized to an existing term.
 Term newVariable()
          Creates a term initialized to an unbound variable.
 Term numberFromString(java.lang.String str)
          Creates a term initialized to a Prolog number from a string.
 Query openPrologQuery(java.lang.String string, java.util.Map varMap)
          Opens a query, specified as a string, for obtaining multiple solutions.
 Term prologReadFromString(java.lang.String string, java.util.Map varMap)
          Creates a term by reading from a string.
 boolean query(java.lang.String string, java.util.Map varMap)
          Finds the first solution to a query specified as a string.
 boolean queryCutFail(java.lang.String string, java.util.Map varMap)
          Finds the first solution to a query specified as a string, then cuts away any choicepoints and fails, i.e.
 

Method Detail

getServer

public se.sics.jasper.Server getServer()
For internal use by Jasper.

openPrologQuery

public Query openPrologQuery(java.lang.String string,
                             java.util.Map varMap)
                      throws java.lang.NoSuchMethodException,
                             java.lang.InterruptedException,
                             java.lang.Exception
Opens a query, specified as a string, for obtaining multiple solutions. The method itself does not find any solutions; use the method nextSolution to do that. When no more solutions are needed, the query must be closed using methods close or cut on the query-object.

Multiple queries can be open at the same time. See nextSolution for details and restrictions.

Parameters:
string - The goal to use for the query, with terminating period.
varMap - The arguments to the predicate as a map from variable names to Term objects. The map will get entries added for all variables (with names not starting with underscore) in the goal that were not already present as input. May be null.
Returns:
The openened query object.
See Also:
Query.nextSolution(), Query.close(), Query.cut()

query

public boolean query(java.lang.String string,
                     java.util.Map varMap)
              throws java.lang.NoSuchMethodException,
                     java.lang.InterruptedException,
                     java.lang.Exception
Finds the first solution to a query specified as a string. If you need more than one solution, use openPrologQuery.
Parameters:
string - The goal to use for the query, with terminating period.
varMap - The arguments to the predicate as a map from variable names to Term objects. On success varMap will get entries added for all variables (with names not starting with underscore) in the goal that were not already present as input. May be null.
Returns:
True/false corresponding to success/failure of the query.
See Also:
openPrologQuery(java.lang.String, java.util.Map), queryCutFail(java.lang.String, java.util.Map), Term

queryCutFail

public boolean queryCutFail(java.lang.String string,
                            java.util.Map varMap)
                     throws java.lang.NoSuchMethodException,
                            java.lang.InterruptedException,
                            java.lang.Exception
Finds the first solution to a query specified as a string, then cuts away any choicepoints and fails, i.e. ignores everything but the side-effects during the first solution.
Parameters:
string - The goal to use for the query, with terminating period.
varMap - The arguments to the predicate as a map from variable names to Term objects. May be null. No bindings are added.
Returns:
True/false corresponding to success/failure of the query.
See Also:
query(java.lang.String, java.util.Map)

newTerm

public Term newTerm()
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a null-term (i.e. the empty list, '[]').

newTerm

public Term newTerm(Term t)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to an existing term. Modifications to the created Term does not affect the input Term.
Parameters:
t - The Term object whose term to use

newTerm

public Term newTerm(int i)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog integer from a Java int.
Parameters:
i - Initial value of the integer.

newTerm

public Term newTerm(long j)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog integer from a Java long.
Parameters:
j - Initial value of the integer (long).

newTerm

public Term newTerm(double d)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog float.
Parameters:
d - Initial value of the float.

newTerm

public Term newTerm(float f)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog float.
Parameters:
f - Initial value of the float.

newTerm

public Term newTerm(java.lang.String a)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog atom.
Parameters:
a - String describing the initial value of the atom.

newTerm

public Term newTerm(java.lang.String functor,
                    Term[] args)
             throws java.lang.InterruptedException,
                    java.lang.Exception
Creates a term initialized to a Prolog compound term.
Parameters:
functor - The functor of the compound term as a string
args - The arguments as an array of Terms

prologReadFromString

public Term prologReadFromString(java.lang.String string,
                                 java.util.Map varMap)
                          throws java.lang.InterruptedException,
                                 java.lang.Exception
Creates a term by reading from a string.
Parameters:
string - The printed representation of the term, with terminating period.
varMap - Bindings for any variables occurring in the term, as a map from variable names to Term objects. The map will get entries added for all variables (with names not starting with underscore) in the term that were not already present as input. May be null.

newVariable

public Term newVariable()
                 throws java.lang.InterruptedException,
                        java.lang.Exception
Creates a term initialized to an unbound variable.

consFunctor

public Term consFunctor(java.lang.String functor,
                        Term[] args)
                 throws java.lang.InterruptedException,
                        java.lang.Exception
Creates a term initialized to a compound term.
Parameters:
functor - The term's functor as a Java String
args - The arguments of the term

consList

public Term consList(Term head,
                     Term tail)
              throws java.lang.InterruptedException,
                     java.lang.Exception
Creates a term initialized to a list with given head and tail.
Parameters:
head - The head of the list
tail - The tail of the list

newObjectTerm

public Term newObjectTerm(java.lang.Object obj)
                   throws IllegalTermException,
                          ConversionFailedException,
                          java.lang.Exception
Creates a term initialized to a *global* reference to a Java object.
Parameters:
obj - A reference to a Java object.

numberFromString

public Term numberFromString(java.lang.String str)
                      throws ConversionFailedException,
                             IllegalTermException,
                             java.lang.Exception
Creates a term initialized to a Prolog number from a string.
Parameters:
str - The string containing the printed representation of the number.

listFromString

public Term listFromString(java.lang.String str)
                    throws ConversionFailedException,
                           IllegalTermException,
                           java.lang.Exception
Creates a term initialized to a list of character codes from a Java String.
Parameters:
str - The string of characters.