|
|
com.declarativa.interprolog
|
Field Summary | |
String |
firstJavaMessageName
Name of first message sent to Java |
boolean |
interrupting
Prolog is handling an interrupt |
static String |
nl
Convenience for newline |
String |
prologBinDirectoryOrCommand
File path to directory with Prolog machine, or command path, which may have options appended |
Fields inherited from interface com.declarativa.interprolog.PrologEngine |
MAX_INT_VALUE, MIN_INT_VALUE, version |
Constructor Summary | |
AbstractPrologEngine(String prologBinDirectoryOrCommand,
boolean debug,
boolean loadFromJar)
Create a Prolog executor, possibly spawning it in a different process or loading it into memory, depending on the implementation by our subclass. |
Method Summary | |
void |
abortTasks()
Do not invoke this. |
static boolean |
assignableType(Class left,
Class right)
It is OK to assign an expression typed right to a variable typed left. |
boolean |
command(String s)
Execute a Prolog "command" |
boolean |
consultAbsolute(File f)
Consults a Prolog file |
void |
consultFromPackage(String filename,
Object requester)
Extracts a Prolog file from the jar file or directory where the requester's class came from, and asks Prolog process to consult it. |
void |
consultRelative(String filename,
Object requester)
Consults a Prolog file from the directory where the requester's class would come from if it did not come from a jar file. |
boolean |
deterministicGoal(String G)
A parameterless goal with no result other than success/failure. |
Object[] |
deterministicGoal(String G,
String RVars)
Useful when you're constructing objects from Prolog, but don't need to pass any from Java. |
boolean |
deterministicGoal(String G,
String OVar,
Object[] objectsP)
Useful when you want to pass objects to Prolog but don't need objects returned. |
Object[] |
deterministicGoal(String G,
String OVar,
Object[] objectsP,
String RVars)
Synchronously calls a Prolog goal. |
TermModel |
deterministicGoal(TermModel G)
Useful for inter-Prolog goal calling through Java. |
ResultFromJava |
doCallback(Object x)
Execute a Prolog->Java call |
void |
endAllTasks(Exception e)
Do not invoke this |
static Constructor |
findConstructor(Class targetClass,
Class[] formalArguments)
Similar to findMethod(), but for constructors rather than regular methods |
static Method |
findMethod(Class targetClass,
String name,
Class[] formalArguments)
An utility building on the functionality of getMethod(), to provide the javaMessage predicate with method argument polimorphism. |
void |
firstJavaMessage()
Dummy method, whose name is used to start the callback thread |
PrologImplementationPeer |
getImplementationPeer()
|
File |
getJarDirectory()
Returns the directory containing the jar with the engine class |
static File |
getJarDirectory(Class aClass)
Returns the directory containing the jar with the given class |
boolean |
getLoadFromJar()
|
String |
getPrologBaseDirectory()
Returns the installation directory for the Prolog system, without the trailing separator char |
String |
getPrologNumericVersion()
Returns the Prolog numeric version for this engine; useful for functionality that depends on features of a particular version. |
String |
getPrologVersion()
Returns the Prolog system name and version for this engine |
Object |
getRealJavaObject(int ID)
Same as getRealJavaObject(InvisibleObject), but accepts an integer ID as argument instead |
Object |
getRealJavaObject(InvisibleObject o)
Get the object referred by the integer in a InvisibleObject wrapper. |
Object |
getRealJavaObject(Object o)
Just returns the object, untouched (but "dereferenced" if called from Prolog). |
Object |
handleCallback(Object x)
Handling of javaMessages and deterministicGoals. |
void |
interrupt()
Interrupt Prolog and make it return to its top level. |
void |
interruptTasks()
Do not invoke this. |
boolean |
isAvailable()
Present implementation is always available, so this always returns true. |
boolean |
isDebug()
Debug messages are being written, both Java and Prolog side, cf. ipIsDebugging/0 |
boolean |
isIdle()
The engine is doing nothing: no pending Prolog goals nor Java callbacks |
static boolean |
isMacOS()
|
boolean |
isShutingDown()
The engine is in the process of shuting down |
static boolean |
isWindowsOS()
|
void |
load_dynRelative(String filename,
Object requester)
|
Object |
makeInvisible(Object x)
Register an object with this Engine, so it later can be referred from Prolog without serializing it, and returns an InvisibleObject encapsulating the reference. |
static void |
printBindings(Object[] b)
Convenience for debugging deterministicGoal() messages |
void |
progressMessage(String s)
Debugging aid |
String |
prologBinToBaseDirectory(String binDirectoryOrStartCommand)
Computes the installation directory for the Prolog system, without the trailing separator char |
abstract boolean |
realCommand(String s)
Implementation of a simple parameterless Prolog goal; does not support recursive nor multithreaded operation, use command instead |
int |
registerJavaObject(Object x)
Register an object with this Engine, so it later can be referred from Prolog without serializing it. |
void |
setDebug(boolean d)
Show (or hide) debug messages, both Java and Prolog side, cf. ipIsDebugging/0. |
void |
setThreadedCallbacks(boolean yes)
If true, the Java execution of javaMessage predicates will happen in new threads (default); if false, execution will be under the thread of the deterministicGoal currently executing in Prolog |
static String |
shortClassName(Class c)
Returns just the name of the class, with no package information. |
void |
shutdown()
Release Prolog engine resources, making it unusable |
boolean |
teachMoreObjects(Object[] examples)
Same as #teachMoreObjects(ObjectExamplePair[]), but example pairs are constructed with (2) repeated examples for each object |
boolean |
teachMoreObjects(ObjectExamplePair example)
|
boolean |
teachMoreObjects(ObjectExamplePair[] examples)
Send an array of object example pairs to Prolog and generate ipObjectSpec facts. |
boolean |
teachOneObject(Object example)
Same as #teachMoreObjects(ObjectExamplePair[]), but the single example pair is constructed repeating the object |
String |
unescapedFilePath(String p)
Some Prologs use '\' as an escape character in atoms, which can affect file paths under Windows. |
boolean |
unregisterJavaObject(int ID)
Removes reference to the object from the registry. |
boolean |
unregisterJavaObject(Object obj)
Removes reference to the object from the registry. |
boolean |
unregisterJavaObjects(Class cls)
Removes references to objects of class cls from the registry. |
void |
waitUntilAvailable()
This method blocks until isAvailable() returns true. |
void |
waitUntilIdle()
Sleeps the current Java thread until this engine is idle. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public String prologBinDirectoryOrCommand
public static final String nl
public boolean interrupting
public final String firstJavaMessageName
Constructor Detail |
public AbstractPrologEngine(String prologBinDirectoryOrCommand, boolean debug, boolean loadFromJar)
prologBinDirectoryOrCommand
- File path to Prolog machine, see subclass docs for precise semanticsdebug
- if true, print progress messages to aid debuggingloadFromJar
- if true, startup files should be loaded from the jar file, rather than directly from the file system
IF prologBinDirectoryOrCommand is null then InterProlog needs to find values for one or more properties, XSB_BIN_DIRECTORY and/or SWI_BIN_DIRECTORY, depending on which Prolog(s) you're using.
First it looks for an 'interprolog.defs' file
(a Properties file in the format described in http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html,
in the directory where the jar file containing the InterProlog classes is).
If 'interprolog.defs' does not exist, an attempt is made
to get the property through System.getProperties(); in this scenario you can define the property by using the -D java (command) switch
Method Detail |
public PrologImplementationPeer getImplementationPeer()
getImplementationPeer
in interface PrologEngine
public String getPrologVersion()
getPrologVersion
in interface PrologEngine
public String getPrologNumericVersion()
public String getPrologBaseDirectory()
getPrologBaseDirectory
in interface PrologEngine
public String prologBinToBaseDirectory(String binDirectoryOrStartCommand)
public static boolean isWindowsOS()
public static boolean isMacOS()
public void shutdown()
shutdown
in interface PrologEngine
public boolean isShutingDown()
public File getJarDirectory()
public static File getJarDirectory(Class aClass)
public String unescapedFilePath(String p)
public void consultFromPackage(String filename, Object requester)
consultFromPackage
in interface PrologEngine
filename
- The Prolog file name, including extension; if it has no extension, the Prolog file extensions are appended in turn until a file is foundrequester
- Defines where the Prolog file residesconsultRelative(String, Object)
,
load_dynRelative(String, Object)
public boolean consultAbsolute(File f)
consultAbsolute
in interface PrologEngine
public void consultRelative(String filename, Object requester)
consultRelative
in interface PrologEngine
filename
- The Prolog file name, including suffix; if a path it should use '/' as the separator, independently of the OSrequester
- Defines where the Prolog file residespublic void load_dynRelative(String filename, Object requester)
load_dynRelative
in interface PrologEngine
public void interrupt()
interrupt
in interface PrologEngine
public boolean command(String s)
command
in interface PrologEngine
public abstract boolean realCommand(String s)
command(String)
public void progressMessage(String s)
public boolean isDebug()
isDebug
in interface PrologEngine
public void setDebug(boolean d)
setDebug
in interface PrologEngine
public boolean getLoadFromJar()
public static void printBindings(Object[] b)
public boolean teachOneObject(Object example)
teachOneObject
in interface PrologEngine
public boolean teachMoreObjects(Object[] examples)
teachMoreObjects
in interface PrologEngine
public boolean teachMoreObjects(ObjectExamplePair[] examples)
teachMoreObjects
in interface PrologEngine
examples
- The examplesObjectExamplePair
public boolean teachMoreObjects(ObjectExamplePair example)
public Object[] deterministicGoal(String G, String OVar, Object[] objectsP, String RVars)
deterministicGoal
in interface PrologEngine
G
- Prolog goal termOVar
- Prolog variable that will be bound to objectsP arrayobjectsP
- Array of Java objects to pass to Prolog goalRVars
- Prolog list with object specifications, typically containing variables occurring in g.
If null a single binding will be returned, containing a TermModel object representing the goal term solution
deterministicGoal(String)
,
deterministicGoal(String,String)
,
deterministicGoal(String,String,Object[])
public boolean deterministicGoal(String G)
deterministicGoal
in interface PrologEngine
public Object[] deterministicGoal(String G, String RVars)
deterministicGoal
in interface PrologEngine
public boolean deterministicGoal(String G, String OVar, Object[] objectsP)
deterministicGoal
in interface PrologEngine
public TermModel deterministicGoal(TermModel G)
deterministicGoal
in interface PrologEngine
public boolean isIdle()
isIdle
in interface PrologEngine
public void endAllTasks(Exception e)
public void abortTasks()
public void interruptTasks()
public boolean isAvailable()
isAvailable
in interface PrologEngine
public void waitUntilAvailable()
PrologEngine
isAvailable()
returns true.
waitUntilAvailable
in interface PrologEngine
public void waitUntilIdle()
waitUntilIdle
in interface PrologEngine
public Object handleCallback(Object x)
x
- Argument of the callback predicatepublic final void firstJavaMessage()
public ResultFromJava doCallback(Object x)
public static Method findMethod(Class targetClass, String name, Class[] formalArguments) throws NoSuchMethodException
NoSuchMethodException
public static Constructor findConstructor(Class targetClass, Class[] formalArguments) throws NoSuchMethodException
NoSuchMethodException
public static boolean assignableType(Class left, Class right)
public static String shortClassName(Class c)
foo.bar.Mumble
were the class passed in, the
string "Mumble"
would be returned. Similarly, if the class
that is passed in is a.b.Class$InnerClass
the string
returned would be InnerClass
.
public int registerJavaObject(Object x)
registerJavaObject
in interface PrologEngine
x
- Object to be registered
InvisibleObject
public Object makeInvisible(Object x)
makeInvisible
in interface PrologEngine
x
- Object to be registered
InvisibleObject
public Object getRealJavaObject(InvisibleObject o)
getRealJavaObject
in interface PrologEngine
o
- An InvisibleObject
InvisibleObject
public Object getRealJavaObject(int ID)
getRealJavaObject
in interface PrologEngine
public Object getRealJavaObject(Object o)
getRealJavaObject
in interface PrologEngine
public boolean unregisterJavaObject(int ID)
unregisterJavaObject
in interface PrologEngine
public boolean unregisterJavaObject(Object obj)
unregisterJavaObject
in interface PrologEngine
public boolean unregisterJavaObjects(Class cls)
cls
from the registry. This method should be
used with extreme caution since any further prolog calls to the unregistered objects by means
of reference to them in the registry might result in unpredictable behaviour.
unregisterJavaObjects
in interface PrologEngine
public void setThreadedCallbacks(boolean yes)
setThreadedCallbacks
in interface PrologEngine
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Declarativa - Serviços de Informática, Lda. |