JTP API Documentation

jtp.context
Class BasicReasoningContext

java.lang.Object
  |
  +--java.beans.beancontext.BeanContextChildSupport
        |
        +--java.beans.beancontext.BeanContextSupport
              |
              +--jtp.context.BasicReasoningContext
All Implemented Interfaces:
BeanContext, BeanContextChild, BeanContextServiceRevokedListener, BeanContextServicesListener, Collection, DesignMode, EventListener, PropertyChangeListener, Serializable, VetoableChangeListener, Visibility
Direct Known Subclasses:
Context, Context

public class BasicReasoningContext
extends BeanContextSupport

A basic interface for JTP with a default configuration.

A reasoning context is the interface that a user should interact with. A reasoning context provides an interface to an AskingControlReasoner, a TellingControlReasoner, an AskingControlDispatcher, and a TellingControlDispatcher. The BasicReasoningContext provides usable methods such as ask(String), tell(Object), and tellString(String).

The BasicReasoningContext exports several properties to its nested children by firing java.beans.PropertyChangeEvents when the properties are set/changed. In order for an object to import one or more properties from this context, it should extend PropertyImporter and use the method PropertyImporter.setImportedProperties(java.lang.String[]). The object must also be added as a child to this context via the method BeanContextSupport.add(Object).

See Also:
Serialized Form

Field Summary
 Tracer tracer
           
 
Fields inherited from class java.beans.beancontext.BeanContextSupport
bcmListeners, children, designTime, locale, okToUseGui
 
Fields inherited from class java.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
 
Fields inherited from interface java.beans.beancontext.BeanContext
globalHierarchyLock
 
Fields inherited from interface java.beans.DesignMode
PROPERTYNAME
 
Constructor Summary
BasicReasoningContext()
           
 
Method Summary
 ReasoningStepIterator ask(String query)
          Submits a query.
 int assertString(String assertion)
          Deprecated. Use tellString(String).
 void defaultSetup()
          Performs a default setup for this context.
 Dispatcher getAskingDispatcher()
          Returns the AskingControlDispatcher.
 Reasoner getAskingReasoner()
          Returns the AskingControlReasoner.
 ReasoningStepIterator getAssertionResults(DirectAssertion assertion)
          Asserts assertion to the telling reasoners.
 Dispatcher getIntermediateResultDispatcher()
           
 int getMaxDepth()
          Returns an integer representing both the telling and asking systems' maximum depth.
 FirstOrderLogicParser getParser()
          Returns parser used to parse String and URL arguments to tellString(String), tellString(String, URL), loadKB(URL, URL), loadKB(URL), getStringAssertionResults(String), and ask(String).
 ReasoningStepIterator getStringAssertionResults(String assertion)
          Asserts to the telling reasoners the clauses encoded in a String.
 Dispatcher getTellingDispatcher()
          Returns the TellingControlDispatcher.
 Reasoner getTellingReasoner()
          Returns the TellingControlReasoner.
 Tracer getTracer()
          Returns the tracer being used by the system.
 FirstOrderLogicTranslator getTranslator()
          Returns translator used to translate String argument in ask(String).
 UndoManager getUndoManager()
          Returns the Undo Manager used to store modifications to the system so that the system can be returned to previous states.
 void loadClauses(ClauseIterator cit, URL publicLocation)
          Feeds a sequence of clauses to the telling reasoner.
 void loadKB(URL url)
          Loads a KB from a URL.
 void loadKB(URL actualLocation, URL publicLocation)
          Loads a KB from a URL.
 void setAskingDispatcher(Dispatcher v)
          Sets the AskingControlDispatcher.
 void setAskingReasoner(Reasoner v)
          Sets the AskingControlReasoner.
 void setIntermediateResultDispatcher(Dispatcher v)
          Fires a PropertyChangeEvent.
 void setMaxDepth(int v)
          Sets both the telling and asking systems' maximum depth.
 void setParser(FirstOrderLogicParser v)
          Sets parser returned by getParser().
 void setTellingDispatcher(Dispatcher v)
          Sets the TellingControlDispatcher.
 void setTellingReasoner(Reasoner v)
          Sets the TellingControlReasoner.
 void setTracer(Tracer v)
          Sets the tracer to be used by the system.
 void setUndoManager(UndoManager undo)
          Sets the UndoManager.
 int tell(Object assertion)
          A DirectAssertion with assertion as its goal is sent to the TellingControlReasoner.
