commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/2] incubator-commonsrdf git commit: Explicit ntriples generation
Date Fri, 24 Apr 2015 16:04:32 GMT
Repository: incubator-commonsrdf
Updated Branches:
  refs/heads/master 22ec3b143 -> f932db7fb


Explicit ntriples generation

.. instead of relying on Triple.toString()

(This is not used for anything, just a test for fun and
to show how easy it is)


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/c35631a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/c35631a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/c35631a4

Branch: refs/heads/master
Commit: c35631a4d5422a848a8b5c72a7cc4db2caddc72e
Parents: 22ec3b1
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Fri Apr 24 16:05:18 2015 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Fri Apr 24 16:05:18 2015 +0100

----------------------------------------------------------------------
 .../commons/rdf/simple/TestWritingGraph.java    | 25 +++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/c35631a4/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
----------------------------------------------------------------------
diff --git a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
index ecb208d..3818e22 100644
--- a/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
+++ b/simple/src/test/java/org/apache/commons/rdf/simple/TestWritingGraph.java
@@ -17,12 +17,7 @@
  */
 package org.apache.commons.rdf.simple;
 
-import org.apache.commons.rdf.api.Graph;
-import org.apache.commons.rdf.api.IRI;
-import org.apache.commons.rdf.api.RDFTermFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
 import java.nio.charset.Charset;
 import java.nio.file.Files;
@@ -32,7 +27,13 @@ import java.util.Collections;
 import java.util.List;
 import java.util.stream.Stream;
 
-import static org.junit.Assert.assertEquals;
+import org.apache.commons.rdf.api.Graph;
+import org.apache.commons.rdf.api.IRI;
+import org.apache.commons.rdf.api.RDFTermFactory;
+import org.apache.commons.rdf.api.Triple;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * Test writing graph
@@ -106,6 +107,12 @@ public class TestWritingGraph {
         assertEquals(count, TRIPLES);
     }
 
+    public static String tripleAsString(Triple t) {
+        return t.getSubject().ntriplesString() + " "
+                + t.getPredicate().ntriplesString() + " " +
+                t.getObject().ntriplesString() + " .";
+    }
+
     @Test
     public void writeGraphFromStream() throws Exception {
         Path graphFile = Files.createTempFile("graph", ".nt");
@@ -115,7 +122,7 @@ public class TestWritingGraph {
             graphFile.toFile().deleteOnExit();
         }
 
-        Stream<CharSequence> stream = graph.getTriples().map(Object::toString);
+        Stream<CharSequence> stream = graph.getTriples().map(TestWritingGraph::tripleAsString);
         Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
     }
 
@@ -131,7 +138,7 @@ public class TestWritingGraph {
         IRI subject = factory.createIRI("subj");
         IRI predicate = factory.createIRI("pred");
         Stream<CharSequence> stream = graph
-                .getTriples(subject, predicate, null).map(Object::toString);
+                .getTriples(subject, predicate, null).map(TestWritingGraph::tripleAsString);
         Files.write(graphFile, stream::iterator, Charset.forName("UTF-8"));
 
     }


Mime
View raw message