java.lang.Object
org.apache.jena.graph.impl.GraphBase
org.apache.jena.reasoner.BaseInfGraph
org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph
- All Implemented Interfaces:
Graph,GraphWithPerform,InfGraph,ForwardRuleInfGraphI,SilentAddI
- Direct Known Subclasses:
FBRuleInfGraph,RETERuleInfGraph
An inference graph interface that runs a set of forward chaining
rules to conclusion on each added triple and stores the entire
result set.
This implementation has a horribly inefficient rule chainer built in. Once we have this working generalize this to an interface than can call out to a rule engine and build a real rule engine (e.g. Rete style).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.jena.reasoner.BaseInfGraph
BaseInfGraph.InfTransactionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanFlag, if true then find results will be filtered to remove functors and illegal RDFFields 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
ConstructorsConstructorDescriptionBasicForwardRuleInfGraph(Reasoner reasoner, List<Rule> rules, Graph schema) Constructor.Constructor.BasicForwardRuleInfGraph(Reasoner reasoner, Graph schema) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new Backward rule as a rules of a forward rule process.voidAdd a new deduction to the deductions graph.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.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 the Graph containing all the static deductions available so far.Return the Graph containing all the static deductions available so far.Return the derivation of at triple.longReturn the number of rules fired since this rule engine instance was created and initializedReturn the schema graph, if any, bound into this inference graph.intReturn the number of triples in the inferred graphvoidlogDerivation(Triple t, Derivation derivation) Log a dervivation record against the given triple.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.voidrebind()Cause the inference graph to reconsult the underlying graph to take into account changes.voidReplace the underlying data graph for this inference graph and start any inferences over again.voidsetDerivationLogging(boolean recordDerivations) Set to true to enable derivation cachingvoidsetFunctorFiltering(boolean param) Set to true to cause functor-valued literals to be dropped from rule output.voidsetRuleStore(Object ruleStore) Attach a compiled rule set to this inference graph.voidsetTraceOn(boolean state) Set the state of the trace flag.booleanReturn true if derivation logging is enabled.booleanReturn true if tracing should be acted on - i.e. if traceOn is true and we are past the bootstrap phase.voidAssert a new triple in the deduction graph, bypassing any processing machinery.Methods inherited from class org.apache.jena.reasoner.BaseInfGraph
clear, cloneWithPremises, find, getCapabilities, getGlobalProperty, getPrefixMapping, getRawGraph, getReasoner, getTransactionHandler, getVersion, isEmpty, isPrepared, remove, reset, testGlobalProperty, validateMethods 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.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, getGlobalProperty, getRawGraph, getReasoner, reset, testGlobalProperty, validate
-
Field Details
-
filterFunctors
public boolean filterFunctorsFlag, if true then find results will be filtered to remove functors and illegal RDF
-
-
Constructor Details
-
BasicForwardRuleInfGraph
Constructor. Creates a new inference graph to which a (compiled) rule set and a data graph can be attached. This separation of binding is useful to allow any configuration parameters (such as logging) to be set before the data is added. Note that until the data is added usingrebindthen any operations like add, remove, find will result in errors.- Parameters:
reasoner- the parent reasonerschema- the (optional) schema data which is being processed
-
BasicForwardRuleInfGraph
Constructor. Creates a new inference graph based on the given rule set. No data graph is attached at this stage. This is to allow any configuration parameters (such as logging) to be set before the data is added. Note that until the data is added usingrebindthen any operations like add, remove, find will result in errors.- Parameters:
reasoner- the parent reasonerrules- the list of rules to use this timeschema- the (optional) schema or preload data which is being processed
-
BasicForwardRuleInfGraph
Constructor. Creates a new inference graph based on the given rule set then processes the initial data graph. No precomputed deductions are loaded.- Parameters:
reasoner- the parent reasonerrules- the list of rules to use this timeschema- the (optional) schema or preload data which is being processeddata- the data graph to be processed
-
-
Method Details
-
setRuleStore
Attach a compiled rule set to this inference graph.- Parameters:
ruleStore- a compiled set of rules (i.e. the result of an FRuleEngine.compile).
-
rebind
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:
rebindin interfaceInfGraph- Overrides:
rebindin classBaseInfGraph- 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:
rebindin interfaceInfGraph- Overrides:
rebindin classBaseInfGraph
-
getSchemaGraph
Return the schema graph, if any, bound into this inference graph.- Specified by:
getSchemaGraphin classBaseInfGraph
-
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:
preparein interfaceInfGraph- Overrides:
preparein classBaseInfGraph
-
addDeduction
Add a new deduction to the deductions graph.- Specified by:
addDeductionin interfaceForwardRuleInfGraphI
-
setFunctorFiltering
public void setFunctorFiltering(boolean param) Set to true to cause functor-valued literals to be dropped from rule output. Default is true.- Specified by:
setFunctorFilteringin interfaceForwardRuleInfGraphI
-
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.- Specified by:
findWithContinuationin classBaseInfGraph- 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
Basic pattern lookup interface. This implementation assumes that the underlying findWithContinuation will have also consulted the raw data.- Overrides:
findin classBaseInfGraph- 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
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 classBaseInfGraph
-
graphBaseSize
public int graphBaseSize()Return the number of triples in the inferred graph- Overrides:
graphBaseSizein classBaseInfGraph
-
performDelete
Removes the triple t (if possible) from the set belonging to this graph.- Specified by:
performDeletein interfaceGraphWithPerform- Overrides:
performDeletein classBaseInfGraph
-
close
public void close()Free all resources, any further use of this Graph is an error.- Specified by:
closein interfaceGraph- Overrides:
closein classBaseInfGraph
-
addBRule
Adds a new Backward rule as a rules of a forward rule process. Only some infgraphs support this.- Specified by:
addBRulein interfaceForwardRuleInfGraphI
-
deleteBRule
Deletes a new Backward rule as a rules of a forward rule process. Only some infgraphs support this.- Specified by:
deleteBRulein interfaceForwardRuleInfGraphI
-
getDeductionsGraph
Return the Graph containing all the static deductions available so far. Will force a prepare.- Specified by:
getDeductionsGraphin interfaceForwardRuleInfGraphI- Specified by:
getDeductionsGraphin interfaceInfGraph- Overrides:
getDeductionsGraphin classBaseInfGraph- Returns:
- the deductions graph, if relevant for this class of inference engine or null if not.
-
getCurrentDeductionsGraph
Return the Graph containing all the static deductions available so far. Does not trigger a prepare action. Returns a SafeWrapper and so can be used for update (thus triggering listeners) but not for access to generalized triples- Specified by:
getCurrentDeductionsGraphin interfaceForwardRuleInfGraphI
-
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
-
logDerivation
Log a dervivation record against the given triple.- Specified by:
logDerivationin interfaceForwardRuleInfGraphI
-
silentAdd
Assert a new triple in the deduction graph, bypassing any processing machinery.- Specified by:
silentAddin interfaceSilentAddI
-
setDerivationLogging
public void setDerivationLogging(boolean recordDerivations) Set to true to enable derivation caching- Specified by:
setDerivationLoggingin interfaceInfGraph- Overrides:
setDerivationLoggingin classBaseInfGraph
-
shouldLogDerivations
public boolean shouldLogDerivations()Return true if derivation logging is enabled.- Specified by:
shouldLogDerivationsin interfaceForwardRuleInfGraphI
-
getDerivation
Return the derivation of at triple. The derivation is a List of DerivationRecords- Specified by:
getDerivationin interfaceInfGraph- Overrides:
getDerivationin classBaseInfGraph- 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. -
shouldTrace
public boolean shouldTrace()Return true if tracing should be acted on - i.e. if traceOn is true and we are past the bootstrap phase.- Specified by:
shouldTracein interfaceForwardRuleInfGraphI
-
getNRulesFired
public long getNRulesFired()Return the number of rules fired since this rule engine instance was created and initialized
-