protected  int tellInternal(DirectAssertion assertion)
          Helper method called by most of the public tell methods (e.g., tellString(String)).
 int tellString(String assertion)
          Asserts to the telling reasoners the Clauses encoded in a String.
 int tellString(String assertion, URL url)
          Asserts to the telling reasoners the clauses encoded in a String.
 boolean undo()
          Undoes the last top-level modification made to the system.
 void untell(Object assertion)
          Attempts to untell assertion via the undo manager.
 
Methods inherited from class java.beans.beancontext.BeanContextSupport
add, addAll, addBeanContextMembershipListener, avoidingGui, bcsChildren, bcsPreDeserializationHook, bcsPreSerializationHook, childDeserializedHook, childJustAddedHook, childJustRemovedHook, classEquals, clear, contains, containsAll, containsKey, copyChildren, createBCSChild, deserialize, dontUseGui, fireChildrenAdded, fireChildrenRemoved, getBeanContextPeer, getChildBeanContextChild, getChildBeanContextMembershipListener, getChildPropertyChangeListener, getChildSerializable, getChildVetoableChangeListener, getChildVisibility, getLocale, getResource, getResourceAsStream, initialize, instantiateChild, isDesignTime, isEmpty, isSerializing, iterator, needsGui, okToUseGui, propertyChange, readChildren, remove, remove, removeAll, removeBeanContextMembershipListener, retainAll, serialize, setDesignTime, setLocale, size, toArray, toArray, validatePendingAdd, validatePendingRemove, vetoableChange, writeChildren
 
Methods inherited from class java.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

tracer

public Tracer tracer
Constructor Detail

BasicReasoningContext

public BasicReasoningContext()
Method Detail

getParser

public FirstOrderLogicParser getParser()
Returns parser used to parse String and URL arguments to tellString(String), tellString(String, URL), loadKB(URL, URL), loadKB(URL), getStringAssertionResults(String), and ask(String).

Returns:
default FirstOrderLogicParser

setParser

public void setParser(FirstOrderLogicParser v)
Sets parser returned by getParser(). Also sets Translator's parser.

Fires a PropertyChangeEvent.

Parameters:
v - default FirstOrderLogicParser to be used by this context

getTranslator

public FirstOrderLogicTranslator getTranslator()
Returns translator used to translate String argument in ask(String). Initially, this is an instance of ParserBasedTranslator.

Returns:
default Translator

getAskingReasoner

public Reasoner getAskingReasoner()
Returns the AskingControlReasoner. This is the reasoner that initially receives queries. The AskingControlReasoner manages the search for proofs of queries and provides the entry point to the AskingControlDispatcher.

Returns:
AskingControlReasoner

setAskingReasoner

public void setAskingReasoner(Reasoner v)
Sets the AskingControlReasoner.

Fires a PropertyChangeEvent.

Parameters:
v - the AskingControlReasoner to be used by this context

getAskingDispatcher

public Dispatcher getAskingDispatcher()
Returns the AskingControlDispatcher. This is the dispatcher that initially receives queries from the AskingControlReasoner.

The AskingControlDispatcher is the top-level manager of all of the general-purpose and domain-specific asking Reasoners that participate in the proof of a query by proving and generating subgoals.

Use DispatcherUtils.addToDispatcher(Reasoner, Dispatcher) and DispatcherUtils.removeFromDispatcher(Reasoner, Dispatcher) to add and remove Reasoners from a Dispatcher.

Returns:
AskingControlDispatcher

setAskingDispatcher

public void setAskingDispatcher(Dispatcher v)
Sets the AskingControlDispatcher.

Fires a PropertyChangeEvent.

Parameters:
v - AskingControlDispatcher to be used by this context

getTellingReasoner

public Reasoner getTellingReasoner()
Returns the TellingControlReasoner. This is the reasoner that initially processes assertions. The TellingControlReasoner manages the search for derived consequences and provides the entry point to the TellingControlDispatcher.

Returns:
TellingControlReasoner

setTellingReasoner

public void setTellingReasoner(Reasoner v)
Sets the TellingControlReasoner.

Fires a PropertyChangeEvent.

Parameters:
v - TellingControlReasoner to be used by this context

getTellingDispatcher

public Dispatcher getTellingDispatcher()
Returns the TellingControlDispatcher. This is the dispatcher that initially receives assertions from the TellingControlReasoner.

