You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2012/11/20 01:41:06 UTC

svn commit: r1411489 - in /jena/trunk/jena-arq/src: main/java/com/hp/hpl/jena/sparql/function/user/ test/java/com/hp/hpl/jena/sparql/function/user/

Author: rvesse
Date: Tue Nov 20 00:41:05 2012
New Revision: 1411489

URL: http://svn.apache.org/viewvc?rev=1411489&view=rev
Log:
Change AllowDependencies to PreserveDependencies as that better describes the behaviour it embodies

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/ExprTransformExpand.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/UserDefinedFunctionFactory.java
    jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionExpansion.java
    jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionNonExpansion.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/ExprTransformExpand.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/ExprTransformExpand.java?rev=1411489&r1=1411488&r2=1411489&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/ExprTransformExpand.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/ExprTransformExpand.java Tue Nov 20 00:41:05 2012
@@ -33,7 +33,7 @@ import com.hp.hpl.jena.sparql.sse.builde
  * An expression transformer that will expand user defined function expressions
  * so they do not explicitly rely on other user defined functions.
  * <p>
- * See {@link UserDefinedFunctionFactory#getAllowDependencies()} for discussion of what this means in practise
+ * See {@link UserDefinedFunctionFactory#getPreserveDependencies()} for discussion of what this means in practise
  * </p>
  */
 public class ExprTransformExpand extends ExprTransformCopy {

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/UserDefinedFunctionFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/UserDefinedFunctionFactory.java?rev=1411489&r1=1411488&r2=1411489&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/UserDefinedFunctionFactory.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/function/user/UserDefinedFunctionFactory.java Tue Nov 20 00:41:05 2012
@@ -57,7 +57,11 @@ import com.hp.hpl.jena.sparql.sse.builde
  * <p>
  * Internally the call to the <strong>square</strong> function is translated into it's equivalent SPARQL expression and executed in that form.
  * </p>
- *
+ * <p>
+ * User defined functions may rely on each other but this has some risks, therefore the default behaviour is to not preserve these dependencies
+ * but rather to expand the function definitions to give the resulting expression associated with a function.  Please see {@link #getPreserveDependencies()}
+ * for more information on this.
+ * </p>
  */
 public class UserDefinedFunctionFactory implements FunctionFactory {
     
@@ -72,7 +76,7 @@ public class UserDefinedFunctionFactory 
     }
 
     private Map<String, UserDefinedFunctionDefinition> definitions = new HashMap<String, UserDefinedFunctionDefinition>();
-    private boolean allowDependencies = false;
+    private boolean preserveDependencies = false;
     
     /**
      * Private constructor prevents instantiation
@@ -80,29 +84,29 @@ public class UserDefinedFunctionFactory 
     private UserDefinedFunctionFactory() { }
     
     /**
-     * Gets whether user defined functions may explicitly rely on each other (default false)
+     * Gets whether user defined functions may preserve dependencies on each other (default false)
      * <p>
-     * When this is disabled (as it is by default) function definitions are fully expanded at registration time, so if
+     * When this is disabled (as it is by default) function definitions are fully expanded at registration time.  So if
      * you add a function that references an existing user defined function it will be expanded to include the
      * resulting expression rather than left with a reference to another function.  This protects the user from
-     * depending on other functions whose definitions are removed or changed.
+     * depending on other functions whose definitions are later removed or changed.
      * </p>
      * <p>
-     * However it may sometimes be desirable to have functions explicitly depend on each in which case this option may be 
-     * disabled with the corresponding {@link #setAllowDependencies(boolean)} setter
+     * However it may sometimes be desirable to have dependencies preserved which case this option may be 
+     * disabled with the corresponding {@link #setPreserveDependencies(boolean)} setter
      * </p>
      * @return Whether explicit dependencies are allowed
      */
-    public boolean getAllowDependencies() {
-        return this.allowDependencies;
+    public boolean getPreserveDependencies() {
+        return this.preserveDependencies;
     }
     
     /**
-     * Sets whether user functions may explicitly depend on each other, see {@link #getAllowDependencies()} for explanation of this behaviour
-     * @param allow Whether to allow explicit dependencies
+     * Sets whether user functions may explicitly depend on each other, see {@link #getPreserveDependencies()} for explanation of this behavior
+     * @param allow Whether to preserve dependencies
      */
-    public void setAllowDependencies(boolean allow) {
-        this.allowDependencies = allow;
+    public void setPreserveDependencies(boolean allow) {
+        this.preserveDependencies = allow;
     }
         
     /**
@@ -123,7 +127,7 @@ public class UserDefinedFunctionFactory 
      * @param args Arguments
      */
     public void add(String uri, Expr e, List<Var> args) {
-        if (!allowDependencies) {
+        if (!preserveDependencies) {
             //If not allowing dependencies expand expression fully
             e = ExprTransformer.transform(new ExprTransformExpand(this.definitions), e);
         }        
@@ -148,7 +152,7 @@ public class UserDefinedFunctionFactory 
      */
     public void add(String uri, String expr, List<Var> args) throws ParseException {
         Expr e = new SPARQLParser11(new StringReader(expr)).Expression();
-        if (!allowDependencies) {
+        if (!preserveDependencies) {
             //If not allowing dependencies expand expression fully
             e = ExprTransformer.transform(new ExprTransformExpand(this.definitions), e);
         }  

Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionExpansion.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionExpansion.java?rev=1411489&r1=1411488&r2=1411489&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionExpansion.java (original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionExpansion.java Tue Nov 20 00:41:05 2012
@@ -45,20 +45,20 @@ import com.hp.hpl.jena.sparql.util.NodeF
 
 /**
  * Test for checking that functions are appropriately expanded when supplied with actual arguments
- *
+ * and the default behavior of not preserving dependencies is enabled
  */
 public class TestFunctionExpansion {
     
     @BeforeClass
     public static void setup() {
         UserDefinedFunctionFactory.getFactory().clear();
-        UserDefinedFunctionFactory.getFactory().setAllowDependencies(false);
+        UserDefinedFunctionFactory.getFactory().setPreserveDependencies(false);
     }
     
     @AfterClass
     public static void teardown() {
         UserDefinedFunctionFactory.getFactory().clear();
-        UserDefinedFunctionFactory.getFactory().setAllowDependencies(false);
+        UserDefinedFunctionFactory.getFactory().setPreserveDependencies(false);
     }
 
     @Test
@@ -114,7 +114,7 @@ public class TestFunctionExpansion {
         Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
         
-        //Test that with allowDependencies set to false (the default) that the definition of cube is actually
+        //Test that with preserveDependencies set to false (the default) that the definition of cube is actually
         //expanded to include the definition of square
         Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
@@ -133,7 +133,7 @@ public class TestFunctionExpansion {
         Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
         
-        //Test that with allowDependencies set to false (the default) that the definition of cube is actually
+        //Test that with preserveDependencies set to false (the default) that the definition of cube is actually
         //expanded to include the definition of square
         Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("y"))), new ExprVar("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
@@ -155,7 +155,7 @@ public class TestFunctionExpansion {
         args.add(Var.alloc("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         ExprList numArgs = new ExprList();
         numArgs.add(new NodeValueInteger(1));
         numArgs.add(new NodeValueDouble(2.3));
@@ -178,7 +178,7 @@ public class TestFunctionExpansion {
         args.add(Var.alloc("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         ExprList numArgs = new ExprList();
         numArgs.add(new NodeValueDouble(2.3));
         numArgs.add(new NodeValueInteger(1));
@@ -201,7 +201,7 @@ public class TestFunctionExpansion {
         args.add(Var.alloc("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         ExprList altArgs = new ExprList();
         altArgs.add(new ExprVar("a"));
         altArgs.add(new ExprVar("b"));
@@ -229,7 +229,7 @@ public class TestFunctionExpansion {
         args.add(Var.alloc("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         ExprList altArgs = new ExprList();
         altArgs.add(new ExprVar("b"));
         altArgs.add(new ExprVar("a"));
@@ -254,7 +254,7 @@ public class TestFunctionExpansion {
         Expr single = new ExprVar("x");
         UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<Var>(single.getVarsMentioned()));
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         //when the outer function has differing numbers of arguments
         List<Var> args = new ArrayList<Var>();
         args.add(Var.alloc("x"));
@@ -277,7 +277,7 @@ public class TestFunctionExpansion {
         Expr single = new ExprVar("x");
         UserDefinedFunctionFactory.getFactory().add("http://example/single", single, new ArrayList<Var>(single.getVarsMentioned()));
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         //when the outer function has differing numbers of arguments
         List<Var> args = new ArrayList<Var>();
         args.add(Var.alloc("x"));
@@ -303,7 +303,7 @@ public class TestFunctionExpansion {
         args.add(Var.alloc("y"));
         UserDefinedFunctionFactory.getFactory().add("http://example/takeaway", takeaway, args);
         
-        //Test that with allowDependencies set to false (the default) that the definition is expanded appropriately
+        //Test that with preserveDependencies set to false (the default) that the definition is expanded appropriately
         ExprList altArgs = new ExprList();
         altArgs.add(new ExprVar("a"));
         altArgs.add(new ExprVar("a"));
@@ -329,7 +329,7 @@ public class TestFunctionExpansion {
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
         
         //This test illustrates that if we change the definition of square and call our function again we always
-        //get the same result with dependencies disallowed (false) because even though the definition of the dependent function 
+        //get the same result with dependencies not preserved because even though the definition of the dependent function 
         //can change the definition of our function is fully expanded when first defined
         Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
@@ -342,7 +342,7 @@ public class TestFunctionExpansion {
         Assert.assertEquals(8, NodeFactory.nodeToInt(result.asNode()));
         
         //Change the definition of the function we depend on
-        //This has no effect with allowDependencies set to false (the default) since we fully expanded the call to the dependent
+        //This has no effect with preserveDependencies set to false (the default) since we fully expanded the call to the dependent
         //function when our outer function was defined
         square = new ExprVar("x");
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));

Modified: jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionNonExpansion.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionNonExpansion.java?rev=1411489&r1=1411488&r2=1411489&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionNonExpansion.java (original)
+++ jena/trunk/jena-arq/src/test/java/com/hp/hpl/jena/sparql/function/user/TestFunctionNonExpansion.java Tue Nov 20 00:41:05 2012
@@ -38,7 +38,7 @@ import com.hp.hpl.jena.sparql.function.F
 import com.hp.hpl.jena.sparql.util.NodeFactory;
 
 /**
- * Tests which check that functions are not expanded when {@link UserDefinedFunctionFactory#setAllowDependencies(boolean)} is set to true
+ * Tests which check that functions are not expanded when {@link UserDefinedFunctionFactory#setPreserveDependencies(boolean)} is set to true
  *
  */
 public class TestFunctionNonExpansion {
@@ -46,13 +46,13 @@ public class TestFunctionNonExpansion {
     @BeforeClass
     public static void setup() {
         UserDefinedFunctionFactory.getFactory().clear();
-        UserDefinedFunctionFactory.getFactory().setAllowDependencies(true);
+        UserDefinedFunctionFactory.getFactory().setPreserveDependencies(true);
     }
     
     @AfterClass
     public static void teardown() {
         UserDefinedFunctionFactory.getFactory().clear();
-        UserDefinedFunctionFactory.getFactory().setAllowDependencies(false);
+        UserDefinedFunctionFactory.getFactory().setPreserveDependencies(false);
     }
     
     @Test
@@ -60,7 +60,7 @@ public class TestFunctionNonExpansion {
         Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
         
-        //Test that with allowDependencies set to true that the definition of cube is not expanded
+        //Test that with preserveDependencies set to true that the definition of cube is not expanded
         Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));
         
@@ -81,7 +81,7 @@ public class TestFunctionNonExpansion {
         UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<Var>(square.getVarsMentioned()));
         
         //This test illustrates that if we change the definition of square and call our function again we can
-        //get a different result with dependencies allowed because the definition of the dependent function can change
+        //get a different result with dependencies preserved because the definition of the dependent function can change
         Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x"));
         UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<Var>(cube.getVarsMentioned()));