Package org.apache.jena.reasoner
Class BaseInfGraph
- java.lang.Object
-
- org.apache.jena.graph.impl.GraphBase
-
- org.apache.jena.reasoner.BaseInfGraph
-
- All Implemented Interfaces:
Graph
,GraphWithPerform
,InfGraph
- Direct Known Subclasses:
BasicForwardRuleInfGraph
,LPBackwardRuleInfGraph
,TransitiveInfGraph
public abstract class BaseInfGraph extends GraphBase implements InfGraph
A base level implementation of the InfGraph interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseInfGraph.InfCapabilities
An InfCapabilities notes that size may not be accurate.static class
BaseInfGraph.InfFindSafeCapabilities
An InfCapabilities notes that size may not be accurate.static class
BaseInfGraph.InfTransactionHandler
-
Field Summary
-
Fields inherited from class org.apache.jena.graph.impl.GraphBase
TOSTRING_TRIPLE_BASE, TOSTRING_TRIPLE_LIMIT
-
Fields inherited from interface org.apache.jena.graph.Graph
emptyGraph
-
-
Constructor Summary
Constructors Constructor Description BaseInfGraph(Graph data, Reasoner reasoner)
Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
clear()
Remove all the statements from this graph.InfGraph
cloneWithPremises(Graph premises)
Return a new inference graph which is a clone of the current graph together with an additional set of data premises.void
close()
Free all resources, any further use of this Graph is an error.ExtendedIterator<Triple>
find(Node subject, Node property, Node object, Graph param)
An extension of the Graph.find interface which allows the caller to encode complex expressions in RDF and then refer to those expressions within the query triple.ExtendedIterator<Triple>
find(TriplePattern pattern)
Basic pattern lookup interface.abstract 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.Capabilities
getCapabilities()
Answer the InfCapabilities of this InfGraph.Graph
getDeductionsGraph()
Returns a derivations graph.java.util.Iterator<Derivation>
getDerivation(Triple triple)
Return the derivation of the given triple (which is the result of some previous find operation).Node
getGlobalProperty(Node property)
Test a global boolean property of the graph.PrefixMapping
getPrefixMapping()
Inference graphs share the prefix-mapping of their underlying raw graph.Graph
getRawGraph()
Return the raw RDF data Graph being processed (i.e.Reasoner
getReasoner()
Return the Reasoner which is being used to answer queries to this graph.abstract Graph
getSchemaGraph()
Return the schema graph, if any, bound into this inference graph.TransactionHandler
getTransactionHandler()
Answer a transaction handler bound to this graph.int
getVersion()
Return a version stamp for this graph which can be used to fast-fail concurrent modification exceptions.int
graphBaseSize()
Return the number of triples in the just the base graphboolean
isEmpty()
Answer true iff this graph is empty.boolean
isPrepared()
Answer true iff this graph has been through theprepare()
step.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.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
remove(Node s, Node p, Node o)
Remove all triples that match by find(s, p, o)void
reset()
Reset any internal caches.void
setDerivationLogging(boolean logOn)
Switch on/off drivation loggingboolean
testGlobalProperty(Node property)
A convenience version of getGlobalProperty which can only return a boolean result.ValidityReport
validate()
Test the consistency of the bound data.-
Methods inherited from class org.apache.jena.graph.impl.GraphBase
add, contains, contains, delete, dependsOn, find, find, forTestingOnly_graphBaseFind, getEventManager, isClosed, isIsomorphicWith, notifyAdd, notifyDelete, size, toString, toString
-
-
-
-
Method Detail
-
getPrefixMapping
public PrefixMapping getPrefixMapping()
Inference graphs share the prefix-mapping of their underlying raw graph.- Specified by:
getPrefixMapping
in interfaceGraph
- Overrides:
getPrefixMapping
in classGraphBase
- See Also:
Graph.getPrefixMapping()
-
getCapabilities
public Capabilities getCapabilities()
Answer the InfCapabilities of this InfGraph.- Specified by:
getCapabilities
in interfaceGraph
- Overrides:
getCapabilities
in classGraphBase
-
remove
public void remove(Node s, Node p, Node o)
Description copied from class:GraphBase
Remove all triples that match by find(s, p, o)
-
clear
public void clear()
Description copied from class:GraphBase
Remove all the statements from this graph.
-
getTransactionHandler
public TransactionHandler getTransactionHandler()
Description copied from class:GraphBase
Answer a transaction handler bound to this graph. The default is SimpleTransactionHandler, which handles no transactions.- Specified by:
getTransactionHandler
in interfaceGraph
- Overrides:
getTransactionHandler
in classGraphBase
-
getRawGraph
public Graph getRawGraph()
Return the raw RDF data Graph being processed (i.e. the argument to the Reasonder.bind call that created this InfGraph).- Specified by:
getRawGraph
in interfaceInfGraph
-
getReasoner
public Reasoner getReasoner()
Return the Reasoner which is being used to answer queries to this graph.- Specified by:
getReasoner
in interfaceInfGraph
-
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.
-
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.
-
reset
public void reset()
Reset any internal caches. Some systems, such as the tabled backchainer, retain information after each query. A reset will wipe this information preventing unbounded memory use at the expense of more expensive future queries. A reset does not cause the raw data to be reconsulted and so is less expensive than a rebind.
-
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.
-
getDeductionsGraph
public Graph getDeductionsGraph()
Returns a derivations graph. The rule reasoners typically create a graph containing those triples added to the base graph due to rule firings. In some applications it can useful to be able to access those deductions directly, without seeing the raw data which triggered them. In particular, this allows the forward rules to be used as if they were rewrite transformation rules.- Specified by:
getDeductionsGraph
in interfaceInfGraph
- Returns:
- the deductions graph, if relevant for this class of inference engine or null if not.
-
getGlobalProperty
public Node getGlobalProperty(Node property)
Test a global boolean property of the graph. This might included properties like consistency, OWLSyntacticValidity etc. It remains to be seen what level of generality is needed here. We could replace this by a small number of specific tests for common concepts.- Specified by:
getGlobalProperty
in interfaceInfGraph
- Parameters:
property
- the URI of the property to be tested- Returns:
- a Node giving the value of the global property, this may be a boolean literal, some other literal value (e.g. a size).
-
testGlobalProperty
public boolean testGlobalProperty(Node property)
A convenience version of getGlobalProperty which can only return a boolean result.- Specified by:
testGlobalProperty
in interfaceInfGraph
-
validate
public ValidityReport validate()
Test the consistency of the bound data. This normally tests the validity of the bound instance data against the bound schema data.
-
find
public ExtendedIterator<Triple> find(Node subject, Node property, Node object, Graph param)
An extension of the Graph.find interface which allows the caller to encode complex expressions in RDF and then refer to those expressions within the query triple. For example, one might encode a class expression and then ask if there are any instances of this class expression in the InfGraph.- Specified by:
find
in interfaceInfGraph
- Parameters:
subject
- the subject Node of the query triple, may be a Node in the graph or a node in the parameter micro-graph or nullproperty
- the property to be retrieved or nullobject
- the object Node of the query triple, may be a Node in the graph or a node in the parameter micro-graph.param
- a small graph encoding an expression which the subject and/or object nodes refer.
-
findWithContinuation
public abstract 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.- Parameters:
pattern
- a TriplePattern to be matched against the datacontinuation
- 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.
-
find
public ExtendedIterator<Triple> find(TriplePattern pattern)
Basic pattern lookup interface. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data.- Parameters:
pattern
- a TriplePattern to be matched against the data- Returns:
- a ExtendedIterator over all Triples in the data set that match the pattern
-
setDerivationLogging
public void setDerivationLogging(boolean logOn)
Switch on/off drivation logging- Specified by:
setDerivationLogging
in interfaceInfGraph
-
getDerivation
public java.util.Iterator<Derivation> getDerivation(Triple triple)
Return the derivation of the given triple (which is the result of some previous find operation). Not all reasoneers will support derivations.- Specified by:
getDerivation
in interfaceInfGraph
- Returns:
- an iterator over Derivation records or null if there is no derivation information available for this triple.
-
graphBaseSize
public int graphBaseSize()
Return the number of triples in the just the base graph
-
isEmpty
public boolean isEmpty()
Answer true iff this graph is empty. [Used to be in QueryHandler, but moved in here because it's a more primitive operation.]
-
close
public void close()
Free all resources, any further use of this Graph is an error.
-
getVersion
public int getVersion()
Return a version stamp for this graph which can be used to fast-fail concurrent modification exceptions.
-
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 interfaceGraphWithPerform
- Overrides:
performAdd
in classGraphBase
-
performDelete
public void performDelete(Triple t)
Removes the triple t (if possible) from the set belonging to this graph.- Specified by:
performDelete
in interfaceGraphWithPerform
- Overrides:
performDelete
in classGraphBase
-
getSchemaGraph
public abstract Graph getSchemaGraph()
Return the schema graph, if any, bound into this inference graph.
-
cloneWithPremises
public InfGraph cloneWithPremises(Graph premises)
Return a new inference graph which is a clone of the current graph together with an additional set of data premises. The default implementation loses ALL partial deductions so far. Some subclasses may be able to a more efficient job.
-
isPrepared
public boolean isPrepared()
Answer true iff this graph has been through theprepare()
step. For testing purposes.- Returns:
- Whether the graph is prepared
-
-