The TellingControlDispatcher is the top-level manager of the general-purpose and domain-specific telling Reasoners that participate in the assertion of knowledge to the system by storing assertions and generating derived consequences from assertions.

Use DispatcherUtils.addToDispatcher(Reasoner, Dispatcher) and DispatcherUtils.removeFromDispatcher(Reasoner, Dispatcher) to add and remove Reasoners from a Dispatcher.

Returns:
TellingControlDispatcher

setTellingDispatcher

public void setTellingDispatcher(Dispatcher v)
Sets the TellingControlDispatcher.

Fires a PropertyChangeEvent.

Parameters:
v - TellingControlDispatcher to be used by this context

getIntermediateResultDispatcher

public Dispatcher getIntermediateResultDispatcher()

setIntermediateResultDispatcher

public void setIntermediateResultDispatcher(Dispatcher v)
Fires a PropertyChangeEvent.


getTracer

public Tracer getTracer()
Returns the tracer being used by the system.

Returns:
default Tracer

setTracer

public void setTracer(Tracer v)
Sets the tracer to be used by the system.

Fires a PropertyChangeEvent.

Parameters:
v - Tracer to be used by this reasoners that record tracing information

getUndoManager

public UndoManager getUndoManager()
Returns the Undo Manager used to store modifications to the system so that the system can be returned to previous states. Children of this context that wish to record their modifications to the system should import this property (see PropertyImporter). Telling Reasoners are most likely to use the UndoManager.

Returns:
default UndoManager
See Also:
undo(), untell(Object), UntellUndoManager, SnapshotUndoManager, PropertyImporter

setUndoManager

public void setUndoManager(UndoManager undo)
Sets the UndoManager.

Fires a PropertyChangeEvent.

Parameters:
undo - UndoManager to be used (primarily by telling reasoners)

undo

public boolean undo()
Undoes the last top-level modification made to the system. For example, calling undo() immediately after calling loadKB will result in the removal of the contents of the last loaded KB from the system.

Returns:
true if the undo was successfully performed, false otherwise

getMaxDepth

public int getMaxDepth()
Returns an integer representing both the telling and asking systems' maximum depth. In the asking system, this is the maximum depth to which subgoals will be generated in an attempt to prove a query. In the telling system, this is the maximum depth to which consequences will be inferred given the initial direct assertion.

Returns:
maximum depth of inference

setMaxDepth

public void setMaxDepth(int v)
Sets both the telling and asking systems' maximum depth.

Fires a PropertyChangeEvent.

Parameters:
v - maximum depth of inference

untell

public void untell(Object assertion)
            throws CannotUndoException,
                   ReasoningException
Attempts to untell assertion via the undo manager. After the assertion has been untold, the assertions that needed to be retold will all be wrapped in a new MultipleTellEdit, so calling undo() will perform differently after an untell than it would have before the untell. Executing SnapshotUndoManager.revertToSnapshot(Snapshot) will still work assuming the user took the Snapshot before the user originally told the assertion.

Parameters:
assertion - a previously asserted object.
CannotUndoException
ReasoningException

tell

public int tell(Object assertion)
         throws ReasoningException
A DirectAssertion with assertion as its goal is sent to the TellingControlReasoner.

Parameters:
assertion - a goal to be told. Most common goals are instances of CNFSentence
Returns:
the number of forward-chained consequences that resulted from this tell
ReasoningException

tellInternal

protected int tellInternal(DirectAssertion assertion)
                    throws ReasoningException
Helper method called by most of the public tell methods (e.g., tellString(String)). tellInternal wraps assertion and all of the resulting modifications to the system in a TellEdit.

Parameters:
assertion - the assertion to be added to the system
Returns:
the number of forward-chained consequences that resulted from this tell
ReasoningException

assertString

public int assertString(String assertion)
                 throws ReasoningException
Deprecated. Use tellString(String).

ReasoningException

tellString

public int tellString(String assertion)
               throws ReasoningException
Asserts to the telling reasoners the Clauses encoded in a String. Uses the specified parser to convert assertion into Clauses. The Clauses are then sequentially passed to the TellingControlReasoner as the goals of new DirectAssertions. The DirectAssertions and their inferred consequences are stored in the system. Note that the consequences that are inferred and stored are determined by the telling reasoners that the system has been configured to use via the TellingControlDispatcher.

Parameters:
assertion - a String that is parsed into Clauses by the FirstOrderLogicParser returned by getParser(), and the Clauses are asserted in the telling system as goals of DirectAssertions
Returns:
the number of consequences derived from telling assertion
ReasoningException

