Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-679

Use an alternative implementation of a FRuleEngineI

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: Jena 2.11.1
    • Fix Version/s: Jena 2.11.2
    • Component/s: Reasoners
    • Labels:

      Description

      Give the possibility to use an alternative FRuleEngineI implementation.
      My proposition is to introduce a singleton factory FRuleEngineIFactory.

      com.hp.hpl.jena.reasoner.rulesys.impl.FRuleEngineIFactory.java
      public class FRuleEngineIFactory {
          private static FRuleEngineIFactory instance = new FRuleEngineIFactory();
          public static void setInstance(FRuleEngineIFactory instance) { FRuleEngineIFactory.instance = instance; }
          public FRuleEngineIFactory getInstance() { return instance; }
          
          public FRuleEngineI createFRuleEngineI(ForwardRuleInfGraphI parent, List<Rule> rules, boolean useRETE) {
              FRuleEngineI engine;
              if (rules != null) {
                  if (useRETE) {
                      engine = new RETEEngine(parent, rules);
                  } else {
                      engine = new FRuleEngine(parent, rules);
                  }
              } else {
                  if (useRETE) {
                      engine = new RETEEngine(parent);
                  } else {
                      engine = new FRuleEngine(parent);
                  }
              }
              return engine;
          }
      }
      

      This factory will be used by existing classes.

      com.hp.hpl.jena.reasoner.rulesys.BasicForwardRuleInfGraph
          
      @Override
      protected void instantiateRuleEngine(List<Rule> rules) {
          engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(this, rules, false);
      }
      
      com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph
      @Override
      protected void instantiateRuleEngine(List<Rule> rules) {
          engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(this, rules, useRETE);
      }
      
      com.hp.hpl.jena.reasoner.rulesys.RETERuleInfGraph
          
      @Override
      protected void instantiateRuleEngine(List<Rule> rules) {
          engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(this, rules, true);
      }
      

      And i could replace the factory instance by my own instance :

      FRuleEngineIFactory.setInstance(new CustomFRuleEngineIFactory());
      

      I will propose a patch soon.

        Attachments

        1. JENA-679.patch
          16 kB
          Sébastien Boulet

          Activity

            People

            • Assignee:
              der Dave Reynolds
              Reporter:
              gontard Sébastien Boulet
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: