com.hp.hpl.jena.reasoner.rulesys
Class LPBackwardRuleInfGraph

java.lang.Object
  extended by com.hp.hpl.jena.graph.impl.GraphBase
      extended by com.hp.hpl.jena.reasoner.BaseInfGraph
          extended by com.hp.hpl.jena.reasoner.rulesys.LPBackwardRuleInfGraph
All Implemented Interfaces:
Graph, GraphAdd, com.hp.hpl.jena.graph.impl.GraphWithPerform, InfGraph, BackwardRuleInfGraphI, SilentAddI

public class LPBackwardRuleInfGraph
extends BaseInfGraph
implements BackwardRuleInfGraphI

Inference graph for accessing the LP version of the backward chaining rule engine.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.hp.hpl.jena.reasoner.BaseInfGraph
BaseInfGraph.InfCapabilities, BaseInfGraph.InfFindSafeCapabilities, BaseInfGraph.InfTransactionHandler
 
Field Summary
 
Fields inherited from class com.hp.hpl.jena.graph.impl.GraphBase
TOSTRING_TRIPLE_BASE, TOSTRING_TRIPLE_LIMIT
 
Fields inherited from interface com.hp.hpl.jena.graph.Graph
emptyGraph
 
Constructor Summary
LPBackwardRuleInfGraph(Reasoner reasoner, com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleStore ruleStore, Graph data, Graph schema)
          Constructor.
 
Method Summary
 com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> find(TriplePattern pattern)
          Basic pattern lookup interface.
 com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> findDataMatches(TriplePattern pattern)
          Match a pattern just against the stored data (raw data, schema, axioms) but no derivation.
 com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation)
          Extended find interface used in situations where the implementator may or may not be able to answer the complete query.
 Iterator<Derivation> getDerivation(Triple t)
          Return the derivation of at triple.
 Graph getSchemaGraph()
          Return the schema graph, if any, bound into this inference graph.
 Node getTemp(Node instance, Node prop, Node pclass)
          Retrieve or create a bNode representing an inferred property value.
 com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> graphBaseFind(Node subject, Node property, Node object)
          Returns an iterator over Triples.
 boolean isTraceOn()
          Return true if tracing is switched on
 void logDerivation(Triple t, Derivation derivation)
          Log a dervivation record against the given triple.
 void performAdd(Triple t)
          Add one triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples.
 void performDelete(Triple t)
          Removes the triple t (if possible) from the set belonging to this graph.
 void prepare()
          Perform any initial processing and caching.
 boolean processBuiltin(ClauseEntry clause, Rule rule, BindingEnvironment env)
          Process a call to a builtin predicate
 void rebind()
          Cause the inference graph to reconsult the underlying graph to take into account changes.
 void rebind(Graph data)
          Replace the underlying data graph for this inference graph and start any inferences over again.
 void reset()
          Flush out all cached results.
 void setDerivationLogging(boolean recordDerivations)
          Set to true to enable derivation caching
 void setTabled(Node predicate)
          Set a predicate to be tabled/memoized by the LP engine.
 void setTraceOn(boolean state)
          Set the state of the trace flag.
 void silentAdd(Triple t)
          Assert a new triple in the deduction graph, bypassing any processing machinery.
 
Methods inherited from class com.hp.hpl.jena.reasoner.BaseInfGraph
clear, cloneWithPremises, close, find, getBulkUpdateHandler, getCapabilities, getDeductionsGraph, getGlobalProperty, getPrefixMapping, getRawGraph, getReasoner, getTransactionHandler, getVersion, graphBaseFind, graphBaseSize, isEmpty, isPrepared, remove, testGlobalProperty, validate
 
Methods inherited from class com.hp.hpl.jena.graph.impl.GraphBase
add, contains, contains, delete, dependsOn, find, find, forTestingOnly_graphBaseFind, getEventManager, getStatisticsHandler, isClosed, isIsomorphicWith, notifyAdd, notifyDelete, size, toString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.jena.reasoner.rulesys.BackwardRuleInfGraphI
getVersion
 
Methods inherited from interface com.hp.hpl.jena.reasoner.InfGraph
find, getDeductionsGraph, getGlobalProperty, getRawGraph, getReasoner, testGlobalProperty, validate
 
Methods inherited from interface com.hp.hpl.jena.graph.Graph
add, clear, close, contains, contains, delete, dependsOn, find, find, getBulkUpdateHandler, getCapabilities, getEventManager, getPrefixMapping, getStatisticsHandler, getTransactionHandler, isClosed, isEmpty, isIsomorphicWith, remove, size
 

Constructor Detail

LPBackwardRuleInfGraph

public LPBackwardRuleInfGraph(Reasoner reasoner,
                              com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleStore ruleStore,
                              Graph data,
                              Graph schema)
Constructor. Create a new backward inference graph to process the given data. The parent reasoner supplies the ruleset and any additional schema graph.

Parameters:
reasoner - the parent reasoner
ruleStore - the indexed set of rules to use
data - the data graph to be processed
schema - optional precached schema (use null if not required)
Method Detail

getSchemaGraph

public Graph getSchemaGraph()
Return the schema graph, if any, bound into this inference graph.

