jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1453469 - in /jena/branches/arq-riot-output/src: main/java/org/apache/jena/riot/ main/java/org/apache/jena/riot/lang/ main/java/org/apache/jena/riot/process/inf/ main/java/org/apache/jena/riot/system/ main/java/org/apache/jena/riot/writer/...
Date Wed, 06 Mar 2013 18:38:09 GMT
Author: andy
Date: Wed Mar  6 18:38:09 2013
New Revision: 1453469

URL: http://svn.apache.org/r1453469
Log:
Convert command line parsing tool to use StreamRDF.
Convert command line inference tool to use StreamRDF.
Rename RDFParserOuputCounts as StreamRDFCounting.


Added:
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java
      - copied, changed from r1452591, jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/RDFParserOutputCounting.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorStreamRDF.java
Removed:
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/RDFParserOutputCounting.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorQuads.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorTriples.java
Modified:
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFDataMgr.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InfFactory.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorRDFS.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
    jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
    jena/branches/arq-riot-output/src/main/java/riotcmd/CmdLangParse.java
    jena/branches/arq-riot-output/src/main/java/riotcmd/infer.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNQuads.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
    jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangRdfJson.java

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFDataMgr.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFDataMgr.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFDataMgr.java (original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/RDFDataMgr.java Wed Mar
 6 18:38:09 2013
@@ -658,6 +658,17 @@ public class RDFDataMgr
      * @param in        Bytes to read.
      * @param base      Base URI (defaults to uri).
      * @param hintLang  Hint for the syntax
+     */
+    public static void parse(StreamRDF sink, InputStream in, String base, Lang hintLang)
+    {
+        parse(sink, in, base, hintLang, null) ;  
+    }
+
+    /** Read RDF data.
+     * @param sink      Destination for the RDF read.
+     * @param in        Bytes to read.
+     * @param base      Base URI (defaults to uri).
+     * @param hintLang  Hint for the syntax
      * @param context   Content object to control reading process.
      */
     public static void parse(StreamRDF sink, InputStream in, String base, Lang hintLang,
Context context)

Copied: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java
(from r1452591, jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/RDFParserOutputCounting.java)
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java?p2=jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java&p1=jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/RDFParserOutputCounting.java&r1=1452591&r2=1453469&rev=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/RDFParserOutputCounting.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java
Wed Mar  6 18:38:09 2013
@@ -20,7 +20,7 @@ package org.apache.jena.riot.lang;
 
 import org.apache.jena.riot.system.StreamRDF ;
 
-public interface RDFParserOutputCounting extends StreamRDF
+public interface StreamRDFCounting extends StreamRDF
 {
     /** Count of triples, quads or tuples */
     public long count() ;

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InfFactory.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InfFactory.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InfFactory.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InfFactory.java
Wed Mar  6 18:38:09 2013
@@ -18,33 +18,20 @@
 
 package org.apache.jena.riot.process.inf;
 
-import org.apache.jena.atlas.lib.Sink ;
+import org.apache.jena.riot.system.StreamRDF ;
 
-import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.sparql.core.Quad ;
 
 public class InfFactory
 {
-    public static Sink<Triple> infTriples(Sink<Triple> sink, Model vocab)
+    public static StreamRDF inf(StreamRDF data, Model vocab)
     {
         InferenceSetupRDFS setup =  new InferenceSetupRDFS(vocab) ;
-        return new InferenceProcessorTriples(sink, setup) ; 
+        return new InferenceProcessorStreamRDF(data, setup) ; 
     }
     
-    public static Sink<Quad> infQuads(Sink<Quad> sink, Model vocab)
+    public static StreamRDF inf(StreamRDF data, InferenceSetupRDFS setup)
     {
-        InferenceSetupRDFS setup =  new InferenceSetupRDFS(vocab) ;
-        return new InferenceProcessorQuads(sink, setup) ; 
-    }
-
-    public static Sink<Triple> infTriples(Sink<Triple> sink, InferenceSetupRDFS
setup)
-    {
-        return new InferenceProcessorTriples(sink, setup) ; 
-    }
-    
-    public static Sink<Quad> infQuads(Sink<Quad> sink, InferenceSetupRDFS setup)
-    {
-        return new InferenceProcessorQuads(sink, setup) ; 
+        return new InferenceProcessorStreamRDF(data, setup) ; 
     }
 }

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorRDFS.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorRDFS.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorRDFS.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorRDFS.java
Wed Mar  6 18:38:09 2013
@@ -37,7 +37,6 @@ import com.hp.hpl.jena.vocabulary.RDF ;
  *  Usage: call process(Node, Node, Node), outputs to derive(Node, Node, Node).
  */
 
-
 abstract class InferenceProcessorRDFS
 {
     // Calculates hierarchies (subclass, subproperty) from a model.

Added: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorStreamRDF.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorStreamRDF.java?rev=1453469&view=auto
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorStreamRDF.java
(added)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/process/inf/InferenceProcessorStreamRDF.java
Wed Mar  6 18:38:09 2013
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.riot.process.inf;
+
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFWrapper ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/** Receive triples and quads (incoming because this is a StreamRDF);
+ *  allow RDFS; output to place provided. 
+ */
+public class InferenceProcessorStreamRDF extends StreamRDFWrapper
+{
+    private final InferenceSetupRDFS rdfsSetup ;
+    private final InferenceProcessorRDFS rdfs ;
+    private boolean isTriple = true ;
+    private Node g ;
+
+    public InferenceProcessorStreamRDF(final StreamRDF output, InferenceSetupRDFS rdfsSetup)
+    {
+        super(output) ;
+        this.rdfsSetup = rdfsSetup ;
+        this.rdfs = new InferenceProcessorRDFS(rdfsSetup)
+        {
+            @Override
+            public void derive(Node s, Node p, Node o)
+            {
+                if ( isTriple )
+                    output.triple(Triple.create(s,p,o)) ;
+                else
+                    output.quad(Quad.create(g,s,p,o)) ;
+            }
+        } ;
+    }
+    
+    @Override
+    public void triple(Triple triple)
+    { 
+        super.triple(triple) ;
+        isTriple = true ;
+        g = null ;
+        rdfs.process(triple.getSubject(), triple.getPredicate(), triple.getObject()) ;
+    }
+
+    @Override
+    public void quad(Quad quad)
+    {
+        super.quad(quad) ;
+        isTriple = false ;
+        g = quad.getGraph() ;
+        rdfs.process(quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
+    }
+    
+}
+

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
Wed Mar  6 18:38:09 2013
@@ -18,11 +18,14 @@
 
 package org.apache.jena.riot.system;
 
+import java.io.OutputStream ;
+import java.io.Writer ;
 import java.util.Iterator ;
 
 import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.atlas.lib.Tuple ;
-import org.apache.jena.riot.lang.RDFParserOutputCounting ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
+import org.apache.jena.riot.writer.WriterStreamRDFTuples ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
@@ -36,11 +39,14 @@ public class StreamRDFLib
     /** Send everything to nowhere ... efficiently */
     public static StreamRDF sinkNull()                       { return new StreamRDFBase()
; }
 
+    public static StreamRDF writer(OutputStream out)         { return new WriterStreamRDFTuples(out)
; }
+    public static StreamRDF writer(Writer out)               { return new WriterStreamRDFTuples(out)
; }
+
     public static StreamRDF graph(Graph graph)               { return new ParserOutputGraph(graph)
; }
     
     public static StreamRDF dataset(DatasetGraph dataset)    { return new ParserOutputDataset(dataset)
; }
     
-    /** Set triples to a StreamRDF - does not all .start/.finish */ 
+    /** Set triples to a StreamRDF - does not call .start/.finish */ 
     public static void triplesToStream(StreamRDF dest, Iterator<Triple> iter)
     {
         for ( ; iter.hasNext() ; )
@@ -50,7 +56,7 @@ public class StreamRDFLib
         }
     }
 
-    /** Set quads to a StreamRDF - does not all .start/.finish */ 
+    /** Set quads to a StreamRDF - does not call .start/.finish */ 
     public static void quadsToStream(StreamRDF dest, Iterator<Quad> iter)
     {
         for ( ; iter.hasNext() ; )
@@ -59,7 +65,6 @@ public class StreamRDFLib
             dest.quad(q) ;
         }
     }
-
     
     /** 
      * Output to a sink; prefix and base handled only within the parser.
@@ -83,11 +88,11 @@ public class StreamRDFLib
     public static StreamRDF extendTriplesToQuads(Node graphNode, StreamRDF base)
     { return new ParserOutputSinkTriplesToQuads(graphNode, base) ; }
     
-    public static RDFParserOutputCounting count()
-    { return new ParserOutputCountingBase(sinkNull()) ; }
+    public static StreamRDFCounting count()
+    { return new StreamRDFCountingBase(sinkNull()) ; }
 
-    public static RDFParserOutputCounting count(StreamRDF other)
-    { return new ParserOutputCountingBase(other) ; }
+    public static StreamRDFCounting count(StreamRDF other)
+    { return new StreamRDFCountingBase(other) ; }
 
     private static class ParserOutputSinkTriplesToQuads extends StreamRDFWrapper
     {
@@ -192,7 +197,7 @@ public class StreamRDFLib
         }
     }
 
-    private  static class ParserOutputCountingBase extends StreamRDFWrapper implements StreamRDF,
RDFParserOutputCounting
+    private  static class StreamRDFCountingBase extends StreamRDFWrapper implements StreamRDF,
StreamRDFCounting
     {
         private long countTriples = 0 ;
         private long countQuads = 0 ;
@@ -200,7 +205,7 @@ public class StreamRDFLib
         private long countBase = 0 ;
         private long countPrefixes = 0 ;
         
-        public ParserOutputCountingBase (StreamRDF other)     { super(other) ; }
+        public StreamRDFCountingBase (StreamRDF other)     { super(other) ; }
 
         @Override
         public void triple(Triple triple)

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NQuadsWriter.java
Wed Mar  6 18:38:09 2013
@@ -35,7 +35,7 @@ public class NQuadsWriter extends Writer
 {
     public static void write(OutputStream out, Iterator<Quad> iter)
     {
-        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDF s = StreamRDFLib.writer(out) ;
         s.start() ;
         StreamRDFLib.quadsToStream(s, iter) ;
         s.finish();
@@ -43,7 +43,7 @@ public class NQuadsWriter extends Writer
     
     public static void write(Writer out, Iterator<Quad> iter)
     {
-        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDF s = StreamRDFLib.writer(out) ;
         s.start() ;
         StreamRDFLib.quadsToStream(s, iter) ;
         s.finish();

Modified: jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
(original)
+++ jena/branches/arq-riot-output/src/main/java/org/apache/jena/riot/writer/NTriplesWriter.java
Wed Mar  6 18:38:09 2013
@@ -35,7 +35,7 @@ public class NTriplesWriter extends Writ
 {
     public static void write(OutputStream out, Iterator<Triple> iter)
     {
-        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDF s = StreamRDFLib.writer(out) ;
         s.start() ;
         StreamRDFLib.triplesToStream(s, iter) ;
         s.finish();
@@ -43,7 +43,7 @@ public class NTriplesWriter extends Writ
     
     public static void write(Writer out, Iterator<Triple> iter)
     {
-        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDF s = StreamRDFLib.writer(out) ;
         s.start() ;
         StreamRDFLib.triplesToStream(s, iter) ;
         s.finish();

Modified: jena/branches/arq-riot-output/src/main/java/riotcmd/CmdLangParse.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/riotcmd/CmdLangParse.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/riotcmd/CmdLangParse.java (original)
+++ jena/branches/arq-riot-output/src/main/java/riotcmd/CmdLangParse.java Wed Mar  6 18:38:09
2013
@@ -27,16 +27,12 @@ import java.util.Map ;
 import java.util.Properties ;
 
 import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.Sink ;
-import org.apache.jena.atlas.lib.SinkCounting ;
-import org.apache.jena.atlas.lib.SinkNull ;
 import org.apache.jena.atlas.lib.StrUtils ;
 import org.apache.jena.riot.* ;
 import org.apache.jena.riot.lang.LabelToNode ;
 import org.apache.jena.riot.lang.LangRIOT ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
 import org.apache.jena.riot.out.NodeToLabel ;
-import org.apache.jena.riot.out.SinkQuadOutput ;
-import org.apache.jena.riot.out.SinkTripleOutput ;
 import org.apache.jena.riot.process.inf.InfFactory ;
 import org.apache.jena.riot.process.inf.InferenceSetupRDFS ;
 import org.apache.jena.riot.system.* ;
@@ -47,9 +43,7 @@ import arq.cmd.CmdException ;
 import arq.cmdline.* ;
 
 import com.hp.hpl.jena.Jena ;
-import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.query.ARQ ;
-import com.hp.hpl.jena.sparql.core.Quad ;
 
 /** Common framework for running RIOT parsers */
 public abstract class CmdLangParse extends CmdGeneral
@@ -271,44 +265,20 @@ public abstract class CmdLangParse exten
         // Also, as URI.
         final boolean labelsAsGiven = false ;
         
-        SinkCounting<?> sink ;
-        LangRIOT parser ;
-        
         NodeToLabel labels = SyntaxLabels.createNodeToLabel() ;
         if ( labelsAsGiven )
             labels = NodeToLabel.createBNodeByLabelEncoded() ;
         
-        // Uglyness because quads and triples aren't subtype of some Tuple<Node>
-        // Replace with StreamRDF all the way through.
-        
-        if ( RDFLanguages.isTriples(lang) )
-        {
-            Sink<Triple> s = SinkNull.create() ;
-            if ( ! modLangParse.toBitBucket() )
-                s = new SinkTripleOutput(output, null, labels) ;
-            if ( setup != null )
-                s = InfFactory.infTriples(s, setup) ;
-            
-            SinkCounting<Triple> sink2 = new SinkCounting<Triple>(s) ;
-            StreamRDF dest = StreamRDFLib.sinkTriples(sink2) ;
-            parser = RiotReader.createParser(in, lang, baseURI, dest) ;
-            
-            sink = sink2 ;
-        }
-        else
-        {
-            Sink <Quad> s = SinkNull.create() ;
-            if ( ! modLangParse.toBitBucket() )
-                s = new SinkQuadOutput(output, null, labels) ;
-            if ( setup != null )
-                s = InfFactory.infQuads(s, setup) ;
-            
-            SinkCounting<Quad> sink2 = new SinkCounting<Quad>(s) ;
-            StreamRDF dest = StreamRDFLib.sinkQuads(sink2) ;
-            parser = RiotReader.createParser(in, lang, baseURI, dest) ;
-            sink = sink2 ;
-        }
+        StreamRDF s = StreamRDFLib.sinkNull() ;
+        if ( ! modLangParse.toBitBucket() )
+            s = StreamRDFLib.writer(output) ;
+        if ( setup != null )
+            s = InfFactory.inf(s, setup) ;
+        StreamRDFCounting sink = StreamRDFLib.count(s) ;
+        s = null ;
         
+        // Need low level control over the parser.
+        LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ;
         try
         {
             if ( checking )
@@ -323,7 +293,6 @@ public abstract class CmdLangParse exten
             
             if ( labelsAsGiven )
                 parser.getProfile().setLabelToNode(LabelToNode.createUseLabelAsGiven()) ;
-            
             modTime.startTimer() ;
             parser.parse() ;
         }
@@ -336,12 +305,12 @@ public abstract class CmdLangParse exten
                 return ;
         }
         finally {
-            IO.close(in) ;
             // Not close - we may write again to the underlying output stream in another
call to parse a file.  
-            sink.flush() ;
+            sink.finish() ;
+            IO.close(in) ;
         }
         long x = modTime.endTimer() ;
-        long n = sink.getCount() ;
+        long n = sink.countTriples()+sink.countQuads() ;
 
         if ( modTime.timingEnabled() )
             output(filename, n, x, handler) ;

Modified: jena/branches/arq-riot-output/src/main/java/riotcmd/infer.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/main/java/riotcmd/infer.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/main/java/riotcmd/infer.java (original)
+++ jena/branches/arq-riot-output/src/main/java/riotcmd/infer.java Wed Mar  6 18:38:09 2013
@@ -18,17 +18,12 @@
 
 package riotcmd;
 
-import java.io.InputStream ;
 import java.util.List ;
 
 import org.apache.jena.atlas.io.IO ;
-import org.apache.jena.atlas.lib.IRILib ;
-import org.apache.jena.atlas.lib.Sink ;
 import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
 import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.RiotReader ;
-import org.apache.jena.riot.lang.LangRIOT ;
-import org.apache.jena.riot.out.SinkQuadOutput ;
 import org.apache.jena.riot.process.inf.InfFactory ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.system.StreamRDFLib ;
@@ -37,7 +32,6 @@ import arq.cmdline.ArgDecl ;
 import arq.cmdline.CmdGeneral ;
 
 import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.util.FileManager ;
 
 /*
@@ -130,8 +124,8 @@ public class infer extends CmdGeneral
     @Override
     protected void exec()
     {
-        Sink<Quad> sink = new SinkQuadOutput(System.out) ;
-        sink = InfFactory.infQuads(sink, vocab) ;
+        StreamRDF sink = StreamRDFLib.writer(System.out) ;
+        sink = InfFactory.inf(sink, vocab) ;
         
         List<String> files = getPositionalOrStdin() ;
         if ( files.isEmpty() )
@@ -142,26 +136,14 @@ public class infer extends CmdGeneral
         IO.flush(System.out); 
     }
 
-    private void processFile(String filename, Sink<Quad> qsink)
+    private void processFile(String filename, StreamRDF sink)
     {
         Lang lang = filename.equals("-") ? RDFLanguages.NQUADS : RDFLanguages.filenameToLang(filename,
RDFLanguages.NQUADS) ;
-        String baseURI = IRILib.filenameToIRI(filename) ;
-        StreamRDF sink = StreamRDFLib.sinkQuads(qsink) ;
-        
-        if ( RDFLanguages.isTriples(lang) )
-        {
-            InputStream in = IO.openFile(filename) ;
-            sink = StreamRDFLib.extendTriplesToQuads(sink) ;
-            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ;
-            parser.parse() ;
-            return ;
-        }
+
+        if ( filename.equals("-") )
+            RDFDataMgr.parse(sink, System.in, null, RDFLanguages.NQUADS, null) ;
         else
-        {
-            InputStream in = IO.openFile(filename) ;
-            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ; 
-            parser.parse() ;
-        }        
+            RDFDataMgr.parse(sink, filename) ;
     }
 
     @Override

Modified: jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNQuads.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNQuads.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNQuads.java
(original)
+++ jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNQuads.java
Wed Mar  6 18:38:09 2013
@@ -21,7 +21,7 @@ package org.apache.jena.riot.lang;
 import org.apache.jena.riot.RiotReader ;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExFatal ;
 import org.apache.jena.riot.lang.LangRIOT ;
-import org.apache.jena.riot.lang.RDFParserOutputCounting ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.system.StreamRDFLib ;
 import org.apache.jena.riot.tokens.Tokenizer ;
@@ -75,7 +75,7 @@ public class TestLangNQuads extends Test
     @Override
     protected long parseCount(String... strings)
     {
-        RDFParserOutputCounting sink = StreamRDFLib.count() ;
+        StreamRDFCounting sink = StreamRDFLib.count() ;
         parse(sink, strings) ;
         return sink.count() ;
     }

Modified: jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
(original)
+++ jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTriples.java
Wed Mar  6 18:38:09 2013
@@ -95,7 +95,7 @@ public class TestLangNTriples extends Te
     {
         String string = StrUtils.strjoin("\n", strings) ;
         Tokenizer tokenizer = tokenizer(string) ;
-        RDFParserOutputCounting sink = StreamRDFLib.count() ;
+        StreamRDFCounting sink = StreamRDFLib.count() ;
         LangNTriples x = RiotReader.createParserNTriples(tokenizer, sink) ;
         x.getProfile().setHandler(new ErrorHandlerEx()) ;
         x.parse() ;

Modified: jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
(original)
+++ jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangNTuples.java
Wed Mar  6 18:38:09 2013
@@ -29,7 +29,7 @@ import org.apache.jena.riot.ErrorHandler
 import org.apache.jena.riot.ErrorHandlerTestLib.ExFatal ;
 import org.apache.jena.riot.ErrorHandlerTestLib.ExWarning ;
 import org.apache.jena.riot.lang.LangRIOT ;
-import org.apache.jena.riot.lang.RDFParserOutputCounting ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
 import org.apache.jena.riot.system.RiotLib ;
 import org.apache.jena.riot.system.StreamRDF ;
 import org.apache.jena.riot.system.StreamRDFLib ;
@@ -182,7 +182,7 @@ abstract public class TestLangNTuples ex
     {
         String string = StrUtils.strjoin("\n", strings) ;
         Tokenizer tokenizer = tokenizer(string) ;
-        RDFParserOutputCounting sink = StreamRDFLib.count() ;
+        StreamRDFCounting sink = StreamRDFLib.count() ;
         LangRIOT x = RiotReader.createParserNQuads(tokenizer, sink) ;
         x.setProfile(RiotLib.profile(null, false, true, new ErrorHandlerEx())) ;
         x.parse() ;

Modified: jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangRdfJson.java
URL: http://svn.apache.org/viewvc/jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangRdfJson.java?rev=1453469&r1=1453468&r2=1453469&view=diff
==============================================================================
--- jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangRdfJson.java
(original)
+++ jena/branches/arq-riot-output/src/test/java/org/apache/jena/riot/lang/TestLangRdfJson.java
Wed Mar  6 18:38:09 2013
@@ -496,14 +496,14 @@ public class TestLangRdfJson extends Bas
 		byte b[] = StrUtils.asUTF8bytes("") ;
 		ByteArrayInputStream in = new ByteArrayInputStream(b);
 		Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(in) ;
-        RDFParserOutputCounting sink = StreamRDFLib.count() ;
+        StreamRDFCounting sink = StreamRDFLib.count() ;
 		LangRDFJSON parser = RiotReader.createParserRdfJson(tokenizer, sink) ;
 	}
 
     private long parseCount(String string)
     {
         Tokenizer tokenizer = tokenizer(string) ;
-        RDFParserOutputCounting sink = StreamRDFLib.count() ;
+        StreamRDFCounting sink = StreamRDFLib.count() ;
         LangRDFJSON x = RiotReader.createParserRdfJson(tokenizer, sink) ;
         x.getProfile().setHandler(new ErrorHandlerEx()) ;
         x.parse() ;



Mime
View raw message