java.lang.Object
org.apache.jena.reasoner.rulesys.impl.LPBRuleEngine
LP version of the core backward chaining engine. For each parent inference
graph (whether pure backward or hybrid) there should be one LPBRuleEngine
instance. The shared instance holds any common result caching, rule store
and global state data. However, all the processing is done by instances
of the LPInterpreter - one per query.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The number of generator cycles to wait before running a completion check. -
Constructor Summary
ConstructorDescriptionLPBRuleEngine
(BackwardRuleInfGraphI infGraph) Constructor.LPBRuleEngine
(BackwardRuleInfGraphI infGraph, LPRuleStore rules) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a single rule to the store.void
Check all known interpeter contexts to see if any are complete.void
Check that there are no currently processing queries.void
Delete all the rules.void
deleteRule
(Rule rule) Remove a single rule from the store.void
detach
(LPInterpreter engine) Detach the given engine from the list of active engines for this inf graphfind
(TriplePattern goal) Start a new interpreter running to answer a query.generatorFor
(TriplePattern goal) Return a generator for the given goal (assumes that the caller knows that the goal should be tabled).generatorFor
(TriplePattern goal, List<RuleClauseCode> clauses) Return a generator for the given goal (assumes that the caller knows that the goal should be tabled).Return an ordered list of all registered rules.boolean
Return true in derivations should be logged.Return the parent inference graph associated with this engineReturn the rule store associated with the inference graphvoid
halt()
Stop the current work.void
incrementProfile
(RuleClauseCode clause) Record a rule invocation in the profile count.boolean
Return true if traces of rule firings should be logged.void
Print a profile of rules used since the last reset.void
pump
(LPInterpreterContext gen) Run the scheduled generators until the given generator is ready to run.void
reset()
Clear all tabled results.void
resetProfile
(boolean enable) Reset the profile.void
schedule
(LPAgendaEntry state) Register that a generator or specific generator state (Consumer choice point) is now ready to run.void
setDerivationLogging
(boolean recordDerivations) Set to true to enable derivation cachingvoid
setTraceOn
(boolean state) Set the state of the trace flag.void
tablePredicate
(Node predicate) Register an RDF predicate as one whose presence in a goal should force the goal to be tabled.
-
Field Details
-
CYCLES_BETWEEN_COMPLETION_CHECK
public static final int CYCLES_BETWEEN_COMPLETION_CHECKThe number of generator cycles to wait before running a completion check. If set to 0 then checks will be done in the generator each time.- See Also:
-
-
Constructor Details
-
LPBRuleEngine
Constructor.- Parameters:
infGraph
- the parent inference graph which is using this enginerules
- the indexed set of rules to process
-
LPBRuleEngine
Constructor. Creates an empty engine to which rules must be added.- Parameters:
infGraph
- the parent inference graph which is using this engine
-
-
Method Details
-
find
Start a new interpreter running to answer a query.- Parameters:
goal
- the query to be processed- Returns:
- a closable iterator over the query results
-
reset
public void reset()Clear all tabled results. -
addRule
Add a single rule to the store. N.B. This will invalidate current partial results and the engine should be reset() before future queries. -
deleteRule
Remove a single rule from the store. N.B. This will invalidate current partial results and the engine should be reset() before future queries. -
getAllRules
Return an ordered list of all registered rules. -
deleteAllRules
public void deleteAllRules()Delete all the rules. -
halt
public void halt()Stop the current work. Forcibly stop all current query instances over this engine. -
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. -
isTraceOn
public boolean isTraceOn()Return true if traces of rule firings should be logged. -
setDerivationLogging
public void setDerivationLogging(boolean recordDerivations) Set to true to enable derivation caching -
getDerivationLogging
public boolean getDerivationLogging()Return true in derivations should be logged. -
getRuleStore
Return the rule store associated with the inference graph -
getInfGraph
Return the parent inference graph associated with this engine -
detach
Detach the given engine from the list of active engines for this inf graph -
checkSafeToUpdate
public void checkSafeToUpdate()Check that there are no currently processing queries. Could throw an exception here but often this can be caused by simply leaving an unclosed iterator. So instead we try to close the iterators and assume the rest of the context will be reset by the add call.Should be called from within a synchronized block.
-
tablePredicate
Register an RDF predicate as one whose presence in a goal should force the goal to be tabled. -
generatorFor
Return a generator for the given goal (assumes that the caller knows that the goal should be tabled). Note: If an earlier Generator for the samegoal
exists in the cache, it will be returned without considering the providedclauses
.- Parameters:
goal
- the goal whose results are to be generatedclauses
- the precomputed set of code blocks used to implement the goal
-
generatorFor
Return a generator for the given goal (assumes that the caller knows that the goal should be tabled).- Parameters:
goal
- the goal whose results are to be generated
-
schedule
Register that a generator or specific generator state (Consumer choice point) is now ready to run. -
pump
Run the scheduled generators until the given generator is ready to run. -
checkForCompletions
public void checkForCompletions()Check all known interpeter contexts to see if any are complete. -
incrementProfile
Record a rule invocation in the profile count. -
resetProfile
public void resetProfile(boolean enable) Reset the profile.- Parameters:
enable
- it true then profiling will continue with a new empty profile table, if false profiling will stop all current data lost.
-
printProfile
public void printProfile()Print a profile of rules used since the last reset.
-