clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r1485960 - in /clerezza/trunk: parent/ rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ rdf.jena.sparql/ rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jen...
Date Fri, 24 May 2013 08:11:22 GMT
Author: misl
Date: Fri May 24 08:11:22 2013
New Revision: 1485960

URL: http://svn.apache.org/r1485960
Log:
CLEREZZA-782: Added getResultVars() to ResultSet.

Modified:
    clerezza/trunk/parent/pom.xml
    clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ResultSet.java
    clerezza/trunk/rdf.jena.sparql/pom.xml
    clerezza/trunk/rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ResultSetWrapper.java
    clerezza/trunk/rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jena/sparql/SimpleTest.java
    clerezza/trunk/rdf.web/rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/utils/ResultSetsWrapper.java

Modified: clerezza/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/clerezza/trunk/parent/pom.xml?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/parent/pom.xml (original)
+++ clerezza/trunk/parent/pom.xml Fri May 24 08:11:22 2013
@@ -553,6 +553,11 @@
                 <artifactId>bcprov-jdk16</artifactId>
                 <version>1.46</version>
             </dependency>
+            <dependency>
+            	<groupId>org.apache.clerezza</groupId>
+            	<artifactId>rdf.jena.storage</artifactId>
+            	<version>0.6-SNAPSHOT</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     <distributionManagement>

Modified: clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ResultSet.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ResultSet.java?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ResultSet.java
(original)
+++ clerezza/trunk/rdf.core/src/main/java/org/apache/clerezza/rdf/core/sparql/ResultSet.java
Fri May 24 08:11:22 2013
@@ -19,6 +19,7 @@
 package org.apache.clerezza.rdf.core.sparql;
 
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * The reult of a sparql SELECT-query. This corresponds to a Solution Sequence
@@ -31,4 +32,8 @@ import java.util.Iterator;
  */
 public interface ResultSet extends Iterator<SolutionMapping> {
 
+    /** Iterate over the variable names (strings) in this QuerySolution.
+     * @return Iterator of strings
+     */ 
+    public List<String> getResultVars() ;
 }

Modified: clerezza/trunk/rdf.jena.sparql/pom.xml
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.jena.sparql/pom.xml?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/rdf.jena.sparql/pom.xml (original)
+++ clerezza/trunk/rdf.jena.sparql/pom.xml Fri May 24 08:11:22 2013
@@ -37,7 +37,6 @@
         <dependency>
             <groupId>org.apache.clerezza</groupId>
             <artifactId>rdf.jena.storage</artifactId>
-            <version>0.6-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.clerezza</groupId>

Modified: clerezza/trunk/rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ResultSetWrapper.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ResultSetWrapper.java?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ResultSetWrapper.java
(original)
+++ clerezza/trunk/rdf.jena.sparql/src/main/java/org/apache/clerezza/rdf/jena/sparql/ResultSetWrapper.java
Fri May 24 08:11:22 2013
@@ -32,6 +32,7 @@ import org.apache.clerezza.rdf.core.spar
 public class ResultSetWrapper implements org.apache.clerezza.rdf.core.sparql.ResultSet {
 
     private final Iterator<QuerySolution> solutionsIter;
+    private final List<String> resultVars;
 
 
     public ResultSetWrapper(final ResultSet jenaResultSet) {
@@ -40,6 +41,7 @@ public class ResultSetWrapper implements
             solutions.add(jenaResultSet.nextSolution());
         }
         solutionsIter = solutions.iterator();
+        resultVars = jenaResultSet.getResultVars();
     }
 
     @Override
@@ -57,4 +59,8 @@ public class ResultSetWrapper implements
         throw new UnsupportedOperationException("Not supported yet.");
     }
 
+    @Override
+    public List<String> getResultVars() {
+    	return resultVars;
+    }
 }

Modified: clerezza/trunk/rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jena/sparql/SimpleTest.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jena/sparql/SimpleTest.java?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jena/sparql/SimpleTest.java
(original)
+++ clerezza/trunk/rdf.jena.sparql/src/test/java/org/apache/clerezza/rdf/jena/sparql/SimpleTest.java
Fri May 24 08:11:22 2013
@@ -18,6 +18,8 @@
  */
 package org.apache.clerezza.rdf.jena.sparql;
 
+import java.util.List;
+
 import org.junit.Assert;
 import org.junit.Test;
 import org.apache.clerezza.rdf.core.Graph;
@@ -33,84 +35,87 @@ import org.apache.clerezza.rdf.core.spar
 import org.apache.clerezza.rdf.ontologies.DC;
 
 /**
- *
+ * 
  * @author rbn
  */
 public class SimpleTest {
 
-    @Test
-    public void simpleStringQuery() throws ParseException {
-        SimpleMGraph data = new SimpleMGraph();
-        final String titleValue = "SPARQL Tutorial";
-        data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
-                DC.title, new PlainLiteralImpl(titleValue)));
-        String query = "SELECT ?title WHERE" +
-                "{" +
-                "    <http://example.org/book/book1> <"+DC.title.getUnicodeString()+">
?title ." +
-                "}";
-        ResultSet resultSet = (ResultSet) TcManager.getInstance().executeSparqlQuery(
-                query, data);
-        Assert.assertEquals(titleValue, 
-                ((Literal)resultSet.next().get("title")).getLexicalForm());
-    }
-
-    @Test
-    public void simpleSelectQuery() throws ParseException {
-        SimpleMGraph data = new SimpleMGraph();
-        final String titleValue = "SPARQL Tutorial";
-        data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
-                DC.title, new PlainLiteralImpl(titleValue)));
-        String query = "SELECT ?title WHERE" +
-                "{" +
-                "    <http://example.org/book/book1> <"+DC.title.getUnicodeString()+">
?title ." +
-                "}";
-        ResultSet resultSet = (ResultSet) TcManager.getInstance().executeSparqlQuery(
-                QueryParser.getInstance().parse(query), data);
-        Assert.assertEquals(titleValue, 
-                ((Literal)resultSet.next().get("title")).getLexicalForm());
-    }
-
-    @Test
-    public void simpleAskQuery() throws ParseException {
-        SimpleMGraph data = new SimpleMGraph();
-        final String titleValue = "SPARQL Tutorial";
-        data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
-                DC.title, new PlainLiteralImpl(titleValue)));
-        String query = "ASK WHERE" +
-                "{" +
-                "    <http://example.org/book/book1> <"+DC.title.getUnicodeString()+">
?title ." +
-                "}";
-        Assert.assertEquals(Boolean.TRUE,
-                TcManager.getInstance().executeSparqlQuery(
-                QueryParser.getInstance().parse(query), data));
-    }
-
-    @Test
-    public void simpleDescribe() throws ParseException {
-        SimpleMGraph data = new SimpleMGraph();
-        final String titleValue = "SPARQL Tutorial";
-        data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
-                DC.title, new PlainLiteralImpl(titleValue)));
-        String query = "DESCRIBE "+
-                "    <http://example.org/book/book1>";
-        Assert.assertEquals(1,
-                ((Graph)TcManager.getInstance().executeSparqlQuery(
-                QueryParser.getInstance().parse(query), data)).size());
-    }
-
-    @Test
-    public void simpleConstruct() throws ParseException {
-        SimpleMGraph data = new SimpleMGraph();
-        final String titleValue = "SPARQL Tutorial";
-        data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
-                DC.title, new PlainLiteralImpl(titleValue)));
-        String query = "PREFIX foaf:   <http://xmlns.com/foaf/0.1/> " +
-                "CONSTRUCT { <http://foo/bar> foaf:name ?title } WHERE" +
-                "{" +
-                "    <http://example.org/book/book1> <"+DC.title.getUnicodeString()+">
?title ." +
-                "}";
-        Assert.assertEquals(1,
-                ((Graph)TcManager.getInstance().executeSparqlQuery(
-                QueryParser.getInstance().parse(query), data)).size());
-    }
+	@Test
+	public void simpleStringQuery() throws ParseException {
+		SimpleMGraph data = new SimpleMGraph();
+		final String titleValue = "SPARQL Tutorial";
+		data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
+				DC.title, new PlainLiteralImpl(titleValue)));
+		String query = "SELECT ?title WHERE" + "{"
+				+ "    <http://example.org/book/book1> <"
+				+ DC.title.getUnicodeString() + "> ?title ." + "}";
+		ResultSet resultSet = (ResultSet) TcManager.getInstance()
+				.executeSparqlQuery(query, data);
+		Assert.assertEquals(titleValue, ((Literal) resultSet.next()
+				.get("title")).getLexicalForm());
+
+		List<String> columnNames = resultSet.getResultVars();
+		Assert.assertEquals(columnNames.size(), 1);
+		Assert.assertEquals(columnNames.get(0), "title");
+	}
+
+	@Test
+	public void simpleSelectQuery() throws ParseException {
+		SimpleMGraph data = new SimpleMGraph();
+		final String titleValue = "SPARQL Tutorial";
+		data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
+				DC.title, new PlainLiteralImpl(titleValue)));
+		String query = "SELECT ?title WHERE" + "{"
+				+ "    <http://example.org/book/book1> <"
+				+ DC.title.getUnicodeString() + "> ?title ." + "}";
+		ResultSet resultSet = (ResultSet) TcManager.getInstance()
+				.executeSparqlQuery(QueryParser.getInstance().parse(query),
+						data);
+		Assert.assertEquals(titleValue, ((Literal) resultSet.next()
+				.get("title")).getLexicalForm());
+	}
+
+	@Test
+	public void simpleAskQuery() throws ParseException {
+		SimpleMGraph data = new SimpleMGraph();
+		final String titleValue = "SPARQL Tutorial";
+		data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
+				DC.title, new PlainLiteralImpl(titleValue)));
+		String query = "ASK WHERE" + "{"
+				+ "    <http://example.org/book/book1> <"
+				+ DC.title.getUnicodeString() + "> ?title ." + "}";
+		Assert.assertEquals(
+				Boolean.TRUE,
+				TcManager.getInstance().executeSparqlQuery(
+						QueryParser.getInstance().parse(query), data));
+	}
+
+	@Test
+	public void simpleDescribe() throws ParseException {
+		SimpleMGraph data = new SimpleMGraph();
+		final String titleValue = "SPARQL Tutorial";
+		data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
+				DC.title, new PlainLiteralImpl(titleValue)));
+		String query = "DESCRIBE " + "    <http://example.org/book/book1>";
+		Assert.assertEquals(
+				1,
+				((Graph) TcManager.getInstance().executeSparqlQuery(
+						QueryParser.getInstance().parse(query), data)).size());
+	}
+
+	@Test
+	public void simpleConstruct() throws ParseException {
+		SimpleMGraph data = new SimpleMGraph();
+		final String titleValue = "SPARQL Tutorial";
+		data.add(new TripleImpl(new UriRef("http://example.org/book/book1"),
+				DC.title, new PlainLiteralImpl(titleValue)));
+		String query = "PREFIX foaf:   <http://xmlns.com/foaf/0.1/> "
+				+ "CONSTRUCT { <http://foo/bar> foaf:name ?title } WHERE" + "{"
+				+ "    <http://example.org/book/book1> <"
+				+ DC.title.getUnicodeString() + "> ?title ." + "}";
+		Assert.assertEquals(
+				1,
+				((Graph) TcManager.getInstance().executeSparqlQuery(
+						QueryParser.getInstance().parse(query), data)).size());
+	}
 }

Modified: clerezza/trunk/rdf.web/rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/utils/ResultSetsWrapper.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.web/rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/utils/ResultSetsWrapper.java?rev=1485960&r1=1485959&r2=1485960&view=diff
==============================================================================
--- clerezza/trunk/rdf.web/rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/utils/ResultSetsWrapper.java
(original)
+++ clerezza/trunk/rdf.web/rdf.web.core/src/main/java/org/apache/clerezza/rdf/web/core/utils/ResultSetsWrapper.java
Fri May 24 08:11:22 2013
@@ -16,7 +16,10 @@
  */
 package org.apache.clerezza.rdf.web.core.utils;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 import org.apache.clerezza.rdf.core.sparql.ResultSet;
 import org.apache.clerezza.rdf.core.sparql.SolutionMapping;
@@ -30,10 +33,17 @@ public class ResultSetsWrapper implement
 
     private Iterator<ResultSet> resultSetsIter;
     private ResultSet currentResultSet;
+    private List<String> varNames;
 
     public ResultSetsWrapper(Set<ResultSet> resultSets) {
         this.resultSetsIter = resultSets.iterator();
-        currentResultSet = resultSetsIter.next();
+        this.currentResultSet = resultSetsIter.next();
+
+        Set<String> uniqueVarNames = new HashSet<String>();
+        for (ResultSet resultSet : resultSets) {
+			uniqueVarNames.addAll(resultSet.getResultVars());
+		}
+    	this.varNames = new ArrayList<String>(uniqueVarNames);
     }
 
     @Override
@@ -59,4 +69,9 @@ public class ResultSetsWrapper implement
     public void remove() {
         currentResultSet.remove();
     }
+    
+    @Override
+    public List<String> getResultVars() {
+    	return varNames;
+    }
 }



Mime
View raw message