Class RETEEngine

  • All Implemented Interfaces:
    FRuleEngineI

    public class RETEEngine
    extends java.lang.Object
    implements FRuleEngineI
    A RETE version of the forward rule system engine. 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  RETEEngine.RuleStore
      Structure used to wrap up processed rule indexes.
    • Method Summary

      All 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 addTriple​(Triple triple, boolean deduction)
      Add a new triple to the network.
      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 deleteTriple​(Triple triple, boolean deduction)
      Remove a new triple from the network.
      void fastInit​(Finder inserts)
      Process all available data.
      long getNRulesFired()
      Return the number of rules fired since this rule engine instance was created and initialized
      java.lang.Object getRuleStore()
      Access the precomputed internal rule form.
      void init​(boolean ignoreBrules, Finder inserts)
      Process all available data.
      void requestRuleFiring​(Rule rule, BindingEnvironment env, boolean isAdd)
      Add a rule firing request to the conflict set.
      void runAll()
      Process the queue of pending insert/deletes until the queues are empty.
      void setDerivationLogging​(boolean recordDerivations)
      Set to true to enable derivation caching
      void 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.
      void testTripleInsert​(Triple t)
      This fires a triple into the current RETE network.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RETEEngine

        public RETEEngine​(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
      • RETEEngine

        public RETEEngine​(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 interface FRuleEngineI
        Parameters:
        ignoreBrules - set to true if rules written in backward notation should be ignored
        inserts - 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 interface FRuleEngineI
        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 interface FRuleEngineI
      • delete

        public boolean delete​(Triple t)
        Remove one triple to the data graph.
        Specified by:
        delete in interface FRuleEngineI
        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 interface FRuleEngineI
      • 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 interface FRuleEngineI
      • setDerivationLogging

        public void setDerivationLogging​(boolean recordDerivations)
        Set to true to enable derivation caching
        Specified by:
        setDerivationLogging in interface FRuleEngineI
      • getRuleStore

        public java.lang.Object getRuleStore()
        Access the precomputed internal rule form. Used when precomputing the internal axiom closures.
        Specified by:
        getRuleStore in interface FRuleEngineI
      • setRuleStore

        public void setRuleStore​(java.lang.Object ruleStore)
        Set the internal rule from a precomputed state.
        Specified by:
        setRuleStore in interface FRuleEngineI
      • requestRuleFiring

        public void requestRuleFiring​(Rule rule,
                                      BindingEnvironment env,
                                      boolean isAdd)
        Add a rule firing request to the conflict set.
      • 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 objects
        ignoreBrules - set to true if rules written in backward notation should be ignored
      • addTriple

        public void addTriple​(Triple triple,
                              boolean deduction)
        Add a new triple to the network.
        Parameters:
        triple - the new triple
        deduction - true if the triple has been generated by the rules and so should be added to the deductions graph.
      • deleteTriple

        public void deleteTriple​(Triple triple,
                                 boolean deduction)
        Remove a new triple from the network.
        Parameters:
        triple - the new triple
        deduction - true if the remove has been generated by the rules
      • runAll

        public void runAll()
        Process the queue of pending insert/deletes until the queues are empty. Public to simplify unit tests - not normally called directly.
      • testTripleInsert

        public void testTripleInsert​(Triple t)
        This fires a triple into the current RETE network. This format of call is used in the unit testing but needs to be public because the tester is in another package.