You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/09/26 14:36:38 UTC

svn commit: r1526459 - in /jena/trunk: jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/ jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/ jena-text/src/main/java/org/apache/jena/query/text/ jena-text/src/test/java/org/ap...

Author: andy
Date: Thu Sep 26 12:36:38 2013
New Revision: 1526459

URL: http://svn.apache.org/r1526459
Log:
JENA-549 : Ground subject and object PropFuncArg before use.
Add checking code to QueryIterExtendByVar

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/QueryIterExtendByVar.java
    jena/trunk/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
    jena/trunk/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithTextIndex.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/QueryIterExtendByVar.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/QueryIterExtendByVar.java?rev=1526459&r1=1526458&r2=1526459&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/QueryIterExtendByVar.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/iterator/QueryIterExtendByVar.java Thu Sep 26 12:36:38 2013
@@ -21,6 +21,7 @@ package com.hp.hpl.jena.sparql.engine.it
 import java.util.Iterator ;
 
 import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
 import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.binding.Binding ;
@@ -39,6 +40,10 @@ public class QueryIterExtendByVar extend
     public QueryIterExtendByVar(Binding binding, Var var, Iterator<Node> members, ExecutionContext execCxt)
     {
         super(execCxt) ;
+        if ( true ) { // Assume not too costly.
+            if ( binding.contains(var) )
+                throw new ARQInternalErrorException("Var "+var+" already set in "+binding) ;
+        }
         this.binding = binding ;
         this.var = var ;
         this.members = members ;

Modified: jena/trunk/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java?rev=1526459&r1=1526458&r2=1526459&view=diff
==============================================================================
--- jena/trunk/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java (original)
+++ jena/trunk/jena-spatial/src/main/java/org/apache/jena/query/spatial/pfunction/SpatialOperationPFBase.java Thu Sep 26 12:36:38 2013
@@ -18,29 +18,30 @@
 
 package org.apache.jena.query.spatial.pfunction;
 
-import java.util.List;
+import java.util.List ;
 
-import org.apache.jena.atlas.iterator.Iter;
-import org.apache.jena.atlas.lib.InternalErrorException;
-import org.apache.jena.atlas.logging.Log;
-import org.apache.jena.query.spatial.DatasetGraphSpatial;
-import org.apache.jena.query.spatial.SpatialIndex;
-import org.apache.jena.query.spatial.SpatialQuery;
-import org.apache.lucene.spatial.query.SpatialOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.hp.hpl.jena.graph.Node;
-import com.hp.hpl.jena.sparql.core.DatasetGraph;
-import com.hp.hpl.jena.sparql.core.Var;
-import com.hp.hpl.jena.sparql.engine.ExecutionContext;
-import com.hp.hpl.jena.sparql.engine.QueryIterator;
-import com.hp.hpl.jena.sparql.engine.binding.Binding;
-import com.hp.hpl.jena.sparql.engine.iterator.QueryIterExtendByVar;
-import com.hp.hpl.jena.sparql.engine.iterator.QueryIterSlice;
-import com.hp.hpl.jena.sparql.pfunction.PropFuncArg;
-import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionBase;
-import com.hp.hpl.jena.sparql.util.IterLib;
+import org.apache.jena.atlas.iterator.Iter ;
+import org.apache.jena.atlas.lib.InternalErrorException ;
+import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.query.spatial.DatasetGraphSpatial ;
+import org.apache.jena.query.spatial.SpatialIndex ;
+import org.apache.jena.query.spatial.SpatialQuery ;
+import org.apache.lucene.spatial.query.SpatialOperation ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Substitute ;
+import com.hp.hpl.jena.sparql.core.Var ;
+import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
+import com.hp.hpl.jena.sparql.engine.QueryIterator ;
+import com.hp.hpl.jena.sparql.engine.binding.Binding ;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterExtendByVar ;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterSlice ;
+import com.hp.hpl.jena.sparql.pfunction.PropFuncArg ;
+import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionBase ;
+import com.hp.hpl.jena.sparql.util.IterLib ;
 
 public abstract class SpatialOperationPFBase extends PropertyFunctionBase {
 
@@ -95,10 +96,12 @@ public abstract class SpatialOperationPF
 		}
 
 		DatasetGraph dsg = execCxt.getDataset();
-
+		
+        argSubject = Substitute.substitute(argSubject, binding) ;
+        argObject = Substitute.substitute(argObject, binding) ;
+		
 		if (!argSubject.isNode())
-			throw new InternalErrorException(
-					"Subject is not a node (it was earlier!)");
+			throw new InternalErrorException("Subject is not a node (it was earlier!)");
 
 		Node s = argSubject.getArg();
 

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java?rev=1526459&r1=1526458&r2=1526459&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQueryPF.java Thu Sep 26 12:36:38 2013
@@ -32,6 +32,7 @@ import com.hp.hpl.jena.datatypes.xsd.XSD
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.query.QueryBuildException ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Substitute ;
 import com.hp.hpl.jena.sparql.core.Var ;
 import com.hp.hpl.jena.sparql.engine.ExecutionContext ;
 import com.hp.hpl.jena.sparql.engine.QueryIterator ;
@@ -113,6 +114,9 @@ public class TextQueryPF extends Propert
 
         DatasetGraph dsg = execCxt.getDataset() ;
 
+        argSubject = Substitute.substitute(argSubject, binding) ;
+        argObject = Substitute.substitute(argObject, binding) ;
+
         if (!argSubject.isNode())
             throw new InternalErrorException("Subject is not a node (it was earlier!)") ;
 
@@ -188,7 +192,6 @@ public class TextQueryPF extends Propert
         EntityDefinition docDef = server.getDocDef() ;
         if (argObject.isNode()) {
             Node o = argObject.getArg() ;
-
             if (!o.isLiteral()) {
                 log.warn("Object to text query is not a literal") ;
                 return null ;

Modified: jena/trunk/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithTextIndex.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithTextIndex.java?rev=1526459&r1=1526458&r2=1526459&view=diff
==============================================================================
--- jena/trunk/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithTextIndex.java (original)
+++ jena/trunk/jena-text/src/test/java/org/apache/jena/query/text/AbstractTestDatasetWithTextIndex.java Thu Sep 26 12:36:38 2013
@@ -69,11 +69,131 @@ public abstract class AbstractTestDatase
 				"    ?s text:query ( rdfs:label 'testOneSimpleResult' 10 ) .",
 				"}"
 				);
-		Set<String> expectedURIs = (new HashSet<String>());
-		expectedURIs.addAll( Arrays.asList((new String[] {"http://example.org/data/resource/testOneSimpleResult"})));
+		Set<String> expectedURIs = new HashSet<String>() ;
+		expectedURIs.addAll( Arrays.asList("http://example.org/data/resource/testOneSimpleResult")) ;
 		doTestSearch(turtle, queryString, expectedURIs);
 	}
 
+	static String R_S1 = RESOURCE_BASE + "s1" ;
+    static String R_S2 = RESOURCE_BASE + "s2" ;
+	static String PF_DATA = StrUtils.strjoinNL(
+	                                           TURTLE_PROLOG,
+	                                           "<" + R_S1 + "> rdfs:label 'text' .",
+	                                           "<" + R_S2 + "> rdfs:label 'fuzz' ."
+	                                           );
+	
+    @Test
+    public void propertyFunctionText_1() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'text') .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+    @Test
+    public void propertyFunctionText_2() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s text:query ( rdfs:label 'text') .",
+                "    ?s rdfs:label 'text' .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+    @Test
+    public void propertyFunctionText_3() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s rdfs:label 'text' .",
+                "    ?s text:query ( rdfs:label 'text') .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+    
+    @Test
+    public void propertyFunctionText_4() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    ?s rdfs:label 'text' .",
+                "    ?s text:query ( rdfs:label 'fuzz') .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+    @Test
+    public void propertyFunctionText_5() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    BIND('text' AS ?t)", 
+                "    ?s text:query ( rdfs:label ?t) .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+    @Test
+    public void propertyFunctionText_6() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    BIND(rdfs:label AS ?P)", 
+                "    ?s text:query ( ?P 'text') .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+
+    @Test
+    public void propertyFunctionText_7() {
+        final String turtle = PF_DATA ;
+        String queryString = StrUtils.strjoinNL(
+                QUERY_PROLOG,
+                "SELECT ?s",
+                "WHERE {",
+                "    BIND(1 AS ?C)", 
+                "    ?s text:query ( rdfs:label 'text' ?C) .",
+                "}"
+                );
+        Set<String> expectedURIs = new HashSet<String>();
+        expectedURIs.addAll( Arrays.asList( R_S1 ) ) ;
+        doTestSearch(turtle, queryString, expectedURIs);
+    }
+
+
     @Test
 	public void testMultipleResults() {
 		String label = "testMultipleResults";
@@ -93,13 +213,11 @@ public abstract class AbstractTestDatase
 				"    ?s text:query ( rdfs:label '" + label + "?' 10 ) .",
 				"}"
 				);
