|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectubc.cs.JLog.Foundation.jPrologAPI
public class jPrologAPI
This class is encapsulates the Prolog Engine into a single, simple class, suitable for programmatic access.
Nested Class Summary | |
---|---|
protected class |
jPrologAPI.KeyPairs
|
Field Summary | |
---|---|
protected jPrologServices |
prolog
|
protected int |
query_state
|
protected static int |
QUERY_STATE_FINISHED
|
protected static int |
QUERY_STATE_SUCCEEDED
|
protected static int |
QUERY_STATE_WAITING
|
protected jAPIQueryThread |
thread
|
protected jTermTranslation |
translations
|
protected java.util.Hashtable |
var_translation_keys
|
Constructor Summary | |
---|---|
jPrologAPI(java.io.InputStream source)
Basic constructor instantiates a bare-bones Prolog engine, and consults the given source input stream. |
|
jPrologAPI(java.io.InputStream source,
iPrologFileServices fs,
java.io.PrintWriter output,
java.io.BufferedReader input,
java.lang.Object ae)
Complete constructor instantiates a bare-bones Prolog engine, sets the external services to those provided, and consults the given source input stream. |
|
jPrologAPI(java.lang.String source)
Basic constructor instantiates a bare-bones Prolog engine, and consults the given source string. |
|
jPrologAPI(java.lang.String source,
iPrologFileServices fs,
java.io.PrintWriter output,
java.io.BufferedReader input,
java.lang.Object ae)
Complete constructor instantiates a bare-bones Prolog engine, sets the external services to those provided, and consults the given source string. |
Method Summary | |
---|---|
void |
consultSource(java.lang.String source)
Consult a source string. |
boolean |
getFailUnknownPredicate()
Get the behaviour for unknown predicates. |
java.lang.String |
getRequiredCreditInfo()
This function returns the credit assignment and copyright informaiton string. |
jTermTranslation |
getTranslation()
Get the current translation unit used to convert queries and results between Prolog terms and Java objects. |
protected void |
initConsultSource(java.lang.String source)
|
protected void |
initPrologListeners()
|
protected void |
initTranslation()
|
protected void |
joinForcedQueryCompletion()
|
java.util.Hashtable |
query(java.lang.String query)
Initiates a query. |
java.util.Hashtable |
query(java.lang.String query,
java.util.Hashtable bindings)
Initiates a query, pre-binding variables based on the key:value pairs in the given hashtable. |
java.util.Hashtable |
queryOnce(java.lang.String query)
Initiates a query, and stops the query after the first result. |
java.util.Hashtable |
queryOnce(java.lang.String query,
java.util.Hashtable bindings)
Initiates a query, pre-binding variables based on the key:value pairs in the given hashtable, but stops the query after the first result. |
java.util.Hashtable |
retry()
Retries the previous query. |
void |
setFailUnknownPredicate(boolean fp)
Set the behaviour for unknown predicates. |
protected void |
setQueryResultState(boolean result)
|
void |
setTranslation(jTermTranslation tt)
Sets the translation unit used to convert queries and results between Prolog terms and Java objects. |
void |
setVariableTranslationKeys(java.lang.String v,
java.lang.Object tkey,
java.lang.Object okey)
Associates a variable with translation keys. |
void |
stop()
|
protected java.util.Hashtable |
waitForCompletion()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int QUERY_STATE_WAITING
protected static final int QUERY_STATE_SUCCEEDED
protected static final int QUERY_STATE_FINISHED
protected jPrologServices prolog
protected jAPIQueryThread thread
protected java.util.Hashtable var_translation_keys
protected jTermTranslation translations
protected int query_state
Constructor Detail |
---|
public jPrologAPI(java.lang.String source)
source
- The source string to consult (i.e., the initial KB).public jPrologAPI(java.io.InputStream source) throws java.io.IOException
source
- The source input stream to consult (i.e., the initial KB).
java.io.IOException
public jPrologAPI(java.lang.String source, iPrologFileServices fs, java.io.PrintWriter output, java.io.BufferedReader input, java.lang.Object ae)
source
- The source string to consult (i.e., the initial KB).fs
- External file services facilities (e.g., used for load_library/1 etc.) If
null, an instance of jPrologFileServices is used by default.output
- External text ouput facilities (e.g., used for writeln/1 etc.)input
- External text input facilities (e.g., used for read/1 etc.)ae
- External animation display facilities (e.g., used for animation/2 etc.)
Must be of type aAnimationEnvironment
, else an exception will
be thrown when proving animation/2
.public jPrologAPI(java.io.InputStream source, iPrologFileServices fs, java.io.PrintWriter output, java.io.BufferedReader input, java.lang.Object ae) throws java.io.IOException
source
- The source input stream to consult (i.e., the initial KB).fs
- External file services facilities (e.g., used for load_library/1 etc.) If
null, an instance of jPrologFileServices is used by default.output
- External text ouput facilities (e.g., used for writeln/1 etc.)input
- External text input facilities (e.g., used for read/1 etc.)ae
- External animation display facilities (e.g., used for animation/2 etc.)
Must be of type aAnimationEnvironment
, else an exception will
be thrown when proving animation/2
.
java.io.IOException
Method Detail |
---|
protected void initTranslation()
protected void initPrologListeners()
protected void initConsultSource(java.lang.String source)
public java.lang.String getRequiredCreditInfo()
public void setFailUnknownPredicate(boolean fp)
fp
- If fail
(default) then missing predicates generate a
failing exception (i.e., exception thrown), if false
then the query for that predicate fails (i.e., no exception is thrown).public boolean getFailUnknownPredicate()
public void setVariableTranslationKeys(java.lang.String v, java.lang.Object tkey, java.lang.Object okey)
v
- The name of the variable.tkey
- The translation lookup key to use for translating the value bound to this
variable to a prolog term. Set to null to use the default translation.okey
- The translation lookup key to use for translating the value bound to this
variable back to a Java object. Set to null for the default translation.public jTermTranslation getTranslation()
jTermTranslation
object used for translating between
objects and terms.public void setTranslation(jTermTranslation tt)
tt
- The jTermTranslation
object to use for translating between
objects and terms.public void consultSource(java.lang.String source)
source
- The KB source string to consult.public java.util.Hashtable query(java.lang.String query)
query
- The query string (must be non-empty).
public java.util.Hashtable queryOnce(java.lang.String query)
query
- The query string (must be non-empty).
public java.util.Hashtable query(java.lang.String query, java.util.Hashtable bindings)
jTermTranslation
for more information about how translation between
Java objects and Prolog terms is performed. By default, the jPrologAPI class uses the
default translation, but the user may set the preferred jTermTranslation object.
query
- The query string (must be non-empty).bindings
- A hashtable mapping variable names (key) to their values (value). If
null, then performs the same as query(String)
above.
query(String)
above). The values are translated using the
translation object associated with this API object (to translate from
jTerm to Object). Returns null if the query fails.public java.util.Hashtable queryOnce(java.lang.String query, java.util.Hashtable bindings)
query
- The query string (must be non-empty).bindings
- A hashtable mapping variable names (key) to their values (value).
Just as the corresponding query method.
public java.util.Hashtable retry()
query(String)
above). Returns null if the query retry fails.public void stop()
protected java.util.Hashtable waitForCompletion()
protected void setQueryResultState(boolean result)
protected void joinForcedQueryCompletion()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |