You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by de...@apache.org on 2016/07/17 11:26:43 UTC

[1/3] jena git commit: [JENA-1204] support for multiple BuiltinRegistry for different rule sets

Repository: jena
Updated Branches:
  refs/heads/master b6ee59d06 -> b722e943c


[JENA-1204] support for multiple BuiltinRegistry for different rule sets


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/60f4a0a0
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/60f4a0a0
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/60f4a0a0

Branch: refs/heads/master
Commit: 60f4a0a0f22b25e2ed167f3a4625d037c0d82c2c
Parents: dea868f
Author: Paul Houle <pa...@ontology2.com>
Authored: Wed Jul 6 09:56:04 2016 -0400
Committer: Paul Houle <pa...@ontology2.com>
Committed: Wed Jul 6 09:56:04 2016 -0400

----------------------------------------------------------------------
 .../apache/jena/reasoner/rulesys/Builtin.java   |  2 +-
 .../jena/reasoner/rulesys/BuiltinRegistry.java  | 88 +++++++-------------
 .../jena/reasoner/rulesys/FBRuleReasoner.java   |  2 +-
 .../apache/jena/reasoner/rulesys/Functor.java   | 57 +++++++++----
 .../reasoner/rulesys/MapBuiltinRegistry.java    | 69 +++++++++++++++
 .../rulesys/OverrideBuiltinRegistry.java        | 61 ++++++++++++++
 .../org/apache/jena/reasoner/rulesys/Rule.java  | 72 ++++++++++++----
 .../reasoner/rulesys/impl/BindingStack.java     |  2 +-
 .../reasoner/rulesys/impl/BindingVector.java    |  2 +-
 .../jena/reasoner/rulesys/test/TestBugs.java    |  4 +-
 .../test/TestGenericRuleReasonerConfig.java     | 46 ++++++++++
 11 files changed, 309 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Builtin.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Builtin.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Builtin.java
index eea2590..592f519 100755
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Builtin.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Builtin.java
@@ -31,7 +31,7 @@ import org.apache.jena.graph.* ;
  * <p>
  * The mapping from the rule definition (which uses functors to hold the parsed call)
  * to the java implementation of the builtin is done via the 
- * {@link BuiltinRegistry BuiltinRegistry} which can
+ * {@link MapBuiltinRegistry BuiltinRegistry} which can
  * be user extended.
  */
 public interface Builtin {

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BuiltinRegistry.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BuiltinRegistry.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BuiltinRegistry.java
index d37b574..b6ed580 100755
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BuiltinRegistry.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BuiltinRegistry.java
@@ -1,3 +1,7 @@
+package org.apache.jena.reasoner.rulesys;
+
+import org.apache.jena.reasoner.rulesys.builtins.*;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -16,35 +20,11 @@
  * limitations under the License.
  */
 
-package org.apache.jena.reasoner.rulesys;
-
-import java.util.*;
-
-import org.apache.jena.reasoner.rulesys.builtins.* ;
-
-/** * A registry for mapping functor names on java objects (instances 
- * of subclasses of Builtin) which implement their behvaiour.
- * <p>
- * This is currently implemented as a singleton to simply any future
- * move to support different sets of builtins.
- * 
- * @see Builtin
- */
-public class BuiltinRegistry {
-
-    /** The single global static registry */
+public abstract class BuiltinRegistry {
+    /** The default base registry */
     public static BuiltinRegistry theRegistry;
-    
-    /** Mapping from functor name to Builtin implementing it */
-    protected Map<String,Builtin> builtins = new HashMap<>();
-    
-    /** Mapping from URI of builtin to implementation */
-    protected Map<String,Builtin> builtinsByURI = new HashMap<>();
-    
-    // Static initilizer for the singleton instance
     static {
-        theRegistry = new BuiltinRegistry();
-        
+        theRegistry=new MapBuiltinRegistry();
         theRegistry.register(new Print());
         theRegistry.register(new AddOne());
         theRegistry.register(new LessThan());
@@ -82,66 +62,54 @@ public class BuiltinRegistry {
         theRegistry.register(new ListNotContains());
         theRegistry.register(new ListMapAsSubject());
         theRegistry.register(new ListMapAsObject());
-        
+
         theRegistry.register(new MakeInstance());
         theRegistry.register(new Table());
         theRegistry.register(new TableAll());
-        
+
         theRegistry.register(new MakeSkolem());
-        
+
         theRegistry.register(new Hide());
-        
+
         theRegistry.register(new StrConcat());
         theRegistry.register(new UriConcat());
         theRegistry.register(new Regex());
-        
+
         theRegistry.register(new Now());
-        
+
         // Special purposes support functions for OWL
         theRegistry.register(new AssertDisjointPairs());
+
     }
-    
+
     /**
-     * Construct an empty registry
+     * Register an implementation for a given builtin using its default name.
+     * @param impl the implementation of the builtin
      */
-    public BuiltinRegistry() {
-    }
-    
+
+    public abstract void register(Builtin impl);
     /**
      * Register an implementation for a given builtin functor.
      * @param functor the name of the functor used to invoke the builtin
      * @param impl the implementation of the builtin
      */
-    public void register(String functor, Builtin impl) {
-        builtins.put(functor, impl);
-        builtinsByURI.put(impl.getURI(), impl);
-    }
-   
-    /**
-     * Register an implementation for a given builtin using its default name.
-     * @param impl the implementation of the builtin
-     */
-    public void register(Builtin impl) {
-        builtins.put(impl.getName(), impl);
-        builtinsByURI.put(impl.getURI(), impl);
-    }
-    
+
+    public abstract void register(String functor, Builtin impl);
     /**
      * Find the implementation of the given builtin functor.
      * @param functor the name of the functor being invoked.
      * @return a Builtin or null if there is none registered under that name
      */
-    public Builtin getImplementation(String functor) {
-        return builtins.get(functor);
-    }
-    
+
+    public abstract Builtin getImplementation(String functor);
+
     /**
      * Find the implementation of the given builtin functor.
      * @param uri the URI of the builtin to be retrieved
      * @return a Builtin or null if there is none registered under that name
      */
-    public Builtin getImplementationByURI(String uri) {
-        return builtinsByURI.get(uri);
-    }
-    
+
+    public abstract Builtin getImplementationByURI(String uri);
+
+
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleReasoner.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleReasoner.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleReasoner.java
index 1f067c8..51ac06f 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleReasoner.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleReasoner.java
@@ -280,7 +280,7 @@ public class FBRuleReasoner implements RuleReasoner {
         // Create a dummy rule which tables the predicate ...
         Rule tablePredicateRule = new Rule("", 
                 new ClauseEntry[]{
-                    new Functor("table", new Node[] { predicate })
+                    new Functor("table", new Node[] { predicate },BuiltinRegistry.theRegistry)
                 }, 
                 new ClauseEntry[]{});
         // ... end append the rule to the ruleset

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Functor.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Functor.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Functor.java
index 2eb22e5..ee0ea90 100755
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Functor.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Functor.java
@@ -54,17 +54,7 @@ public class Functor implements ClauseEntry {
             };
     
     protected static Logger logger = LoggerFactory.getLogger(Functor.class);
-    
-    /**
-     * Constructor. 
-     * @param name the name of the functor
-     * @param args a list of nodes defining the arguments
-     */
-    public Functor(String name, List<Node> args) {
-        this.name = name;
-        this.args = args.toArray(new Node[]{});
-    }
-    
+
     /**
      * Constructor. 
      * @param name the name of the functor
@@ -80,13 +70,48 @@ public class Functor implements ClauseEntry {
      * Constructor
      * @param name the name of the functor
      * @param args a list of nodes defining the arguments
-     * @param registry a table of builtins to consult to check for 
+     * @param registry a table of builtins to consult to check for
      * implementations of this functor when used as a rule clause
      */
     public Functor(String name, List<Node> args, BuiltinRegistry registry) {
+        this(name, args,registry.getImplementation(name));
+    }
+
+    /**
+     * Constructor
+     * @param name the name of the functor
+     * @param args an array of nodes defining the arguments
+     * @param registry a table of builtins to consult to check for
+     * implementations of this functor when used as a rule clause
+     */
+    public Functor(String name,Node[] args, BuiltinRegistry registry) {
+        this(name, args,registry.getImplementation(name));
+    }
+
+    /**
+     * Constructor
+     * @param name the name of the functor
+     * @param args a list of nodes defining the arguments
+     * @param impl a specific builtin implementation of this functor
+     *
+     */
+    public Functor(String name, List<Node> args, Builtin impl) {
         this.name = name;
         this.args = args.toArray(new Node[]{});
-        this.implementor = registry.getImplementation(name);
+        this.implementor = impl;
+    }
+
+    /**
+     * Constructor
+     * @param name the name of the functor
+     * @param args a list of nodes defining the arguments
+     * @param impl a specific builtin implementation of this functor
+     *
+     */
+    public Functor(String name, Node[] args, Builtin impl) {
+        this.name = name;
+        this.args = args;
+        this.implementor = impl;
     }
     
     /**
@@ -262,7 +287,7 @@ public class Functor implements ClauseEntry {
         }
         return false;
     }
-    
+
     /**
      * Create a functor and wrap it up as a Literal node
      * @param name the name of the functor
@@ -270,9 +295,9 @@ public class Functor implements ClauseEntry {
      * accidental structure sharing
      */
     public static Node makeFunctorNode(String name, Node[] args) {
-        return makeFunctorNode( new Functor( name, args ) );
+        return makeFunctorNode( new Functor( name, args, BuiltinRegistry.theRegistry ) );
     }
-    
+
     /**
      * Wrap  a functor as a Literal node
      * @param f the functor data structure to be wrapped in a node.

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
new file mode 100644
index 0000000..fd542ad
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.reasoner.rulesys;
+
+import java.util.*;
+
+import org.apache.jena.reasoner.rulesys.builtins.* ;
+
+/** * A registry for mapping functor names on java objects (instances 
+ * of subclasses of Builtin) which implement their behvaiour.
+ * <p>
+ * This is currently implemented as a singleton to simply any future
+ * move to support different sets of builtins.
+ * 
+ * @see Builtin
+ */
+public class MapBuiltinRegistry extends BuiltinRegistry {
+
+    /** Mapping from functor name to Builtin implementing it */
+    protected Map<String,Builtin> builtins = new HashMap<>();
+    
+    /** Mapping from URI of builtin to implementation */
+    protected Map<String,Builtin> builtinsByURI = new HashMap<>();
+
+    /**
+     * Construct an empty registry
+     */
+    public MapBuiltinRegistry() {
+    }
+
+    @Override
+    public void register(String functor, Builtin impl) {
+        builtins.put(functor, impl);
+        builtinsByURI.put(impl.getURI(), impl);
+    }
+
+    @Override
+    public void register(Builtin impl) {
+        builtins.put(impl.getName(), impl);
+        builtinsByURI.put(impl.getURI(), impl);
+    }
+    
+    @Override
+    public Builtin getImplementation(String functor) {
+        return builtins.get(functor);
+    }
+    
+    @Override
+    public Builtin getImplementationByURI(String uri) {
+        return builtinsByURI.get(uri);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/OverrideBuiltinRegistry.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/OverrideBuiltinRegistry.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/OverrideBuiltinRegistry.java
new file mode 100644
index 0000000..e8e39f0
--- /dev/null
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/OverrideBuiltinRegistry.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.reasoner.rulesys;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OverrideBuiltinRegistry extends BuiltinRegistry {
+
+    /** Mapping from functor name to Builtin implementing it */
+    final protected Map<String,Builtin> builtins = new HashMap<>();
+
+    /** Mapping from URI of builtin to implementation */
+    final protected Map<String,Builtin> builtinsByURI = new HashMap<>();
+
+    final protected BuiltinRegistry innerRegistry;
+
+    public OverrideBuiltinRegistry(BuiltinRegistry innerRegistry) {
+        this.innerRegistry = innerRegistry;
+    }
+
+    @Override
+    public void register(String functor, Builtin impl) {
+        builtins.put(functor, impl);
+        builtinsByURI.put(impl.getURI(), impl);
+    }
+
+    @Override
+    public void register(Builtin impl) {
+        builtins.put(impl.getName(), impl);
+        builtinsByURI.put(impl.getURI(), impl);
+    }
+
+    @Override
+    public Builtin getImplementation(String functor) {
+        Builtin that=builtins.get(functor);
+        return that==null ? innerRegistry.getImplementation(functor) : that;
+    }
+
+    @Override
+    public Builtin getImplementationByURI(String uri) {
+        Builtin that=builtinsByURI.get(uri);
+        return that==null ? innerRegistry.getImplementationByURI(uri) : that;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Rule.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Rule.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Rule.java
index c0ad540..d38b6fb 100755
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Rule.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/Rule.java
@@ -158,7 +158,7 @@ public class Rule implements ClauseEntry {
                 else
                 {
                     throw new ReasonerException(
-                        "Undefined Functor " + ( (Functor) elt ).getName() + " in " + toShortString() );
+                            "(allMonotonic) Undefined Functor " + ( (Functor) elt ).getName() + " in " + toShortString() );
                 }
             }
         }
@@ -376,7 +376,7 @@ public class Rule implements ClauseEntry {
         for (int i = 0; i < args.length; i++) {
             cargs[i] = cloneNode(args[i], vmap, env);
         }
-        Functor fn = new Functor(f.getName(), cargs);
+        Functor fn = new Functor(f.getName(), cargs, f.getImplementor());
         fn.setImplementor(f.getImplementor());
         return fn;
     }
@@ -482,19 +482,31 @@ public class Rule implements ClauseEntry {
 // parser access
 
     /**
-     * Parse a string as a rule.
+     * Parse a string as a rule,  using the default BuiltinRegistry to resolve functor names
+     *
      * @throws ParserException if there is a problem
      */
     public static Rule parseRule(String source) throws ParserException {
-        Parser parser = new Parser(source);
+        return parseRule(source,BuiltinRegistry.theRegistry);
+    }
+
+    /**
+     * Parse a string as a rule using a specified BuiltinRegistry to resolve functor names
+     *
+     * @param source the source string for the rule
+     * @param registry the BuiltinRegistry used to resolve functor names
+     * @throws ParserException if there is a problem
+     */
+    public static Rule parseRule(String source,BuiltinRegistry registry) throws ParserException {
+        Parser parser = new Parser(source,registry);
         return parser.parseRule();
     }
-    
+
     /**
      * Answer the list of rules parsed from the given URL.
      * @throws RulesetNotFoundException
      */
-    public static List<Rule> rulesFromURL( String uri ) {
+    public static List<Rule> rulesFromURL( String uri,BuiltinRegistry registry) {
         BufferedReader br = null;
         try {
             InputStream in = FileManager.get().open(uri);
@@ -505,6 +517,14 @@ public class Rule implements ClauseEntry {
             if (br != null) try { br.close(); } catch (IOException e2) {}
         }
     }
+
+    /**
+     * Answer the list of rules parsed from the given URL.
+     * @throws RulesetNotFoundException
+     */
+    public static List<Rule> rulesFromURL( String uri) {
+        return rulesFromURL(uri,BuiltinRegistry.theRegistry);
+    }
         
     /**
      * Processes the source reader stripping off comment lines and noting prefix
@@ -512,7 +532,7 @@ public class Rule implements ClauseEntry {
      * Returns a parser which is bound to the stripped source text with 
      * associated prefix and rule inclusion definitions.
     */
-    public static Parser rulesParserFromReader( BufferedReader src ) {
+    public static Parser rulesParserFromReader( BufferedReader src, BuiltinRegistry registry ) {
        try {
            StringBuilder result = new StringBuilder();
            String line;
@@ -557,7 +577,7 @@ public class Rule implements ClauseEntry {
                    result.append("\n");
                }
            }
-           Parser parser = new Parser(result.toString());
+           Parser parser = new Parser(result.toString(),registry);
            parser.registerPrefixMap(prefixes);
            parser.addRulesPreload(preloadedRules);
            return parser;
@@ -566,6 +586,16 @@ public class Rule implements ClauseEntry {
            { throw new WrappedIOException( e ); }
    }
 
+    /**
+     * Processes the source reader stripping off comment lines and noting prefix
+     * definitions (@prefix) and rule inclusion commands (@include).
+     * Returns a parser which is bound to the stripped source text with
+     * associated prefix and rule inclusion definitions.
+     */
+    public static Parser rulesParserFromReader( BufferedReader src) {
+       return rulesParserFromReader(src,BuiltinRegistry.theRegistry);
+    }
+
     /** 
      * Helper function find a URI argument in the current string,
      * optionally surrounded by matching <>.
@@ -644,8 +674,17 @@ public class Rule implements ClauseEntry {
      * @return a list of rules
      * @throws ParserException if there is a problem
      */
+    public static List<Rule> parseRules(String source,BuiltinRegistry registry) throws ParserException {
+        return parseRules(new Parser(source,registry));
+    }
+
+    /**
+     * Parse a string as a list a rules.
+     * @return a list of rules
+     * @throws ParserException if there is a problem
+     */
     public static List<Rule> parseRules(String source) throws ParserException {
-        return parseRules(new Parser(source));
+        return parseRules(source,BuiltinRegistry.theRegistry);
     }
     
 
@@ -658,13 +697,17 @@ public class Rule implements ClauseEntry {
      * No embedded spaces supported.
      */
     public static class Parser {
-        
+
+
         /** Tokenizer */
         private Tokenizer stream;
         
         /** Look ahead, null if none */
         private String lookahead;
-        
+
+        // registry for builtin name lookup
+        private final BuiltinRegistry registry;
+
         // Literal parse state flags
         private static final int NORMAL = 0;
         private static final int STARTED_LITERAL = 1;
@@ -691,9 +734,10 @@ public class Rule implements ClauseEntry {
          * Constructor
          * @param source the string to be parsed
          */
-        Parser(String source) {
+        Parser(String source,BuiltinRegistry registry) {
             stream = new Tokenizer(source, "()[], \t\n\r", "'\"", true);
             lookahead = null;
+            this.registry=registry;
         }
         
         /**
@@ -859,7 +903,7 @@ public class Rule implements ClauseEntry {
                 }
                 return NodeFactory.createURI(exp);
             } else if (peekToken().equals("(")) {
-                Functor f = new Functor(token, parseNodeList(), BuiltinRegistry.theRegistry);
+                Functor f = new Functor(token, parseNodeList(), registry);
                 return Functor.makeFunctorNode( f );
             } else if (token.equals("'") || token.equals("\"")) {
                 // A plain literal
@@ -968,7 +1012,7 @@ public class Rule implements ClauseEntry {
             } else {
                 String name = nextToken();
                 List<Node> args = parseNodeList();
-                Functor clause = new Functor(name, args, BuiltinRegistry.theRegistry);
+                Functor clause = new Functor(name, args, registry);
                 if (clause.getImplementor() == null) {
                     // Not a.error error becase later processing can add this
                     // implementation to the registry

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingStack.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingStack.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingStack.java
index d4e883f..03fae6a 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingStack.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingStack.java
@@ -137,7 +137,7 @@ public class BindingStack implements BindingEnvironment {
                 }
                 boundargs.add( binding );
             }
-            Functor newf = new Functor(functor.getName(), boundargs);
+            Functor newf = new Functor(functor.getName(), boundargs, functor.getImplementor());
             return Functor.makeFunctorNode( newf );
         } else {
             return node;

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingVector.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingVector.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingVector.java
index 70a20d1..eaca73e 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingVector.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BindingVector.java
@@ -98,7 +98,7 @@ public class BindingVector implements BindingEnvironment {
                 }
                 boundargs.add( binding );
             }
-            Functor newf = new Functor( functor.getName(), boundargs );
+            Functor newf = new Functor( functor.getName(), boundargs, functor.getImplementor() );
             return Functor.makeFunctorNode( newf );
         } else {
             return node;

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
index dd14c03..5194f85 100644
--- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
+++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
@@ -635,7 +635,7 @@ public class TestBugs extends TestCase {
      */
     public void testGroundClosure2() {
         Flag myFlag = new Flag();
-        BuiltinRegistry.theRegistry.register(myFlag);
+        MapBuiltinRegistry.theRegistry.register(myFlag);
         List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules");
         GenericRuleReasoner reasoner = new GenericRuleReasoner( rules );
         InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
@@ -792,7 +792,7 @@ public class TestBugs extends TestCase {
         assertEquals( culprit, ResourceFactory.createTypedLiteral( new Integer(42) ));
         culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo').  (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X).");
         assertEquals( culprit, ResourceFactory.createPlainLiteral("foo"));
-        BuiltinRegistry.theRegistry.register( new SomeTriple() );
+        MapBuiltinRegistry.theRegistry.register( new SomeTriple() );
         culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42).  (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X).");
         assertTrue( culprit.isLiteral() );
         Object val = ((Literal)culprit).getValue();

http://git-wip-us.apache.org/repos/asf/jena/blob/60f4a0a0/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java
index 75e5841..2c96559 100644
--- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java
+++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestGenericRuleReasonerConfig.java
@@ -21,10 +21,17 @@ package org.apache.jena.reasoner.rulesys.test;
 import java.util.*;
 
 import org.apache.jena.assembler.test.AssemblerTestBase ;
+import org.apache.jena.graph.Node;
 import org.apache.jena.rdf.model.* ;
+import org.apache.jena.reasoner.Reasoner;
 import org.apache.jena.reasoner.rulesys.* ;
+import org.apache.jena.reasoner.rulesys.builtins.BaseBuiltin;
+import org.apache.jena.vocabulary.RDF;
 import org.apache.jena.vocabulary.ReasonerVocabulary ;
 
+import static org.apache.jena.reasoner.rulesys.Rule.parseRule;
+
+
 /**
     Your eyes will bleed with the number of backslashes required in the substitute
     strings.
@@ -121,4 +128,43 @@ public class TestGenericRuleReasonerConfig extends AssemblerTestBase
         rules.addAll( Rule.rulesFromURL( whereB ) );
         return rules;
         }
+
+    public void testRuleLoadingWithOverridenBuiltins() {
+        List<Node> savedNode=new ArrayList<>();
+        Builtin b= new BaseBuiltin() {
+            @Override
+            public String getName() {
+                return "groo";
+            }
+
+            @Override
+            public int getArgLength() {
+                return 1;
+            }
+
+            @Override
+            public void headAction(Node[] args, int length, RuleContext context) {
+                savedNode.add(getArg(0,args,context));
+            }
+
+
+        };
+        BuiltinRegistry r=new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry);
+        r.register(b);
+        assertEquals(b,r.getImplementation("groo"));
+        List<Rule> rules=new ArrayList<>();
+        //
+        // note that the head action does not appear to fire unless we put a triple in the head as well..  is
+        // this expected?
+        //
+        rules.add(parseRule("[ (?instance rdf:type ?type) -> groo(?type) ]",r));
+        GenericRuleReasoner article=new GenericRuleReasoner(rules);
+        article.setMode(GenericRuleReasoner.FORWARD_RETE);
+        Model input=ModelFactory.createDefaultModel();
+        input.add(input.createResource(), RDF.type,input.createResource("http://example.com/Renegade"));
+        InfModel output=ModelFactory.createInfModel(article,input);
+        output.size(); // not optional, inferences are not run if we don't trigger them
+        assertEquals(1,savedNode.size());
+        assertEquals("http://example.com/Renegade",savedNode.get(0).getURI());
     }
+}


[3/3] jena git commit: This closes #150

Posted by de...@apache.org.
This closes #150


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/b722e943
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/b722e943
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/b722e943

Branch: refs/heads/master
Commit: b722e943c4b93a4496d3ba38f54cef60c7f291df
Parents: 1dfc105
Author: der <da...@epimorphics.com>
Authored: Sun Jul 17 12:25:13 2016 +0100
Committer: der <da...@epimorphics.com>
Committed: Sun Jul 17 12:25:13 2016 +0100

----------------------------------------------------------------------
 .../reasoner/rulesys/GenericRuleReasoner.java   | 22 ++++++++++++++------
 .../reasoner/rulesys/MapBuiltinRegistry.java    |  5 ++---
 .../jena/reasoner/rulesys/test/TestBugs.java    |  4 ++--
 3 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/b722e943/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/GenericRuleReasoner.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/GenericRuleReasoner.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/GenericRuleReasoner.java
index 7bb8fc3..14db6f2 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/GenericRuleReasoner.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/GenericRuleReasoner.java
@@ -18,13 +18,23 @@
 
 package org.apache.jena.reasoner.rulesys;
 
-import java.util.*;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 
-import org.apache.jena.graph.* ;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.reasoner.* ;
-import org.apache.jena.reasoner.rulesys.impl.* ;
-import org.apache.jena.vocabulary.* ;
+import org.apache.jena.graph.Factory;
+import org.apache.jena.graph.Graph;
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.Statement;
+import org.apache.jena.reasoner.IllegalParameterException;
+import org.apache.jena.reasoner.InfGraph;
+import org.apache.jena.reasoner.Reasoner;
+import org.apache.jena.reasoner.ReasonerException;
+import org.apache.jena.reasoner.ReasonerFactory;
+import org.apache.jena.reasoner.rulesys.impl.LPRuleStore;
+import org.apache.jena.reasoner.rulesys.impl.OWLRuleTranslationHook;
+import org.apache.jena.vocabulary.ReasonerVocabulary;
 
 /**
  * A reasoner interface that is able to invoke any of the useful

http://git-wip-us.apache.org/repos/asf/jena/blob/b722e943/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
index fd542ad..46b7db8 100644
--- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
+++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/MapBuiltinRegistry.java
@@ -18,9 +18,8 @@
 
 package org.apache.jena.reasoner.rulesys;
 
-import java.util.*;
-
-import org.apache.jena.reasoner.rulesys.builtins.* ;
+import java.util.HashMap;
+import java.util.Map;
 
 /** * A registry for mapping functor names on java objects (instances 
  * of subclasses of Builtin) which implement their behvaiour.

http://git-wip-us.apache.org/repos/asf/jena/blob/b722e943/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
index 5194f85..dd14c03 100644
--- a/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
+++ b/jena-core/src/test/java/org/apache/jena/reasoner/rulesys/test/TestBugs.java
@@ -635,7 +635,7 @@ public class TestBugs extends TestCase {
      */
     public void testGroundClosure2() {
         Flag myFlag = new Flag();
-        MapBuiltinRegistry.theRegistry.register(myFlag);
+        BuiltinRegistry.theRegistry.register(myFlag);
         List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules");
         GenericRuleReasoner reasoner = new GenericRuleReasoner( rules );
         InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
@@ -792,7 +792,7 @@ public class TestBugs extends TestCase {
         assertEquals( culprit, ResourceFactory.createTypedLiteral( new Integer(42) ));
         culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo').  (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X).");
         assertEquals( culprit, ResourceFactory.createPlainLiteral("foo"));
-        MapBuiltinRegistry.theRegistry.register( new SomeTriple() );
+        BuiltinRegistry.theRegistry.register( new SomeTriple() );
         culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42).  (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X).");
         assertTrue( culprit.isLiteral() );
         Object val = ((Literal)culprit).getValue();


[2/3] jena git commit: Merge branch 'master' of https://github.com/paulhoule/jena

Posted by de...@apache.org.
Merge branch 'master' of https://github.com/paulhoule/jena

Working on PR 150 #JENA-1204


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/1dfc1053
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/1dfc1053
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/1dfc1053

Branch: refs/heads/master
Commit: 1dfc10534ab1ec2934b4c4258fa6931ce16ca4ed
Parents: b6ee59d 60f4a0a
Author: der <da...@epimorphics.com>
Authored: Sun Jul 17 12:17:41 2016 +0100
Committer: der <da...@epimorphics.com>
Committed: Sun Jul 17 12:17:41 2016 +0100

----------------------------------------------------------------------
 .../apache/jena/reasoner/rulesys/Builtin.java   |  2 +-
 .../jena/reasoner/rulesys/BuiltinRegistry.java  | 88 +++++++-------------
 .../jena/reasoner/rulesys/FBRuleReasoner.java   |  2 +-
 .../apache/jena/reasoner/rulesys/Functor.java   | 57 +++++++++----
 .../reasoner/rulesys/MapBuiltinRegistry.java    | 69 +++++++++++++++
 .../rulesys/OverrideBuiltinRegistry.java        | 61 ++++++++++++++
 .../org/apache/jena/reasoner/rulesys/Rule.java  | 72 ++++++++++++----
 .../reasoner/rulesys/impl/BindingStack.java     |  2 +-
 .../reasoner/rulesys/impl/BindingVector.java    |  2 +-
 .../jena/reasoner/rulesys/test/TestBugs.java    |  4 +-
 .../test/TestGenericRuleReasonerConfig.java     | 46 ++++++++++
 11 files changed, 309 insertions(+), 96 deletions(-)
----------------------------------------------------------------------