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
public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements BackwardRuleInfGraphI
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 Classes Modifier and Type Class Description static class
FBRuleInfGraph.RuleStore
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
Fields Modifier and Type Field Description static boolean
useRETE
Static switch from Basic to RETE implementation of the forward component-
Fields 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
Constructors Constructor Description FBRuleInfGraph(Reasoner reasoner, java.util.List<Rule> rules, Graph schema)
Constructor.FBRuleInfGraph(Reasoner reasoner, java.util.List<Rule> rules, Graph schema, Graph data)
Constructor.FBRuleInfGraph(Reasoner reasoner, Graph schema)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(java.lang.Object tin)
Post-filter query results to hide unwanted triples from the glare of publicity.void
addBRule(Rule brule)
Adds a new Backward rule as a result of a forward rule process.void
addBRules(java.util.List<Rule> rules)
Adds a set of new Backward rulesvoid
addDeduction(Triple t)
Add a new deduction to the deductions graph.void
addPreprocessingHook(RulePreprocessHook hook)
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.ValidityReport.Report
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.ExtendedIterator<Triple>
find(TriplePattern pattern)
Basic pattern lookup interface.ExtendedIterator<Triple>
findDataMatches(Node subject, Node predicate, Node object)
Search the combination of data and deductions graphs for the given triple pattern.ExtendedIterator<Triple>
findDataMatches(TriplePattern pattern)
Search the combination of data and deductions graphs for the given triple pattern.ExtendedIterator<Triple>
findFull(TriplePattern pattern)
Internal variant of find which omits the filters which block illegal RDF data.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.java.util.List<Rule>
getBRules()
Return an ordered list of all registered backward rules.long
getNRulesFired()
Return the number of rules fired since this rule engine instance was created and initialized.java.util.List<Rule>
getRules()
Return the originally supplied set of rules, may be a mix of forward and backward rules.Node
getTemp(Node instance, Node prop, Node pclass)
Retrieve or create a bNode representing an inferred property value.ExtendedIterator<Triple>
graphBaseFind(Node subject, Node property, Node object)
Returns an iterator over Triples.void
hideNode(Node n)
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
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
printLPProfile()
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
rebindAll()
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
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
setUseTGCCache()
Instantiate the optional caches for the subclass/suproperty lattices.ValidityReport
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, clear, contains, contains, delete, dependsOn, find, find, find, getCapabilities, getEventManager, getPrefixMapping, getTransactionHandler, isClosed, isEmpty, isIsomorphicWith, remove, size
-
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
-
-
-
-
Constructor Detail
-
FBRuleInfGraph
public FBRuleInfGraph(Reasoner reasoner, Graph schema)
Constructor.- Parameters:
reasoner
- the reasoner which created this inf graph instanceschema
- the (optional) schema graph to be included
-
FBRuleInfGraph
public FBRuleInfGraph(Reasoner reasoner, java.util.List<Rule> rules, Graph schema)
Constructor.- Parameters:
reasoner
- the reasoner which created this inf graph instancerules
- the rules to processschema
- the (optional) schema graph to be included
-
FBRuleInfGraph
public FBRuleInfGraph(Reasoner reasoner, java.util.List<Rule> rules, Graph schema, Graph data)
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 Detail
-
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
public ExtendedIterator<Triple> findDataMatches(Node subject, Node predicate, Node object)
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
public ExtendedIterator<Triple> findDataMatches(TriplePattern pattern)
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
public boolean processBuiltin(ClauseEntry clause, Rule rule, BindingEnvironment env)
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
public void addBRule(Rule brule)
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
public void deleteBRule(Rule brule)
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
public void addBRules(java.util.List<Rule> rules)
Adds a set of new Backward rules
-
getBRules
public java.util.List<Rule> getBRules()
Return an ordered list of all registered backward rules. Includes those generated by forward productions.
-
getRules
public java.util.List<Rule> getRules()
Return the originally supplied set of rules, may be a mix of forward and backward rules.
-
setTabled
public void setTabled(Node predicate)
Set a predicate to be tabled/memoized by the LP engine.
-
addDeduction
public void addDeduction(Triple t)
Add a new deduction to the deductions graph.- Specified by:
addDeduction
in interfaceForwardRuleInfGraphI
- Overrides:
addDeduction
in classBasicForwardRuleInfGraph
-
getTemp
public Node getTemp(Node instance, Node prop, Node pclass)
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
public void addRuleDuringPrepare(Rule rule)
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
public void addPreprocessingHook(RulePreprocessHook hook)
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
public 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.- 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
public ExtendedIterator<Triple> findFull(TriplePattern pattern)
Internal variant of find which omits the filters which block illegal RDF data.- Parameters:
pattern
- a TriplePattern to be matched against the data
-
graphBaseFind
public 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.
-
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.- 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
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 classBasicForwardRuleInfGraph
-
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 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
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.- 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
public ValidityReport.Report checkLiteral(Node prop, Triple triple)
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
public void hideNode(Node n)
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
public boolean accept(java.lang.Object tin)
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.
-
-