tellString

public int tellString(String assertion,
                      URL url)
               throws ReasoningException
Asserts to the telling reasoners the clauses encoded in a String.

Parameters:
assertion - a String that is parsed into Clauses by the FirstOrderLogicParser returned by getParser(), and the Clauses are asserted in the telling system as goals of DirectAssertions
url - used by the parser to resolve names of constants denoted in the String, as in RDF
Returns:
the number of consequences derived from telling assertion
ReasoningException
See Also:
tellString(String)

getStringAssertionResults

public ReasoningStepIterator getStringAssertionResults(String assertion)
                                                throws ReasoningException
Asserts to the telling reasoners the clauses encoded in a String. Uses parser to parse assertion into Clauses. The Clauses are the goals of DirectAssertions that are asserted to the TellingControlReasoner.

This method returns a ReasoningStepIterator that contains proofs for all derived consequences of the assertion. The assertion and its consequences are only asserted to the system as the returned ReasoningStepIterator is pulsed. The user must pulse through all results in the ReasoningStepIterator in order for the assertion and all its derived consequences to be asserted to the system.

Note that the consequences that are inferred and stored are determined by the telling reasoners that the system has been configured to use via the TellingControlDispatcher.

Parameters:
assertion - a String to be parsed into Clauses that are asserted in the system
Returns:
iterator over proofs of derived consequences
ReasoningException
See Also:
tellString(String)

getAssertionResults

public ReasoningStepIterator getAssertionResults(DirectAssertion assertion)
                                          throws ReasoningException
Asserts assertion to the telling reasoners. assertion is asserted to the TellingControlReasoner.

This method returns a ReasoningStepIterator that contains proofs for all derived consequences of the assertion. The assertion and its consequences are only asserted to the system as the returned ReasoningStepIterator is pulsed. The user must pulse through all results in the ReasoningStepIterator in order for the assertion and all its derived consequences to be asserted to the system.

Note that the consequences that are inferred and stored are determined by the telling reasoners that the system has been configured to use via the TellingControlDispatcher.

Parameters:
assertion - asserted in the sytem
Returns:
iterator over proofs of derived consequences
ReasoningException
See Also:
tellString(String), getStringAssertionResults(String)

ask

public ReasoningStepIterator ask(String query)
                          throws ReasoningException
Submits a query.

The query string is translated by the FirstOrderLogicTranslator returned by getTranslator() into a CNFSentence. The translator uses the specified parser to parse the string.

The query is passed to the AskingControlReasoner, and reasoners that are in the AskingDispatcher will have an opportunity to prove the query.

Parameters:
query - the query string
Returns:
a ReasoningStepIterator containing proofs (if any) of the query
ReasoningException

loadKB

public void loadKB(URL actualLocation,
                   URL publicLocation)
            throws ReasoningException,
                   IOException
Loads a KB from a URL. We open an InputStream from the URL, and feed it to the parser. Then we feed the results to the telling reasoner (the ClauseIterator that the parser returns is fed to loadClauses(ClauseIterator, URL).) The KB is assumed to be in the language of our parser. The "official" location of the KB is set to publicLocation.

ReasoningException
IOException

loadClauses

public void loadClauses(ClauseIterator cit,
                        URL publicLocation)
                 throws ReasoningException
Feeds a sequence of clauses to the telling reasoner.

Parameters:
cit - a sequence of clauses (e.g., returned by a parser.)
ReasoningException

loadKB

public void loadKB(URL url)
            throws ReasoningException,
                   IOException
Loads a KB from a URL. We open an InputStream from the URL, and feed it to the parser. Then we feed the results to the telling reasoner. The KB is assumed to be in the language of our parser.

Parameters:
url - the URL to load the KB from.
ReasoningException
IOException

defaultSetup

public void defaultSetup()
Performs a default setup for this context. This method should be called before any ask or tell methods are called.

Sets the AskingControlReasoner to an IterativeDeepening reasoner whose theorem prover is a ModelEliminationReasoner. Sets the TellingControlReasoner to a BreadthFirstForwardReasoner. Sets the AskingControlDispatcher and TellingControlDispatcher to instances of SequentialDispatcher. Sets the Parser to a KIF2CNF. Sets the Tracer to a PrintStreamTracer. Sets the UndoManager to a UntellUndoManager.


JTP API Documentation