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
Nested ClassesModifier and TypeClassDescriptionstatic classStructure used to wrap up pre-processed/compiled rule sets.Nested classes/interfaces inherited from class org.apache.jena.reasoner.BaseInfGraph
BaseInfGraph.InfTransactionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanStatic switch from Basic to RETE implementation of the forward componentFields inherited from class org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph
filterFunctorsFields inherited from class org.apache.jena.reasoner.BaseInfGraph
reasonerInfCapabilitiesFields inherited from class org.apache.jena.graph.impl.GraphBase
TOSTRING_TRIPLE_BASE, TOSTRING_TRIPLE_LIMITFields inherited from interface org.apache.jena.graph.Graph
emptyGraph -
Constructor Summary
ConstructorsConstructorDescriptionFBRuleInfGraph(Reasoner reasoner, List<Rule> rules, Graph schema) Constructor.Constructor.FBRuleInfGraph(Reasoner reasoner, Graph schema) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanPost-filter query results to hide unwanted triples from the glare of publicity.voidAdds a new Backward rule as a result of a forward rule process.voidAdds a set of new Backward rulesvoidAdd a new deduction to the deductions graph.voidAdd a new preprocessing hook defining an operation that should be run when the preparation phase is underway.voidaddRuleDuringPrepare(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.voidclose()Free all resources, any further use of this Graph is an error.voiddeleteBRule(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.longReturn 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.voidCalled to flag that a node should be hidden from external queries.voidperformAdd(Triple t) Add one triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples.voidRemoves the triple t (if possible) from the set belonging to this graph.voidprepare()Perform any initial processing and caching.voidPrint a profile of LP rules used since the last reset.booleanprocessBuiltin(ClauseEntry clause, Rule rule, BindingEnvironment env) Process a call to a builtin predicatevoidrebind()Cause the inference graph to reconsult the underlying graph to take into account changes.voidCause the inference graph to reconsult both the underlying graph and the reasoner ruleset, permits the forward rule set to be dynamically changed.voidreset()Flush out all cached results.voidresetLPProfile(boolean enable) Reset the LP engine profile.voidsetDatatypeRangeValidation(boolean on) Switch on/off datatype range validationvoidsetDerivationLogging(boolean recordDerivations) Set to true to enable derivation cachingvoidSet a predicate to be tabled/memoized by the LP engine.voidsetTraceOn(boolean state) Set the state of the trace flag.voidInstantiate 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, silentAddMethods inherited from class org.apache.jena.reasoner.BaseInfGraph
clear, cloneWithPremises, find, getCapabilities, getGlobalProperty, getPrefixMapping, getRawGraph, getReasoner, getTransactionHandler, getVersion, isEmpty, isPrepared, remove, testGlobalPropertyMethods 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, toStringMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.jena.reasoner.rulesys.BackwardRuleInfGraphI
getVersion, logDerivationMethods 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, sizeLong, stream, streamMethods inherited from interface org.apache.jena.reasoner.InfGraph
find, getDerivation, getGlobalProperty, getRawGraph, getReasoner, rebind, testGlobalPropertyMethods 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:
findDataMatchesin interfaceForwardRuleInfGraphI- Overrides:
findDataMatchesin 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:
findDataMatchesin interfaceBackwardRuleInfGraphI
-
processBuiltin
Process a call to a builtin predicate- Specified by:
processBuiltinin 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:
addBRulein interfaceForwardRuleInfGraphI- Overrides:
addBRulein classBasicForwardRuleInfGraph
-
deleteBRule
Deletes a new Backward rule as a rules of a forward rule process. Only some infgraphs support this.- Specified by:
deleteBRulein interfaceForwardRuleInfGraphI- Overrides:
deleteBRulein 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:
addDeductionin interfaceForwardRuleInfGraphI- Overrides:
addDeductionin classBasicForwardRuleInfGraph
-
getTemp
Retrieve or create a bNode representing an inferred property value.- Specified by:
getTempin 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:
preparein interfaceInfGraph- Overrides:
preparein 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:
rebindin interfaceInfGraph- Overrides:
rebindin 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:
setTraceOnin classBasicForwardRuleInfGraph
-
setDerivationLogging
public void setDerivationLogging(boolean recordDerivations) Set to true to enable derivation caching- Specified by:
setDerivationLoggingin interfaceInfGraph- Overrides:
setDerivationLoggingin 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:
getNRulesFiredin 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:
findWithContinuationin 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:
findin 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:
resetin interfaceInfGraph- Overrides:
resetin 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:
performAddin interfaceGraphWithPerform- Overrides:
performAddin classBasicForwardRuleInfGraph
-
performDelete
Removes the triple t (if possible) from the set belonging to this graph.- Specified by:
performDeletein interfaceGraphWithPerform- Overrides:
performDeletein classBasicForwardRuleInfGraph
-
close
public void close()Free all resources, any further use of this Graph is an error.- Specified by:
closein interfaceGraph- Overrides:
closein 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:
validatein interfaceInfGraph- Overrides:
validatein 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.
-