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 2014/06/12 15:16:20 UTC

svn commit: r1602155 - in /jena/trunk/jena-arq/src: main/java/org/apache/jena/riot/lang/ main/java/org/apache/jena/riot/system/ test/java/org/apache/jena/riot/system/

Author: andy
Date: Thu Jun 12 13:16:20 2014
New Revision: 1602155

URL: http://svn.apache.org/r1602155
Log:
Make public a counting StreamRDF implementation.

Added:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java   (with props)
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java   (with props)
Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java?rev=1602155&r1=1602154&r2=1602155&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/lang/StreamRDFCounting.java Thu Jun 12 13:16:20 2014
@@ -20,6 +20,7 @@ package org.apache.jena.riot.lang;
 
 import org.apache.jena.riot.system.StreamRDF ;
 
+/** Provide counts of triples/quads/tuples */
 public interface StreamRDFCounting extends StreamRDF
 {
     /** Count of triples, quads or tuples */

Added: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java?rev=1602155&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java (added)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java Thu Jun 12 13:16:20 2014
@@ -0,0 +1,77 @@
+/**
+ * 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.system ;
+
+import org.apache.jena.atlas.lib.Tuple ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/** Wrap another StreamRDF and provide counts of items */
+public class StreamRDFCountingBase extends StreamRDFWrapper implements StreamRDF, StreamRDFCounting {
+    private long countTriples  = 0 ;
+    private long countQuads    = 0 ;
+    private long countTuples   = 0 ;
+    private long countBase     = 0 ;
+    private long countPrefixes = 0 ;
+
+    public StreamRDFCountingBase(StreamRDF other) {
+        super(other) ;
+    }
+
+    @Override
+    public void triple(Triple triple) {
+        countTriples++ ;
+        super.triple(triple) ;
+    }
+
+    @Override
+    public void quad(Quad quad) {
+        countQuads++ ;
+        super.quad(quad) ;
+    }
+
+    @Override
+    public void tuple(Tuple<Node> tuple) {
+        countTuples++ ;
+        super.tuple(tuple) ;
+    }
+
+    @Override
+    public long count() {
+        return countTriples + countQuads + countTuples ;
+    }
+
+    @Override
+    public long countTriples() {
+        return countTriples ;
+    }
+
+    @Override
+    public long countQuads() {
+        return countQuads ;
+    }
+
+    @Override
+    public long countTuples() {
+        return countTuples ;
+    }
+}

Propchange: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFCountingBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java?rev=1602155&r1=1602154&r2=1602155&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/StreamRDFLib.java Thu Jun 12 13:16:20 2014
@@ -25,7 +25,6 @@ import java.util.Iterator ;
 import org.apache.jena.atlas.io.AWriter ;
 import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.atlas.lib.Sink ;
-import org.apache.jena.atlas.lib.Tuple ;
 import org.apache.jena.riot.lang.StreamRDFCounting ;
 import org.apache.jena.riot.out.CharSpace;
 import org.apache.jena.riot.writer.WriterStreamRDFTuples ;
@@ -234,60 +233,4 @@ public class StreamRDFLib
             } catch (JenaException ex) {}
         }
     }
-
-    private  static class StreamRDFCountingBase extends StreamRDFWrapper implements StreamRDF, StreamRDFCounting
-    {
-        private long countTriples = 0 ;
-        private long countQuads = 0 ;
-        private long countTuples = 0 ;
-        private long countBase = 0 ;
-        private long countPrefixes = 0 ;
-        
-        public StreamRDFCountingBase (StreamRDF other)     { super(other) ; }
-
-        @Override
-        public void triple(Triple triple)
-        {
-            countTriples++ ;
-            super.triple(triple) ;
-        }
-
-        @Override
-        public void quad(Quad quad)
-        {
-            countQuads++ ;
-            super.quad(quad) ;
-        }
-
-        @Override
-        public void tuple(Tuple<Node> tuple)
-        {
-            countTuples++ ;
-            super.tuple(tuple) ;
-        }
-        
-        @Override
-        public long count()
-        {
-            return countTriples + countQuads + countTuples ;
-        }
-
-        @Override
-        public long countTriples()
-        {
-            return countTriples ;
-        }
-
-        @Override
-        public long countQuads()
-        {
-            return countQuads ;
-        }
-
-        @Override
-        public long countTuples()
-        {
-            return countTuples ;
-        }
-    }
 }
\ No newline at end of file

Modified: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java?rev=1602155&r1=1602154&r2=1602155&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java (original)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TS_RiotSystem.java Thu Jun 12 13:16:20 2014
@@ -29,7 +29,7 @@ import org.junit.runners.Suite.SuiteClas
 @RunWith(Suite.class)
 @SuiteClasses({ 
     TestChecker.class
-    
+    , TestStreamRDF.class
     // Prefix Map implementations
     , TestPrefixMap.class
     , TestPrefixMapWrapper.class

Added: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java?rev=1602155&view=auto
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java (added)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java Thu Jun 12 13:16:20 2014
@@ -0,0 +1,64 @@
+/**
+ * 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.system;
+
+import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.riot.lang.StreamRDFCounting ;
+import org.junit.Test ;
+
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+
+public class TestStreamRDF extends BaseTest {
+    private static Triple triple1 = SSE.parseTriple("(<s> <p> <o>)") ;
+    private static Quad quad1 = SSE.parseQuad("(<g> <s> <p> <o>)") ;
+    
+    
+    @Test public void stream_count_01() {
+        StreamRDFCounting stream = StreamRDFLib.count() ;
+        stream.start();
+        assertEquals(0, stream.count()) ;
+        stream.triple(triple1) ;
+        assertEquals(1, stream.count()) ;
+        stream.triple(triple1) ;
+        assertEquals(2, stream.count()) ;
+        stream.finish() ;
+        
+        assertEquals(2, stream.count()) ;
+        assertEquals(2, stream.countTriples()) ;
+        assertEquals(0, stream.countQuads()) ;
+        assertEquals(0, stream.countTuples()) ;
+    }
+    
+    @Test public void stream_count_02() {
+        StreamRDFCounting stream = StreamRDFLib.count() ;
+        stream.start();
+        stream.triple(triple1) ;
+        stream.quad(quad1) ;
+        
+        assertEquals(2, stream.count()) ;
+        assertEquals(1, stream.countTriples()) ;
+        assertEquals(1, stream.countQuads()) ;
+        assertEquals(0, stream.countTuples()) ;
+        
+        stream.finish();
+    }
+}
+

Propchange: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/TestStreamRDF.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain