Class FRuleEngine
- java.lang.Object
-
- org.apache.jena.reasoner.rulesys.impl.FRuleEngine
-
- All Implemented Interfaces:
FRuleEngineI
public class FRuleEngine extends java.lang.Object implements FRuleEngineI
The processing engine for forward production rules. It needs to reference an enclosing ForwardInfGraphI which holds the raw data and deductions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FRuleEngine.RuleStore
Structure used to wrap up processed rule indexes.
-
Constructor Summary
Constructors Constructor Description FRuleEngine(ForwardRuleInfGraphI parent)
Constructor.FRuleEngine(ForwardRuleInfGraphI parent, java.util.List<Rule> rules)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Triple t)
Add one triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples.void
addSet(BFRuleContext context)
Add a set of new triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples.void
compile(java.util.List<Rule> rules, boolean ignoreBrules)
Compile a list of rules into the internal rule store representation.boolean
delete(Triple t)
Remove one triple to the data graph.void
fastInit(Finder inserts)
Process all available data.long
getNRulesFired()
Return the number of rules fired since this rule engine instance was created and initializedjava.lang.Object
getRuleStore()
Access the precomputed internal rule form.void
init(boolean ignoreBrules, Finder inserts)
Process all available data.static boolean
match(Node pattern, Node node, BindingStack env)
Test if a pattern Node matches a Triple Node in the given binding environment.static boolean
match(TriplePattern pattern, Triple triple, BindingStack env)
Test if a TriplePattern matches a Triple in the given binding environment.static int
scoreNodeBoundness(Node n, BindingEnvironment env)
Score a Node in terms of groundedness - heuristic.void
setDerivationLogging(boolean recordDerivations)
Set to true to enable derivation cachingvoid
setRuleStore(java.lang.Object ruleStore)
Set the internal rule from a precomputed state.boolean
shouldTrace()
Return true if the internal engine state means that tracing is worthwhile.
-
-
-
Constructor Detail
-
FRuleEngine
public FRuleEngine(ForwardRuleInfGraphI parent, java.util.List<Rule> rules)
Constructor.- Parameters:
parent
- the F or FB infGraph that it using this engine, the parent graph holds the deductions graph and source data.rules
- the rule set to be processed
-
FRuleEngine
public FRuleEngine(ForwardRuleInfGraphI parent)
Constructor. Build an empty engine to which rules must be added using setRuleStore().- Parameters:
parent
- the F or FB infGraph that it using this engine, the parent graph holds the deductions graph and source data.
-
-
Method Detail
-
init
public void init(boolean ignoreBrules, Finder inserts)
Process all available data. This should be called once a deductions graph has be prepared and loaded with any precomputed deductions. It will process the rule axioms and all relevant existing exiting data entries.- Specified by:
init
in interfaceFRuleEngineI
- Parameters:
ignoreBrules
- set to true if rules written in backward notation should be ignoredinserts
- the set of triples to be processed, normally this is the raw data graph but may include additional deductions made by preprocessing hooks
-
fastInit
public void fastInit(Finder inserts)
Process all available data. This version expects that all the axioms have already be preprocessed and the clause index already exists.- Specified by:
fastInit
in interfaceFRuleEngineI
- Parameters:
inserts
- the set of triples to be processed, normally this is the raw data graph but may include additional deductions made by preprocessing hooks
-
add
public void add(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:
add
in interfaceFRuleEngineI
-
delete
public boolean delete(Triple t)
Remove one triple to the data graph.- Specified by:
delete
in interfaceFRuleEngineI
- Returns:
- true if the effects could be correctly propagated or false if not (in which case the entire engine should be restarted).
-
getNRulesFired
public long getNRulesFired()
Return the number of rules fired since this rule engine instance was created and initialized- Specified by:
getNRulesFired
in interfaceFRuleEngineI
-
shouldTrace
public boolean shouldTrace()
Return true if the internal engine state means that tracing is worthwhile. It will return false during the axiom bootstrap phase.- Specified by:
shouldTrace
in interfaceFRuleEngineI
-
setDerivationLogging
public void setDerivationLogging(boolean recordDerivations)
Set to true to enable derivation caching- Specified by:
setDerivationLogging
in interfaceFRuleEngineI
-
getRuleStore
public java.lang.Object getRuleStore()
Access the precomputed internal rule form. Used when precomputing the internal axiom closures.- Specified by:
getRuleStore
in interfaceFRuleEngineI
-
setRuleStore
public void setRuleStore(java.lang.Object ruleStore)
Set the internal rule from a precomputed state.- Specified by:
setRuleStore
in interfaceFRuleEngineI
-
addSet
public void addSet(BFRuleContext context)
Add a set of new triple to the data graph, run any rules triggered by the new data item, recursively adding any generated triples. Technically the triples having been physically added to either the base or deduction graphs and the job of this function is just to process the stack of additions firing any relevant rules.- Parameters:
context
- a context containing a set of new triples to be added
-
compile
public void compile(java.util.List<Rule> rules, boolean ignoreBrules)
Compile a list of rules into the internal rule store representation.- Parameters:
rules
- the list of Rule objectsignoreBrules
- set to true if rules written in backward notation should be ignored
-
scoreNodeBoundness
public static int scoreNodeBoundness(Node n, BindingEnvironment env)
Score a Node in terms of groundedness - heuristic. Treats a variable as better than a wildcard because it constrains later clauses. Treats rdf:type as worse than any other ground node because that tends to link to lots of expensive rules.
-
match
public static boolean match(TriplePattern pattern, Triple triple, BindingStack env)
Test if a TriplePattern matches a Triple in the given binding environment. If it does then the binding environment is modified the reflect any additional bindings.- Returns:
- true if the pattern matches the triple
-
match
public static boolean match(Node pattern, Node node, BindingStack env)
Test if a pattern Node matches a Triple Node in the given binding environment. If it does then the binding environment is modified the reflect any additional bindings.- Returns:
- true if the pattern matches the node
-
-