jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1129708 - in /incubator/jena/Jena2/ARQ/trunk: ./ src-test/com/hp/hpl/jena/sparql/resultset/ src/com/hp/hpl/jena/query/ src/com/hp/hpl/jena/sparql/resultset/ src/org/openjena/riot/tokens/
Date Tue, 31 May 2011 14:42:02 GMT
Author: andy
Date: Tue May 31 14:42:01 2011
New Revision: 1129708

URL: http://svn.apache.org/viewvc?rev=1129708&view=rev
Log:
Apply patch for JENA-69 (TSVInput)

Added:
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java   (with
props)
Modified:
    incubator/jena/Jena2/ARQ/trunk/Acknowledgements
    incubator/jena/Jena2/ARQ/trunk/ChangeLog.txt
    incubator/jena/Jena2/ARQ/trunk/src-test/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ResultSetFactory.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVOutput.java
    incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java

Modified: incubator/jena/Jena2/ARQ/trunk/Acknowledgements
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/Acknowledgements?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/Acknowledgements (original)
+++ incubator/jena/Jena2/ARQ/trunk/Acknowledgements Tue May 31 14:42:01 2011
@@ -1 +1 @@
-https://issues.apache.org/jira/browse/JENA-65 - Laurent Pellegrino
\ No newline at end of file
+https://issues.apache.org/jira/browse/JENA-69 - Laurent Pellegrino
\ No newline at end of file

Modified: incubator/jena/Jena2/ARQ/trunk/ChangeLog.txt
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/ChangeLog.txt?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/ChangeLog.txt (original)
+++ incubator/jena/Jena2/ARQ/trunk/ChangeLog.txt Tue May 31 14:42:01 2011
@@ -3,6 +3,7 @@ ChangeLog for ARQ
 
 ==== ARQ 2.8.9
 
++ Add TSVInput processor (JENA-69 / Laurent Pellegrino) 
 + Added DatasetGraph.add(g,s,p,o) and .delete(g,s,p,o).
   (JENA-65)
 + Aggregates COUNT(?x) and COUNT(DISTINCT ?x) now skips errors in their expressions

Modified: incubator/jena/Jena2/ARQ/trunk/src-test/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-test/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat.java?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-test/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src-test/com/hp/hpl/jena/sparql/resultset/TestResultSetFormat.java
Tue May 31 14:42:01 2011
@@ -78,6 +78,15 @@ public class TestResultSetFormat
         ResultSet rs2 = ResultSetFactory.fromJSON(in) ;
     }
     
