JTP API Documentation

jtp.context.rdf
Class RDFReasoningContext

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

public class RDFReasoningContext
extends Context

See Also:
Serialized Form

Field Summary
protected  IterativeDeepening idr
           
static String RDF_REF
           
static URL RDF_RULES
           
static URL RDF_TRIPLES
           
 
Fields inherited from class jtp.frame.listen.Context
ONE_VALUE, TRIPLE, VALUE_LINK, VC
 
Fields inherited from class jtp.context.BasicReasoningContext
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
RDFReasoningContext()
           
 
Method Summary
 ReasoningStepIterator ask(String query)
          Submits a KIF-formatted query.
 ReasoningStepIterator ask(URL premise, String query)
          Premise is loaded with loadKB(URL), and query is then passed to ask(String).
 int assertKifString(String assertion)
          Deprecated. Use tellKifString(String).
 int assertString(String assertion)
          Deprecated. Use tellString(String).
 KIF2CNF getKifParser()
           
 com.hp.hpl.jena.rdf.model.Model getModelForAssertions(Snapshot snap)
           
 jtp.fol.rdf.RDFParser getRDFParser()
           
 ReasoningStepIterator inconsistencies()
           
 void loadKB(URL url)
          Loads KBs with an RDF parser.
 void loadKB(URL url, FirstOrderLogicParser p)
          Loads KBs with the specified parser.
 void loadKB(URL url, URL publicLocation, FirstOrderLogicParser p)
          Loads KBs with the specified parser.
 void loadKifKB(URL url)
          Loads url with a KIF parser.
 void loadRDFKB(com.hp.hpl.jena.rdf.model.Model model, URL publicLocation)
          Loads a KB stored in a Jena model.
 void loadRDFKB(URL url, URL publicLocation)
          Loads content of RDF KBs.
 void setMaxDepth(int m)
          Sets both the telling and asking systems' maximum depth.
 void setUp()
           
 int tell(Object assertion)
          Processes the assertion (without parsing it as in tellString(String)) as well as forward-chained information.
 int tellKifString(String assertion)
          Stores the assertion as well as its forward-chained information.
 int tellString(String assertion)
          Stores the triples represented in a RDF-formatted string as well as forward-chained information.
 int tellString(String assertion, FirstOrderLogicParser parser)
          Stores the triples represented in the string as well as forward-chained information.
 int tellString(String assertion, URL location)
          Stores the triples represented in a RDF-formatted string as well as forward-chained information.
 int tellString(String assertion, URL location, FirstOrderLogicParser parser)
          Stores the assertion as well as its forward-chained information.
 void untell(Object assertion)
          Attempts to untell assertion via the undo manager.
 void untellString(String assertion)
           
 void writeRDF(Writer writer, Snapshot snap, String baseUri, Map prefixes)
          A method for writing a portion of JTP's KB in RDF/XML format.
 
Methods inherited from class jtp.frame.listen.Context
addLink, addListener, addRule, addRule, createContentHolders, createEmptyContentHolders, getDamlParser, getFrameKB, loadSpecs, loadSpecs, orderLiterals, setFrameKB
 
Methods inherited from class jtp.context.BasicReasoningContext
defaultSetup, getAskingDispatcher, getAskingReasoner, getAssertionResults, getIntermediateResultDispatcher, getMaxDepth, getParser, getStringAssertionResults, getTellingDispatcher, getTellingReasoner, getTracer, getTranslator, getUndoManager, loadClauses, loadKB, setAskingDispatcher, setAskingReasoner, setIntermediateResultDispatcher, setParser, setTellingDispatcher, setTellingReasoner, setTracer, setUndoManager, tellInternal, undo
 
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

RDF_RULES

public static final URL RDF_RULES

RDF_TRIPLES

public static final URL RDF_TRIPLES

RDF_REF

public static final String RDF_REF
See Also:
Constant Field Values

idr

protected IterativeDeepening idr
Constructor Detail

RDFReasoningContext

public RDFReasoningContext()
Method Detail

getRDFParser

public jtp.fol.rdf.RDFParser getRDFParser()

getKifParser

public KIF2CNF getKifParser()
Overrides:
getKifParser in class Context

setMaxDepth

public void setMaxDepth(int m)
Description copied from class: BasicReasoningContext
Sets both the telling and asking systems' maximum depth.

Fires a PropertyChangeEvent.

Overrides:
setMaxDepth in class BasicReasoningContext
Parameters:
m - maximum depth of inference

setUp

public void setUp()
Overrides:
setUp in class Context

assertKifString

public int assertKifString(String assertion)
                    throws ReasoningException
Deprecated. Use tellKifString(String).

ReasoningException

tellKifString

public int tellKifString(String assertion)
                  throws ReasoningException
Stores the assertion as well as its forward-chained information.

Parameters:
assertion - a KIF-formatted string to assert.
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException

assertString

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

Overrides:
assertString in class BasicReasoningContext
ReasoningException

tellString

public int tellString(String assertion)
               throws ReasoningException
Stores the triples represented in a RDF-formatted string as well as forward-chained information.

Overrides:
tellString in class BasicReasoningContext
Parameters:
assertion - a RDF-formatted string. The string must be enclosed by <rdf:RDF> </rdf:RDF> tags.
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException

tellString

public int tellString(String assertion,
                      URL location)
               throws ReasoningException
Stores the triples represented in a RDF-formatted string as well as forward-chained information.

Overrides:
tellString in class BasicReasoningContext
Parameters:
assertion - a RDF-formatted string. The string must be enclosed by <rdf:RDF> </rdf:RDF> tags.
location - a URL that should be used to resolve namespaces
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException
See Also:
BasicReasoningContext.tellString(String)

tellString

public int tellString(String assertion,
                      FirstOrderLogicParser parser)
               throws ReasoningException
Stores the triples represented in the string as well as forward-chained information. parser is used to parse the string into CNFSentences.

Parameters:
assertion - a string to assert
parser - a parser that can parse assertion
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException

tellString

public int tellString(String assertion,
                      URL location,
                      FirstOrderLogicParser parser)
               throws ReasoningException
Stores the assertion as well as its forward-chained information.

Parameters:
assertion - a string to assert.
location - a URL that should be used to resolve namespaces
parser - a parser that can parse assertion
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException

tell

public int tell(Object assertion)
         throws ReasoningException
Processes the assertion (without parsing it as in tellString(String)) as well as forward-chained information.

Overrides:
tell in class BasicReasoningContext
Parameters:
assertion - an Object that can be handled by some telling reasoner, e.g., Literal
Returns:
an int indicating the number of forward-chained assertions that resulted from this tell
ReasoningException

loadKB

public void loadKB(URL url,
                   URL publicLocation,
                   FirstOrderLogicParser p)
            throws ReasoningException,
                   IOException
Loads KBs with the specified parser. All triples in the KB will be asserted as well as forward-chained information.

Parameters:
url - a URL that points to a KB
publicLocation - if the language that you are using relies on the base URI of the document to determine the fully-qualified names of objects in the document, this url will be used as the base URI
p - a Parser that can parse the KB's format
ReasoningException
IOException

loadKB

public void loadKB(URL url,
                   FirstOrderLogicParser p)
            throws ReasoningException,
                   IOException
Loads KBs with the specified parser. All triples in the KB will be asserted as well as forward-chained information.

Parameters:
url - a URL that points to a KB
p - a Parser that can parse the KB's format
ReasoningException
IOException

loadRDFKB

public void loadRDFKB(URL url,
                      URL publicLocation)
               throws ReasoningException,
                      IOException
Loads content of RDF KBs. All triples in the KB will be asserted as well as forward-chained information. The publicLocation will be used as the base URL for all relative elements.

Parameters:
url - a URL that points to a KB in RDF format
publicLocation - if the language that you are using relies on the base URI of the document to determine the fully-qualified names of objects in the document, this url will be used as the base URI
ReasoningException
IOException

loadRDFKB

public void loadRDFKB(com.hp.hpl.jena.rdf.model.Model model,
                      URL publicLocation)
               throws ReasoningException,
                      IOException
Loads a KB stored in a Jena model.

Parameters:
model - the model to load.
ReasoningException
IOException

loadKB

public void loadKB(URL url)
            throws ReasoningException,
                   IOException
Loads KBs with an RDF parser. All triples in the KB will be asserted as well as forward-chained information.