Specified by:
getSchemaGraph in class BaseInfGraph

prepare

public void prepare()
Perform any initial processing and caching. This call is optional. Most engines either have negligable set up work or will perform an implicit "prepare" if necessary. The call is provided for those occasions where substantial preparation work is possible (e.g. running a forward chaining rule system) and where an application might wish greater control over when this prepration is done.

Specified by:
prepare in interface InfGraph
Overrides:
prepare in class BaseInfGraph

rebind

public void rebind(Graph data)
Replace the underlying data graph for this inference graph and start any inferences over again. This is primarily using in setting up ontology imports processing to allow an imports multiunion graph to be inserted between the inference graph and the raw data, before processing.

Specified by:
rebind in interface InfGraph
Overrides:
rebind in class BaseInfGraph
Parameters:
data - the new raw data graph

rebind

public void rebind()
Cause the inference graph to reconsult the underlying graph to take into account changes. Normally changes are made through the InfGraph's add and remove calls are will be handled appropriately. However, in some cases changes are made "behind the InfGraph's back" and this forces a full reconsult of the changed data.

Specified by:
rebind in interface InfGraph
Overrides:
rebind in class BaseInfGraph

reset

public void reset()
Flush out all cached results. Future queries have to start from scratch.

Specified by:
reset in interface InfGraph
Overrides:
reset in class BaseInfGraph

findWithContinuation

public com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern,
                                                                                   Finder continuation)
Extended find interface used in situations where the implementator may or may not be able to answer the complete query. It will attempt to answer the pattern but if its answers are not known to be complete then it will also pass the request on to the nested Finder to append more results.

Specified by:
findWithContinuation in class BaseInfGraph
Parameters:
pattern - a TriplePattern to be matched against the data
continuation - either a Finder or a normal Graph which will be asked for additional match results if the implementor may not have completely satisfied the query.

graphBaseFind

public com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> graphBaseFind(Node subject,
                                                                            Node property,
                                                                            Node object)
Returns an iterator over Triples. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data.

Overrides:
graphBaseFind in class BaseInfGraph

find

public com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> find(TriplePattern pattern)
Basic pattern lookup interface. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data.

Overrides:
find in class BaseInfGraph
Parameters:
pattern - a TriplePattern to be matched against the data
Returns:
a ExtendedIterator over all Triples in the data set that match the pattern

performAdd

public void performAdd(Triple t)
Add one triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples.

Specified by:
performAdd in interface com.hp.hpl.jena.graph.impl.GraphWithPerform
Overrides:
performAdd in class BaseInfGraph

performDelete

public void performDelete(Triple t)
Removes the triple t (if possible) from the set belonging to this graph.

Specified by:
performDelete in interface com.hp.hpl.jena.graph.impl.GraphWithPerform
Overrides:
performDelete in class BaseInfGraph

setTabled

public void setTabled(Node predicate)
Set a predicate to be tabled/memoized by the LP engine.


setDerivationLogging

public void setDerivationLogging(boolean recordDerivations)
Set to true to enable derivation caching

Specified by:
setDerivationLogging in interface InfGraph
Overrides:
setDerivationLogging in class BaseInfGraph

getDerivation

public Iterator<Derivation> getDerivation(Triple t)
Return the derivation of at triple. The derivation is a List of DerivationRecords

Specified by:
getDerivation in interface InfGraph
Overrides:
getDerivation in class BaseInfGraph
Returns:
an iterator over Derivation records or null if there is no derivation information available for this triple.

setTraceOn

public void setTraceOn(boolean state)
Set the state of the trace flag. If set to true then rule firings are logged out to the Log at "INFO" level.


isTraceOn

public boolean isTraceOn()
Return true if tracing is switched on


logDerivation

public void logDerivation(Triple t,
                          Derivation derivation)
Log a dervivation record against the given triple.

Specified by:
logDerivation in interface BackwardRuleInfGraphI

findDataMatches

public com.hp.hpl.jena.util.iterator.ExtendedIterator<Triple> findDataMatches(TriplePattern pattern)
Match a pattern just against the stored data (raw data, schema, axioms) but no derivation.

Specified by:
findDataMatches in interface BackwardRuleInfGraphI

processBuiltin

public boolean processBuiltin(ClauseEntry clause,
                              Rule rule,
                              BindingEnvironment env)
Process a call to a builtin predicate

Specified by:
processBuiltin in interface BackwardRuleInfGraphI
Parameters:
clause - the Functor representing the call
env - the BindingEnvironment for this call
rule - the rule which is invoking this call
Returns:
true if the predicate succeeds

silentAdd

public void silentAdd(Triple t)
Assert a new triple in the deduction graph, bypassing any processing machinery.

Specified by:
silentAdd in interface SilentAddI

getTemp

public Node getTemp(Node instance,
                    Node prop,
                    Node pclass)
Retrieve or create a bNode representing an inferred property value.

Specified by:
getTemp in interface BackwardRuleInfGraphI
Parameters:
instance - the base instance node to which the property applies
prop - the property node whose value is being inferred
pclass - the (optional, can be null) class for the inferred value.
Returns:
the bNode representing the property value


Licenced under the Apache License, Version 2.0