+    @Test public void resultset_04()           
+    {
+        ResultSet rs = make($rs1) ; 
+        ByteArrayOutputStream out = new ByteArrayOutputStream() ;
+        ResultSetFormatter.outputAsTSV(out, rs) ;
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
+        ResultSet rs2 = ResultSetFactory.fromTSV(in) ;
+    }
+    
 }
 
 /*

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ResultSetFactory.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ResultSetFactory.java?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ResultSetFactory.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/query/ResultSetFactory.java Tue May
31 14:42:01 2011
@@ -115,6 +115,11 @@ public class ResultSetFactory
             return JSONInput.fromJSON(input) ;
         }
         
+        if ( format.equals(ResultSetFormat.syntaxTSV) )
+        {
+            return TSVInput.fromTSV(input) ;
+        }
+        
         Log.warn(ResultSet.class, "Unknown result set syntax: "+format) ;
         return null ;
 
@@ -310,6 +315,16 @@ public class ResultSetFactory
         return JSONInput.fromJSON(in) ;
     }
     
+    /** Read from an input stream which is the format of the SPARQL result set format in
TSV.
+     * 
+     * @param in    InputStream
+     * @return      ResultSet
+     */  
+    public static ResultSet fromTSV(InputStream in)
+    {
+        return TSVInput.fromTSV(in) ;
+    }
+    
     /** Read from an input stream which is the format of the SPARQL result set format in
SSE.
      * 
      * @param in    InputStream

Added: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java?rev=1129708&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java Tue
May 31 14:42:01 2011
@@ -0,0 +1,72 @@
+package com.hp.hpl.jena.sparql.resultset;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openjena.riot.tokens.Token;
+import org.openjena.riot.tokens.Tokenizer;
+import org.openjena.riot.tokens.TokenizerFactory;
+
+import com.hp.hpl.jena.query.ResultSet;
+import com.hp.hpl.jena.sparql.core.Var;
+import com.hp.hpl.jena.sparql.engine.ResultSetStream;
+import com.hp.hpl.jena.sparql.engine.binding.Binding;
+import com.hp.hpl.jena.sparql.engine.binding.BindingFactory;
+import com.hp.hpl.jena.sparql.engine.iterator.QueryIterPlainWrapper;
+
+/**
+ * Input reader associated to {@link TSVOutput}.
+ * 
+ * @author Laurent Pellegrino
+ */
+public class TSVInput {
+
+    public static ResultSet fromTSV(InputStream in) {
+        Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(in);
+        List<String> varNames = new ArrayList<String>();
+        List<Binding> bindings = new ArrayList<Binding>();
+        
+        // reads the variables
+        List<Var> vars = new ArrayList<Var>();
+        Token token = null;
+        while (tokenizer.getLine() == 1)
+        {
+            token = tokenizer.next();
+
+            if (token.isWord()) 
+            {
+                vars.add(Var.alloc(token.asWord()));
+                varNames.add(vars.get(vars.size() - 1).getName());
+            }
+        }
+        
+        Binding binding = BindingFactory.create();;
+        // the first token from the second line is already
+        // consumed, hence we have to apply a specific 
+        // behavior to handle it
+        binding.add(vars.get(0), token.asNode());
+        for (byte i=1; i<vars.size(); i++)
+        {
+            binding.add(vars.get(i), tokenizer.next().asNode());
+        }
+        bindings.add(binding);
+        
+        // reads the next lines
+        while (tokenizer.hasNext()) 
+        {
+            binding = BindingFactory.create();
+            
+            // reads each node from a line
+            for (byte i=1; i<vars.size(); i++)
+            {
+                binding.add(vars.get(i), tokenizer.next().asNode());
+            }
+            
+            bindings.add(binding);
+        }
+        
+        return new ResultSetStream(varNames, null, new QueryIterPlainWrapper(bindings.iterator()));
+    }
+
+}

Propchange: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVInput.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVOutput.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVOutput.java?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVOutput.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/resultset/TSVOutput.java Tue
May 31 14:42:01 2011
@@ -47,18 +47,19 @@ public class TSVOutput extends OutputBas
             List<String> varNames = resultSet.getResultVars() ;
             List<Var> vars = new ArrayList<Var>(varNames.size()) ;
             
+            // writes the variables on the first line
             for( String v : varNames )
             {
                 if ( sep != null )
                     w.write(sep) ;
                 else
                     sep = SEP ;
-                w.write("?") ;
                 w.write(v) ; 
                 vars.add(Var.alloc(v)) ;
             }
             w.write(NL) ;
             
+            // writes one binding by line
             for ( ; resultSet.hasNext() ; )
             {
                 sep = null ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java?rev=1129708&r1=1129707&r2=1129708&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/tokens/Token.java Tue May 31 14:42:01
2011
@@ -137,6 +137,11 @@ public final class Token
         this.column = token.column ;
     }
     
+    public int asInt() {
+        if ( ! hasType(TokenType.INTEGER) ) return -1 ;
+        return Integer.valueOf(tokenImage);
+    }
+    
     public long asLong()
     {
         return asLong(-1) ;
@@ -153,11 +158,10 @@ public final class Token
         }
     }
     
-    
     public String asWord()
     {
         if ( ! hasType(TokenType.KEYWORD) ) return null ;
-        return getImage() ; 
+        return tokenImage ; 
     }
     
     public String text()



Mime
View raw message