Overrides:
loadKB in class BasicReasoningContext
Parameters:
url - a URL that points to a KB in RDF format
ReasoningException
IOException

loadKifKB

public void loadKifKB(URL url)
               throws ReasoningException,
                      IOException
Loads url with a KIF parser.

ReasoningException
IOException

ask

public ReasoningStepIterator ask(URL premise,
                                 String query)
                          throws ReasoningException,
                                 IOException
Premise is loaded with loadKB(URL), and query is then passed to ask(String).

Parameters:
premise - a RDF KB containing data to be asserted.
query - a KIF-formatted query string.
Returns:
a ReasoningStepIterator that contains results of asking query
ReasoningException
IOException
See Also:
ask(String)

ask

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

The query must be a conjunction or disjunction of positive literals. The literals should usually be triples. The query may contain variables. An answer will be returned if bindings can be found for all variables in the query. Here are some examples:

 (|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type ?x |http://www.daml.org/2001/03/daml+oil-ex#|::|Person|)

 (and (|http://www.w3.org/2000/01/rdf-schema#|::|subClassOf| |http://www.daml.org/2001/03/daml+oil-ex#|::|MarriedPerson| ?restr) 
      (|http://www.daml.org/2001/03/daml+oil#|::|onProperty| ?restr ?prop))
 
 (or (|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type ?x |http://www.daml.org/2001/03/daml+oil-ex#|::|TallThing|) 
     (|http://www.w3.org/1999/02/22-rdf-syntax-ns#|::type ?x |http://www.daml.org/2001/03/daml+oil-ex#|::|Person|))
 

Note that the non-variables in the query are symbols of the form package::name. Symbol names will be downcased unless they are escaped as above. Queries can contain integers, floats, and strings.

If you wish to use a variable for the relation (property) in a literal, then you should use the holds construct. E.g.,

 (holds ?prop |http://www.daml.org/2001/03/daml+oil-ex#|::|HumanBeing| |http://www.daml.org/2001/03/daml+oil-ex#|::|Person|)
 

Bindings for variables can only be constants in the knowledge base. Here is an example of a provable query which will fail in the DamlReasoningContext because a binding cannot be provided for the variable. Note that an abbreviated syntax is used for this example. If the KB contains only these statements:

 (rdfs:subClassOf Person Restr_00)
 (daml:onProperty Restr_00 father)
 (daml:cardinality Restr_00 1)
 (rdf:type Fred Person)
 
and the query is:
 (father Fred ?x)
 
An answer will not be returned even though it is provable from the KB that Fred has a father because there is no constant to which ?x can be bound.

Overrides:
ask in class BasicReasoningContext
Parameters:
query - the query string
Returns:
a ReasoningStepIterator containing proofs (if any) of the query
ReasoningException

untellString

public void untellString(String assertion)
                  throws CannotUndoException,
                         ReasoningException
CannotUndoException
ReasoningException

untell

public void untell(Object assertion)
            throws ReasoningException
Description copied from class: BasicReasoningContext
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 BasicReasoningContext.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.

Overrides:
untell in class BasicReasoningContext
Parameters:
assertion - a previously asserted object.
ReasoningException

writeRDF

public void writeRDF(Writer writer,
                     Snapshot snap,
                     String baseUri,
                     Map prefixes)
A method for writing a portion of JTP's KB in RDF/XML format. Only the portion of the KB that was asserted after snap will be written. The KB will be written in the RDF/XML-ABBREV supported by Jena/ARP.

Parameters:
writer - a Writer to which the RDF file will be written
snap - a snapshot of the KB taken at some previous point
baseUri - the base URI for relative URI calculations. Note: There should probably not be a '#' on the end.
prefixes - a map in which the keys are prefixes and the values are namespaces. Both prefixes and namespaces should be Strings. Unfortunately, there's not a way to specify a default namespace; an empty string as a prefix causes unexpected results. Map can be null. Note: There probably should be '#' characters on the end of the namespaces.

getModelForAssertions

public com.hp.hpl.jena.rdf.model.Model getModelForAssertions(Snapshot snap)
Parameters:
snap - a snapshot of the KB taken at some previous point
Returns:
a Model containing all triples that were asserted after the snapshot was taken.

inconsistencies

public ReasoningStepIterator inconsistencies()

JTP API Documentation