Package org.apache.jena.reasoner.rulesys
Class FBRuleInfGraph
java.lang.Object
org.apache.jena.graph.impl.GraphBase
org.apache.jena.reasoner.BaseInfGraph
org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph
org.apache.jena.reasoner.rulesys.FBRuleInfGraph
- All Implemented Interfaces:
Graph
,GraphWithPerform
,InfGraph
,BackwardRuleInfGraphI
,ForwardRuleInfGraphI
,SilentAddI
- Direct Known Subclasses:
RDFSRuleInfGraph
An inference graph that uses a mixture of forward and backward
chaining rules. The forward rules can create direct deductions from
the source data and schema and can also create backward rules. A
query is answered by consulting the union of the raw data, the forward
derived results and any relevant backward rules (whose answers are tabled
for future reference).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Structure used to wrap up pre-processed/compiled rule sets.Nested classes/interfaces inherited from class org.apache.jena.reasoner.BaseInfGraph
BaseInfGraph.InfCapabilities, BaseInfGraph.InfFindSafeCapabilities, BaseInfGraph.InfTransactionHandler
-
Field Summary
Modifier and TypeFieldDescriptionstatic boolean
Static switch from Basic to RETE implementation of the forward componentFields inherited from class org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph
filterFunctors
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
ConstructorDescriptionFBRuleInfGraph
(Reasoner reasoner, List<Rule> rules, Graph schema) Constructor.Constructor.FBRuleInfGraph
(Reasoner reasoner, Graph schema) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Post-filter query results to hide unwanted triples from the glare of publicity.void
Adds a new Backward rule as a result of a forward rule process.void
Adds a set of new Backward rulesvoid
Add a new deduction to the deductions graph.void
Add a new preprocessing hook defining an operation that should be run when the preparation phase is underway.void
addRuleDuringPrepare
(Rule rule) Add a new rule to the rule set.checkLiteral
(Node prop, Triple triple) Check a given literal value for a property against the set of known range constraints for it.void
close()
Free all resources, any further use of this Graph is an error.void
deleteBRule
(Rule brule) Deletes a new Backward rule as a rules of a forward rule process.find
(TriplePattern pattern) Basic pattern lookup interface.findDataMatches
(Node subject, Node predicate, Node object) Search the combination of data and deductions graphs for the given triple pattern.findDataMatches
(TriplePattern pattern) Search the combination of data and deductions graphs for the given triple pattern.findFull
(TriplePattern pattern) Internal variant of find which omits the filters which block illegal RDF data.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.Return an ordered list of all registered backward rules.long
Return the number of rules fired since this rule engine instance was created and initialized.getRules()
Return the originally supplied set of rules, may be a mix of forward and backward rules.Retrieve or create a bNode representing an inferred property value.graphBaseFind
(Node subject, Node property, Node object) Returns an iterator over Triples.void
Called to flag that a node should be hidden from external queries.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
Removes the triple t (if possible) from the set belonging to this graph.void
prepare()
Perform any initial processing and caching.void
Print a profile of LP rules used since the last reset.boolean
processBuiltin
(ClauseEntry clause, Rule rule, BindingEnvironment env) Process a call to a builtin predicatevoid
rebind()
Cause the inference graph to reconsult the underlying graph to take into account changes.void
Cause the inference graph to reconsult both the underlying graph and the reasoner ruleset, permits the forward rule set to be dynamically changed.void
reset()
Flush out all cached results.void
resetLPProfile
(boolean enable) Reset the LP engine profile.void
setDatatypeRangeValidation
(boolean on) Switch on/off datatype range validationvoid
setDerivationLogging
(boolean recordDerivations) Set to true to enable derivation cachingvoid
Set a predicate to be tabled/memoized by the LP engine.void
setTraceOn
(boolean state) Set the state of the trace flag.void
Instantiate the optional caches for the subclass/suproperty lattices.validate()
Test the consistency of the bound data.Methods inherited from class org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph
getCurrentDeductionsGraph, getDeductionsGraph, getDerivation, getSchemaGraph, graphBaseSize, logDerivation, rebind, setFunctorFiltering, setRuleStore, shouldLogDerivations, shouldTrace, silentAdd
Methods inherited from class org.apache.jena.reasoner.BaseInfGraph
clear, cloneWithPremises, find, getCapabilities, getGlobalProperty, getPrefixMapping, getRawGraph, getReasoner, getTransactionHandler, getVersion, isEmpty, isPrepared, remove, testGlobalProperty
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
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.jena.reasoner.rulesys.BackwardRuleInfGraphI
getVersion, logDerivation
Methods inherited from interface org.apache.jena.graph.Graph
add, add, clear, contains, contains, delete, delete, dependsOn, find, find, find, getCapabilities, getEventManager, getPrefixMapping, getTransactionHandler, isClosed, isEmpty, isIsomorphicWith, remove, size, stream, stream
Methods inherited from interface org.apache.jena.reasoner.InfGraph
find, getDerivation, getGlobalProperty, getRawGraph, getReasoner, rebind, testGlobalProperty
Methods inherited from interface org.apache.jena.reasoner.rulesys.SilentAddI
silentAdd
-
Field Details
-
useRETE
public static boolean useRETEStatic switch from Basic to RETE implementation of the forward component
-
-
Constructor Details
-
FBRuleInfGraph
Constructor.- Parameters:
reasoner
- the reasoner which created this inf graph instanceschema
- the (optional) schema graph to be included
-
FBRuleInfGraph
Constructor.- Parameters:
reasoner
- the reasoner which created this inf graph instancerules
- the rules to processschema
- the (optional) schema graph to be included
-
FBRuleInfGraph
Constructor.- Parameters:
reasoner
- the reasoner which created this inf graph instancerules
- the rules to processschema
- the (optional) schema graph to be includeddata
- the data graph to be processed
-
-
Method Details
-
setUseTGCCache
public void setUseTGCCache()Instantiate the optional caches for the subclass/suproperty lattices. Unless this call is made the TGC caching will not be used. -
findDataMatches
Search the combination of data and deductions graphs for the given triple pattern. This may different from the normal find operation in the base of hybrid reasoners where we are side-stepping the backward deduction step.- Specified by:
findDataMatches
in interfaceForwardRuleInfGraphI
- Overrides:
findDataMatches
in classBasicForwardRuleInfGraph
-
findDataMatches
Search the combination of data and deductions graphs for the given triple pattern. This may different from the normal find operation in the base of hybrid reasoners where we are side-stepping the backward deduction step.- Specified by:
findDataMatches
in interfaceBackwardRuleInfGraphI
-
processBuiltin
Process a call to a builtin predicate- Specified by:
processBuiltin
in interfaceBackwardRuleInfGraphI
- Parameters:
clause
- the Functor representing the callenv
- the BindingEnvironment for this callrule
- the rule which is invoking this call- Returns:
- true if the predicate succeeds
-
addBRule
Adds a new Backward rule as a result of a forward rule process. Only some infgraphs support this.- Specified by:
addBRule
in interfaceForwardRuleInfGraphI
- Overrides:
addBRule
in classBasicForwardRuleInfGraph
-
deleteBRule
Deletes a new Backward rule as a rules of a forward rule process. Only some infgraphs support this.- Specified by:
deleteBRule
in interfaceForwardRuleInfGraphI
- Overrides:
deleteBRule
in classBasicForwardRuleInfGraph
-
addBRules
Adds a set of new Backward rules -
getBRules
Return an ordered list of all registered backward rules. Includes those generated by forward productions. -
getRules
Return the originally supplied set of rules, may be a mix of forward and backward rules. -
setTabled
Set a predicate to be tabled/memoized by the LP engine. -
addDeduction
Add a new deduction to the deductions graph.- Specified by:
addDeduction
in interfaceForwardRuleInfGraphI
- Overrides:
addDeduction
in classBasicForwardRuleInfGraph
-
getTemp
Retrieve or create a bNode representing an inferred property value.- Specified by:
getTemp
in interfaceBackwardRuleInfGraphI
- Parameters:
instance
- the base instance node to which the property appliesprop
- the property node whose value is being inferredpclass
- the (optional, can be null) class for the inferred value.- Returns:
- the bNode representing the property value
-
addRuleDuringPrepare
Add a new rule to the rule set. This should only be used by implementations of RuleProprocessHook (which are called during rule system preparation phase). If called at other times the rule won't be correctly transferred into the underlying engines. -
addPreprocessingHook
Add a new preprocessing hook defining an operation that should be run when the preparation phase is underway. -
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 preparation is done.- Specified by:
prepare
in interfaceInfGraph
- Overrides:
prepare
in classBasicForwardRuleInfGraph
-
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 interfaceInfGraph
- Overrides:
rebind
in classBasicForwardRuleInfGraph
-
rebindAll
public void rebindAll()Cause the inference graph to reconsult both the underlying graph and the reasoner ruleset, permits the forward rule set to be dynamically changed. Causes the entire rule engine to be rebuilt from the current ruleset and reinitialized against the current data. Not needed for normal cases. -
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.- Overrides:
setTraceOn
in classBasicForwardRuleInfGraph
-
setDerivationLogging
public void setDerivationLogging(boolean recordDerivations) Set to true to enable derivation caching- Specified by:
setDerivationLogging
in interfaceInfGraph
- Overrides:
setDerivationLogging
in classBasicForwardRuleInfGraph
-
getNRulesFired
public long getNRulesFired()Return the number of rules fired since this rule engine instance was created and initialized. The current implementation only counts forward rules and does not track dynamic backward rules needed for specific queries.- Overrides:
getNRulesFired
in classBasicForwardRuleInfGraph
-
findWithContinuation
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.- Overrides:
findWithContinuation
in classBasicForwardRuleInfGraph
- 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.
-
findFull
Internal variant of find which omits the filters which block illegal RDF data.- Parameters:
pattern
- a TriplePattern to be matched against the data
-
graphBaseFind
Returns an iterator over Triples. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data. -
find
Basic pattern lookup interface. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data.- Overrides:
find
in classBasicForwardRuleInfGraph
- Parameters:
pattern
- a TriplePattern to be matched against the data- Returns:
- a ExtendedIterator over all Triples in the data set that match the pattern
-
reset
public void reset()Flush out all cached results. Future queries have to start from scratch.- Specified by:
reset
in interfaceInfGraph
- Overrides:
reset
in classBaseInfGraph
-
performAdd
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 classBasicForwardRuleInfGraph
-
performDelete
Removes the triple t (if possible) from the set belonging to this graph.- Specified by:
performDelete
in interfaceGraphWithPerform
- Overrides:
performDelete
in classBasicForwardRuleInfGraph
-
close
public void close()Free all resources, any further use of this Graph is an error.- Specified by:
close
in interfaceGraph
- Overrides:
close
in classBasicForwardRuleInfGraph
-
validate
Test the consistency of the bound data. This normally tests the validity of the bound instance data against the bound schema data.- Specified by:
validate
in interfaceInfGraph
- Overrides:
validate
in classBaseInfGraph
- Returns:
- a ValidityReport structure
-
setDatatypeRangeValidation
public void setDatatypeRangeValidation(boolean on) Switch on/off datatype range validation -
checkLiteral
Check a given literal value for a property against the set of known range constraints for it.- Parameters:
prop
- the property node whose range is under scrutinytriple
- the statement whose object value is to be checked.- Returns:
- null if the range is legal, otherwise a ValidityReport.Report which describes the problem.
-
hideNode
Called to flag that a node should be hidden from external queries. -
resetLPProfile
public void resetLPProfile(boolean enable) Reset the LP engine profile.- Parameters:
enable
- it true then profiling will continue with a new empty profile table, if false profiling will stop all current data lost.
-
printLPProfile
public void printLPProfile()Print a profile of LP rules used since the last reset. -
accept
Post-filter query results to hide unwanted triples from the glare of publicity. Unwanted triples are triples with Functor literals and triples with hidden nodes as subject or object.
-