jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1174067 - in /incubator/jena/Jena2/ARQ/trunk: src-dev/dev/ src/com/hp/hpl/jena/sparql/engine/binding/ src/com/hp/hpl/jena/sparql/engine/iterator/ src/org/openjena/riot/out/
Date Thu, 22 Sep 2011 11:28:12 GMT
Author: andy
Date: Thu Sep 22 11:28:12 2011
New Revision: 1174067

URL: http://svn.apache.org/viewvc?rev=1174067&view=rev
Log:
Fix BindingOutputStream to write using a NodeFormatter.

Modified:
    incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java
    incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
    incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/iterator/QueryIterTriplePattern.java
    incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFmtLib.java
    incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java

Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/DevARQ.java Thu Sep 22 11:28:12 2011
@@ -3,6 +3,7 @@ package dev ;
 
 public class DevARQ
 {
+    // NodeFmtLib to use a NodeFormatter.
     // BIO: RS = vars list and the bindings.
     
     // Assembly configuration: <appendAssemblyId>false</appendAssemblyId>

Modified: incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src-dev/dev/RunARQ.java Thu Sep 22 11:28:12 2011
@@ -8,6 +8,8 @@
 
 package dev;
 
+import java.io.ByteArrayInputStream ;
+import java.io.ByteArrayOutputStream ;
 import java.io.FileInputStream ;
 import java.io.InputStream ;
 import java.util.Iterator ;
@@ -28,6 +30,7 @@ import org.openjena.riot.ErrorHandlerFac
 import org.openjena.riot.RiotReader ;
 import org.openjena.riot.checker.CheckerIRI ;
 import org.openjena.riot.pipeline.normalize.CanonicalizeLiteral ;
+import org.openjena.riot.system.PrefixMap ;
 import org.openjena.riot.tokens.Token ;
 import org.openjena.riot.tokens.Tokenizer ;
 import org.openjena.riot.tokens.TokenizerFactory ;
@@ -49,7 +52,6 @@ import com.hp.hpl.jena.query.QueryFactor
 import com.hp.hpl.jena.query.QuerySolutionMap ;
 import com.hp.hpl.jena.query.ResultSet ;
 import com.hp.hpl.jena.query.ResultSetFormatter ;
-import com.hp.hpl.jena.rdf.model.AnonId ;
 import com.hp.hpl.jena.rdf.model.Model ;
 import com.hp.hpl.jena.rdf.model.ModelFactory ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
@@ -123,6 +125,32 @@ public class RunARQ
     @SuppressWarnings("deprecation")
     public static void main(String[] argv) throws Exception
     {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        Binding b = BindingFactory.create();
+        b.add(Var.alloc("test"), Node.createLiteral("21", null, XSDDatatype.XSDint));
+
+        PrefixMap pmap = new PrefixMap() ;
+        pmap.add("xsd",  XSDDatatype.XSD+"#") ;
+        
+        BindingOutputStream bos = new BindingOutputStream(baos, pmap);
+        bos.write(b);
+        bos.flush() ;
+
+        String x = baos.toString() ;
+        System.out.print(x) ;
+
+        bos.close();
+
+        BindingInputStream bis =
+                new BindingInputStream(new ByteArrayInputStream(
+                        baos.toByteArray()));
+
+        System.out.println(bis.next());
+        exit(0) ;
+
+        
+        
         arq.sparql.main("--data=D.ttl", "--query=Q1.rq") ;
         exit(0) ;
         
@@ -146,7 +174,8 @@ public class RunARQ
         Query q = QueryFactory.create("PREFIX ex: <http://example/ns#> SELECT * { FILTER
ex:wait(100) }") ;
         QueryExecution qExec = QueryExecutionFactory.create(q, ModelFactory.createDefaultModel())
;
         
-        try {
+        try {        exit(0) ;
+
             ResultSet rs = qExec.execSelect() ;
             System.out.println(rs.hasNext()) ;
             qExec.abort();
@@ -170,22 +199,6 @@ public class RunARQ
         Token t = tok.next() ;
         System.out.println(t) ;
         exit(0) ;
-        
-        // BNode I/O
-        Binding binding = BindingFactory.create() ;
-        binding.add(Var.alloc("x"), Node.createAnon(new AnonId("abc"))) ;
-        bout.write(binding) ;
-        bout.close() ;
-        exit(0) ;
-        
-        for ( ; bin.hasNext() ; )
-        {
-            Binding b = bin.next() ;
-            System.out.println(b) ;
-            bout.write(b) ;
-        }
-        bout.close() ;
-        exit(0) ;
     }
 
     public static void canoncialNodes()

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/binding/BindingOutputStream.java
Thu Sep 22 11:28:12 2011
@@ -27,13 +27,13 @@ import org.openjena.atlas.io.BufferingWr
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.lib.Sink ;
 import org.openjena.riot.RiotException ;
-import org.openjena.riot.out.NodeFmtLib ;
+import org.openjena.riot.out.NodeFormatter ;
+import org.openjena.riot.out.NodeFormatterTTL ;
 import org.openjena.riot.system.PrefixMap ;
 
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.iri.IRI ;
 import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
 /** Parser for the RDF Tuples language */
 public class BindingOutputStream implements Sink<Binding>
@@ -42,6 +42,7 @@ public class BindingOutputStream impleme
     private Binding lastBinding = null ;
     private List<Var> vars = null ;
     private PrefixMap pmap ;
+    private NodeFormatter nodeFormatter ;
     private boolean needOutputPMap = true ;
     private boolean needOutputVars = true ;
     
@@ -70,8 +71,8 @@ public class BindingOutputStream impleme
         bw = out ;
         vars = variables ;
         pmap = prefixMapping ;
-        if ( pmap == null )
-            pmap = new PrefixMap() ;
+        
+        nodeFormatter = new NodeFormatterTTL(null, pmap) ;
         needOutputVars = (vars != null ) && vars.size() > 0 ;
     }
     
@@ -132,25 +133,8 @@ public class BindingOutputStream impleme
                     bw.write("- ") ;
                     continue ;
                 }
-                if ( n.isURI() && pmap != null )
-                {
-                    String x = pmap.abbreviate(n.getURI()) ;
-                    if ( x != null )
-                    {
-                        bw.write(x) ;
-                        bw.write(" ") ;
-                        continue ;
-                    }
-                }
-                
-                // Need fixing.
-                if ( n.isBlank() )
-                {
-                    bw.write("_:") ;
-                    bw.write(NodeFmtLib.encodeBNodeLabel(n.getBlankNodeLabel())) ;
-                }
-                else
-                    bw.write(FmtUtils.stringForNode(n)) ;
+                // NodeFormatters should write safe bNode labels.
+                nodeFormatter.format(bw, n) ;
                 bw.write(" ") ;
             }
             bw.write(".\n") ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/iterator/QueryIterTriplePattern.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/iterator/QueryIterTriplePattern.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/iterator/QueryIterTriplePattern.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/com/hp/hpl/jena/sparql/engine/iterator/QueryIterTriplePattern.java