-		Set<String> expectedURIs = (new HashSet<String>());
-		expectedURIs.addAll( Arrays.asList((new String[]
-				{
+		Set<String> expectedURIs = new HashSet<String>() ;
+		expectedURIs.addAll( Arrays.asList(
 			    "http://example.org/data/resource/" + label + "1",
 			    "http://example.org/data/resource/" + label + "2"
-				}
-		)));
+		    ));
 		doTestSearch(turtle, queryString, expectedURIs);
 	}
 
@@ -132,18 +250,14 @@ public abstract class AbstractTestDatase
 				"    ?s text:query ( rdfs:comment '" + label + "?' 10 ) .",
 				"}"
 				);
-		Set<String> expectedURIsLabel = (new HashSet<String>());
-		expectedURIsLabel.addAll( Arrays.asList((new String[]
-				{
-			    "http://example.org/data/resource/" + label + "1",
-				}
-		)));
-		Set<String> expectedURIsComment = (new HashSet<String>());
-		expectedURIsComment.addAll( Arrays.asList((new String[]
-				{
-			    "http://example.org/data/resource/" + label + "2",
-				}
-		)));
+		Set<String> expectedURIsLabel = new HashSet<String>() ;
+		expectedURIsLabel.addAll( Arrays.asList(
+			    "http://example.org/data/resource/" + label + "1"
+		    ));
+		Set<String> expectedURIsComment = new HashSet<String>() ;
+		expectedURIsComment.addAll( Arrays.asList(
+			    "http://example.org/data/resource/" + label + "2"
+		    ));
 		doTestSearch("label:", turtle, queryStringLabel, expectedURIsLabel);
 		doTestSearch("comment:", turtle, queryStringComment, expectedURIsComment);
 	}
@@ -170,12 +284,10 @@ public abstract class AbstractTestDatase
 				"    ?s text:query ( rdfs:label '" + label + "?' 10 ) .",
 				"}"
 				);
-		Set<String> expectedURIs = (new HashSet<String>());
-		expectedURIs.addAll( Arrays.asList((new String[]
-				{
-			    "http://example.org/data/resource/" + label + "1",
-				}
-		)));
+		Set<String> expectedURIs = new HashSet<String>() ;
+		expectedURIs.addAll( Arrays.asList(
+			    "http://example.org/data/resource/" + label + "1"
+		    ));
 		doTestSearch("default field:", turtle, queryString, expectedURIs);
 	}
 
@@ -204,16 +316,13 @@ public abstract class AbstractTestDatase
 				"    ?s text:query ( '" + label + "' 3 ) .",
 				"}"
 				);
-		Set<String> expectedURIs = (new HashSet<String>());
-		expectedURIs.addAll( Arrays.asList((
-				new String[]
-				{
+		Set<String> expectedURIs = new HashSet<String>() ;
+		expectedURIs.addAll( Arrays.asList(
 					    "http://example.org/data/resource/" + label + "1",
 					    "http://example.org/data/resource/" + label + "2",
 					    "http://example.org/data/resource/" + label + "3",
-					    "http://example.org/data/resource/" + label + "4",
-				}
-		)));
+					    "http://example.org/data/resource/" + label + "4"
+		    ));
 		doTestSearch("default field:", turtle, queryString, expectedURIs, 3 );
 	}
 	
@@ -244,11 +353,8 @@ public abstract class AbstractTestDatase
 		    boolean b = ( (expectedNumResults > 0) == results.hasNext() ) ;
 		    if ( !b ) {
 		        System.out.println(queryString) ;
-		        System.out.println(expectedNumResults) ;
-		        
+		        //System.out.println(expectedNumResults) ;
 		    }
-		    
-		    
 		    assertEquals(label, expectedNumResults > 0, results.hasNext());
 		    int count;
 		    for (count=0; results.hasNext(); count++) {