Class LPBRuleEngine

java.lang.Object
org.apache.jena.reasoner.rulesys.impl.LPBRuleEngine

public class LPBRuleEngine extends Object
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 Details

    • CYCLES_BETWEEN_COMPLETION_CHECK

      public static final int CYCLES_BETWEEN_COMPLETION_CHECK
      The 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

      public LPBRuleEngine(BackwardRuleInfGraphI infGraph, LPRuleStore rules)
      Constructor.
      Parameters:
      infGraph - the parent inference graph which is using this engine
      rules - the indexed set of rules to process
    • LPBRuleEngine

      public LPBRuleEngine(BackwardRuleInfGraphI infGraph)
      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

      public ExtendedIterator<Triple> find(TriplePattern goal)
      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

      public void addRule(Rule rule)
      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

      public void deleteRule(Rule rule)
      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

      public List<Rule> 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

      public LPRuleStore getRuleStore()
      Return the rule store associated with the inference graph
    • getInfGraph

      public BackwardRuleInfGraphI getInfGraph()
      Return the parent inference graph associated with this engine
    • detach

      public void detach(LPInterpreter engine)
      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

      public void tablePredicate(Node predicate)
      Register an RDF predicate as one whose presence in a goal should force the goal to be tabled.
    • generatorFor

      public Generator generatorFor(TriplePattern goal, List<RuleClauseCode> clauses)
      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 same goal exists in the cache, it will be returned without considering the provided clauses.
      Parameters:
      goal - the goal whose results are to be generated
      clauses - the precomputed set of code blocks used to implement the goal
    • generatorFor

      public Generator generatorFor(TriplePattern goal)
      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

      public void schedule(LPAgendaEntry state)
      Register that a generator or specific generator state (Consumer choice point) is now ready to run.
    • pump

      public void pump(LPInterpreterContext gen)
      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

      public void incrementProfile(RuleClauseCode clause)
      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.