Thu Sep 22 11:28:12 2011
@@ -169,8 +169,7 @@ public class QueryIterTriplePattern exte
         @Override
         protected void requestCancel()
         {
-            // The QuryIteratorBase machinary will do the real work.
-            // but we cleanly kill the ExtendedIterator.
+            // The QueryIteratorBase machinary will do the real work.
             cancelled = true ;
         }
     }

Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFmtLib.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFmtLib.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFmtLib.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFmtLib.java Thu Sep 22 11:28:12
2011
@@ -24,6 +24,9 @@ import com.hp.hpl.jena.sparql.util.FmtUt
 
 public class NodeFmtLib
 {
+    // TODO Switch to using NodeFormatter.
+    
+    
     // FmtUtils: This writes abbreviated bnodes (_:b0 etc)
     // These utilities are lower level and reflect the bNodes label.
     

Modified: incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java?rev=1174067&r1=1174066&r2=1174067&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/org/openjena/riot/out/NodeFormatterTTL.java Thu Sep
22 11:28:12 2011
@@ -40,8 +40,11 @@ public class NodeFormatterTTL extends No
     
    public NodeFormatterTTL(String baseIRI , PrefixMap prefixMap) //OutputPolicy outputPolicy)
     {
+       if ( prefixMap == null )
+           prefixMap = new PrefixMap() ;
        this.prefixMap = prefixMap ;
        this.baseIRI = baseIRI ;
+       
     }
     
     @Override



Mime
View raw message