public class Prolog extends java.lang.Object implements IProlog, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static boolean |
EXCLUDE_KB_IN_SERIALIZATION |
static boolean |
INCLUDE_KB_IN_SERIALIZATION |
Constructor and Description |
---|
Prolog()
Builds a prolog engine with default libraries loaded.
|
Prolog(java.lang.String[] libs)
Builds a tuProlog engine with loaded
the specified libraries
|
Modifier and Type | Method and Description |
---|---|
void |
addExceptionListener(ExceptionListener l)
Adds a listener to exception events
|
void |
addLibraryListener(LibraryListener l)
Adds a listener to library events
|
void |
addOutputListener(OutputListener l)
Adds a listener to ouput events
|
void |
addQueryListener(QueryListener l)
Adds a listener to theory events
|
void |
addSpyListener(SpyListener l)
Adds a listener to spy events
|
void |
addTheory(Theory th)
Adds (appends) a theory
|
void |
addTheoryListener(TheoryListener l)
Adds a listener to theory events
|
void |
addWarningListener(WarningListener l)
Adds a listener to warning events
|
void |
clearTheory()
Clears current theory
|
boolean |
defineFlag(java.lang.String name,
Struct valueList,
Term defValue,
boolean modifiable,
java.lang.String libName)
Defines a new flag
|
void |
exception(java.lang.String m)
Notifies a exception information event
|
static Prolog |
fromJSON(java.lang.String jsonString) |
java.lang.String |
getCurrentDirectory()
Gets the last Element of the path list
|
java.lang.String[] |
getCurrentLibraries()
Gets the list of current libraries loaded
|
java.util.List<Operator> |
getCurrentOperatorList()
Gets the list of the operators currently defined
|
EngineManager |
getEngineManager()
Gets the component managing engine
|
static AbstractEngineState |
getEngineStateFromJSON(java.lang.String jsonString) |
java.util.List<ExceptionListener> |
getExceptionListenerList()
Gets a copy of current listener list to exception events
|
alice.tuprolog.FlagManager |
getFlagManager()
Gets the component managing flags
|
Theory |
getLastConsultedTheory()
Gets last consulted theory, with the original textual format
|
Library |
getLibrary(java.lang.String name)
Gets the reference to a loaded library
|
protected Library |
getLibraryFunctor(java.lang.String name,
int nArgs) |
java.util.List<LibraryListener> |
getLibraryListenerList()
Gets a copy of current listener list to library events
|
LibraryManager |
getLibraryManager()
Gets the component managing libraries
|
protected Library |
getLibraryPredicate(java.lang.String name,
int nArgs) |
OperatorManager |
getOperatorManager()
Gets the component managing operators
|
java.util.List<OutputListener> |
getOutputListenerList()
Gets a copy of current listener list to output events
|
PrimitiveManager |
getPrimitiveManager()
Gets the component managing primitives
|
java.util.List<QueryListener> |
getQueryListenerList()
Gets a copy of current listener list to query events
|
java.util.List<SpyListener> |
getSpyListenerList()
Gets a copy of current listener list to spy events
|
Theory |
getTheory()
Gets current theory
|
java.util.List<TheoryListener> |
getTheoryListenerList()
Gets a copy of current listener list to theory events
|
TheoryManager |
getTheoryManager()
Gets the component managing theory
|
static java.lang.String |
getVersion()
Gets the current version of the tuProlog system
|
java.util.List<WarningListener> |
getWarningListenerList()
Gets a copy of current listener list to warning events
|
boolean |
hasOpenAlternatives()
Asks for the presence of open alternatives to be explored
in current demostration process.
|
void |
identifyFunctor(Term term)
Identify functors
|
boolean |
isException()
Checks if exception information are notified
|
boolean |
isHalted()
Checks if the demonstration process was stopped by an halt command.
|
boolean |
isSpy()
Checks the spy state of the engine
|
boolean |
isWarning()
Checks if warning information are notified
|
void |
loadLibrary(Library lib)
Loads a specific instance of a library
If a library with the same name is already present,
a warning event is notified
|
Library |
loadLibrary(java.lang.String className)
Loads a library.
|
Library |
loadLibrary(java.lang.String className,
java.lang.String[] paths)
Loads a library.
|
boolean |
match(Term t0,
Term t1)
Unifies two terms using current demonstration context.
|
protected void |
notifyChangedTheory(TheoryEvent e)
Notifies a new theory set or updated event
|
protected void |
notifyException(ExceptionEvent e)
Notifies a exception information event
|
protected void |
notifyLoadedLibrary(LibraryEvent e)
Notifies a library loaded event
|
protected void |
notifyNewQueryResultAvailable(QueryEvent e)
Notifies a library loaded event
|
protected void |
notifyOutput(OutputEvent e)
Notifies an ouput information event
|
protected void |
notifySpy(SpyEvent e)
Notifies a spy information event
|
protected void |
notifyUnloadedLibrary(LibraryEvent e)
Notifies a library unloaded event
|
protected void |
notifyWarning(WarningEvent e)
Notifies a warning information event
|
void |
popDirectoryFromList()
Retract an element from directory list
|
void |
pushDirectoryToList(java.lang.String path)
Append a new path to directory list
|
void |
removeAllExceptionListeners()
Removes all exception event listeners
|
void |
removeAllOutputListeners()
Removes all output event listeners
|
void |
removeAllSpyListeners()
Removes all spy event listeners
|
void |
removeAllWarningListeners()
Removes all warning event listeners
|
void |
removeExceptionListener(ExceptionListener l)
Removes a listener to exception events
|
void |
removeLibraryListener(LibraryListener l)
Removes a listener to library events
|
void |
removeOutputListener(OutputListener l)
Removes a listener to ouput events
|
void |
removeQueryListener(QueryListener l)
Removes a listener to query events
|
void |
removeSpyListener(SpyListener l)
Removes a listener to spy events
|
void |
removeTheoryListener(TheoryListener l)
Removes a listener to theory events
|
void |
removeWarningListener(WarningListener l)
Removes a listener to warning events
|
void |
resetDirectoryList(java.lang.String path)
Reset directory list
|
void |
setCurrentDirectory(java.lang.String s)
Sets the last Element of the path list
|
void |
setException(boolean state)
Switches on/off the notification of exception information events
|
void |
setSpy(boolean state)
Switches on/off the notification of spy information events
|
void |
setTheory(Theory th)
Sets a new theory
|
void |
setWarning(boolean state)
Switches on/off the notification of warning information events
|
SolveInfo |
solve(java.lang.String st)
Solves a query
|
SolveInfo |
solve(Term g)
Solves a query
|
void |
solveEnd()
Accepts current solution
|
void |
solveHalt()
Halts current solve computation
|
SolveInfo |
solveNext()
Gets next solution
|
protected void |
spy(java.lang.String s)
Notifies a spy information event
|
protected void |
spy(java.lang.String s,
Engine e)
Notifies a spy information event
|
void |
stdOutput(java.lang.String m)
Produces an output information event
|
Term |
termSolve(java.lang.String st) |
java.lang.String |
toJSON(boolean alsoKB) |
java.lang.String |
toString(Term term)
Gets the string representation of a term, using operators
currently defined by engine
|
Term |
toTerm(java.lang.String st)
Gets a term from a string, using the operators currently
defined by the engine
|
boolean |
unify(Term t0,
Term t1)
Unifies two terms using current demonstration context.
|
void |
unloadLibrary(java.lang.String name)
Unloads a previously loaded library
|
void |
warn(java.lang.String m)
Notifies a warn information event
|
public static final boolean INCLUDE_KB_IN_SERIALIZATION
public static final boolean EXCLUDE_KB_IN_SERIALIZATION
public Prolog()
public Prolog(java.lang.String[] libs) throws InvalidLibraryException
libs
- the (class) name of the libraries to be loadedInvalidLibraryException
public static AbstractEngineState getEngineStateFromJSON(java.lang.String jsonString)
public static Prolog fromJSON(java.lang.String jsonString)
public java.lang.String toJSON(boolean alsoKB)
public alice.tuprolog.FlagManager getFlagManager()
public TheoryManager getTheoryManager()
public PrimitiveManager getPrimitiveManager()
getPrimitiveManager
in interface IProlog
public LibraryManager getLibraryManager()
public OperatorManager getOperatorManager()
getOperatorManager
in interface IProlog
public EngineManager getEngineManager()
public static java.lang.String getVersion()
public java.lang.String getCurrentDirectory()
public void setCurrentDirectory(java.lang.String s)
public void setTheory(Theory th) throws InvalidTheoryException
th
- is the new theoryInvalidTheoryException
- if the new theory is not validTheory
public void addTheory(Theory th) throws InvalidTheoryException
addTheory
in interface IProlog
th
- is the theory to be addedInvalidTheoryException
- if the new theory is not validTheory
public Theory getTheory()
public Theory getLastConsultedTheory()
public void clearTheory()
clearTheory
in interface IProlog
public Library loadLibrary(java.lang.String className) throws InvalidLibraryException
loadLibrary
in interface IProlog
className
- name of the Java class containing the library to be loadedInvalidLibraryException
- if name is not a valid librarypublic Library loadLibrary(java.lang.String className, java.lang.String[] paths) throws InvalidLibraryException
className
- name of the Java class containing the library to be loadedpaths
- The path where is contained the library.InvalidLibraryException
- if name is not a valid librarypublic void loadLibrary(Library lib) throws InvalidLibraryException
lib
- the (Java class) name of the library to be loadedInvalidLibraryException
- if name is not a valid librarypublic java.lang.String[] getCurrentLibraries()
getCurrentLibraries
in interface IProlog
public void unloadLibrary(java.lang.String name) throws InvalidLibraryException
unloadLibrary
in interface IProlog
name
- of the library to be unloadedInvalidLibraryException
- if name is not a valid loaded librarypublic Library getLibrary(java.lang.String name)
getLibrary
in interface IProlog
name
- the name of the library already loadedprotected Library getLibraryPredicate(java.lang.String name, int nArgs)
protected Library getLibraryFunctor(java.lang.String name, int nArgs)
public java.util.List<Operator> getCurrentOperatorList()
public SolveInfo solve(Term g)
g
- the term representing the goal to be demonstratedSolveInfo
public SolveInfo solve(java.lang.String st) throws MalformedGoalException
solve
in interface IProlog
st
- the string representing the goal to be demonstratedMalformedGoalException
SolveInfo
public SolveInfo solveNext() throws NoMoreSolutionException
solveNext
in interface IProlog
NoMoreSolutionException
- if no more solutions are presentSolveInfo
public void solveHalt()
public void solveEnd()
public boolean hasOpenAlternatives()
hasOpenAlternatives
in interface IProlog
public boolean isHalted()
public boolean match(Term t0, Term t1)
t0
- first term to be unifiedt1
- second term to be unifiedpublic boolean unify(Term t0, Term t1)
t0
- first term to be unifiedt1
- second term to be unifiedpublic void identifyFunctor(Term term)
term
- term to identifypublic Term toTerm(java.lang.String st) throws InvalidTermException
st
- the string representing a termInvalidTermException
- if the string does not represent a valid termpublic java.lang.String toString(Term term)
public boolean defineFlag(java.lang.String name, Struct valueList, Term defValue, boolean modifiable, java.lang.String libName)
public void setSpy(boolean state)
public boolean isSpy()
protected void spy(java.lang.String s)
protected void spy(java.lang.String s, Engine e)
s
- TODOpublic void setWarning(boolean state)
state
- - true for enabling warning information notificationpublic boolean isWarning()
public void warn(java.lang.String m)
m
- the warning messagepublic void exception(java.lang.String m)
m
- the exception messagepublic boolean isException()
public void setException(boolean state)
state
- - true for enabling exception information notificationpublic void stdOutput(java.lang.String m)
m
- the output stringpublic void addOutputListener(OutputListener l)
addOutputListener
in interface IProlog
l
- the listenerpublic void addTheoryListener(TheoryListener l)
l
- the listenerpublic void addLibraryListener(LibraryListener l)
l
- the listenerpublic void addQueryListener(QueryListener l)
l
- the listenerpublic void addSpyListener(SpyListener l)
addSpyListener
in interface IProlog
l
- the listenerpublic void addWarningListener(WarningListener l)
l
- the listenerpublic void addExceptionListener(ExceptionListener l)
addExceptionListener
in interface IProlog
l
- the listenerpublic void removeOutputListener(OutputListener l)
removeOutputListener
in interface IProlog
l
- the listenerpublic void removeAllOutputListeners()
removeAllOutputListeners
in interface IProlog
public void removeTheoryListener(TheoryListener l)
l
- the listenerpublic void removeLibraryListener(LibraryListener l)
l
- the listenerpublic void removeQueryListener(QueryListener l)
l
- the listenerpublic void removeSpyListener(SpyListener l)
removeSpyListener
in interface IProlog
l
- the listenerpublic void removeAllSpyListeners()
removeAllSpyListeners
in interface IProlog
public void removeWarningListener(WarningListener l)
l
- the listenerpublic void removeAllWarningListeners()
public void removeExceptionListener(ExceptionListener l)
removeExceptionListener
in interface IProlog
l
- the listenerpublic void removeAllExceptionListeners()
removeAllExceptionListeners
in interface IProlog
public java.util.List<OutputListener> getOutputListenerList()
public java.util.List<WarningListener> getWarningListenerList()
public java.util.List<ExceptionListener> getExceptionListenerList()
public java.util.List<SpyListener> getSpyListenerList()
public java.util.List<TheoryListener> getTheoryListenerList()
public java.util.List<LibraryListener> getLibraryListenerList()
public java.util.List<QueryListener> getQueryListenerList()
protected void notifyOutput(OutputEvent e)
e
- the eventprotected void notifySpy(SpyEvent e)
e
- the eventprotected void notifyWarning(WarningEvent e)
e
- the eventprotected void notifyException(ExceptionEvent e)
e
- the eventprotected void notifyChangedTheory(TheoryEvent e)
e
- the eventprotected void notifyLoadedLibrary(LibraryEvent e)
e
- the eventprotected void notifyUnloadedLibrary(LibraryEvent e)
e
- the eventprotected void notifyNewQueryResultAvailable(QueryEvent e)
e
- the eventpublic void pushDirectoryToList(java.lang.String path)
public void popDirectoryFromList()
public void resetDirectoryList(java.lang.String path)
public Term termSolve(java.lang.String st)