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 2013/02/09 21:01:45 UTC
svn commit: r1444417 [2/2] - in /jena/Experimental/riot-output:
src/main/java/dev/ src/main/java/riot/ src/main/java/riot/adpaters/
src/main/java/riot/system/ src/main/java/riot/writer/
src/test/java/riot/writer/ testing/RIOT/Writer/
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/RDFJSONWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/RDFJSONWriter.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/RDFJSONWriter.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/RDFJSONWriter.java Sat Feb 9 20:01:44 2013
@@ -27,8 +27,11 @@ import java.util.Set ;
import org.apache.jena.atlas.lib.Pair ;
import org.apache.jena.atlas.lib.Sink ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
import org.apache.jena.riot.system.Prologue ;
import org.apache.jena.riot.system.SyntaxLabels ;
+import riot.WriterGraphRIOTBase ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.GraphUtil ;
@@ -36,23 +39,23 @@ import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.graph.Triple ;
import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
-public class RDFJSONWriter {
-
+public class RDFJSONWriter extends WriterGraphRIOTBase
+{
public RDFJSONWriter() {}
- public static void write (OutputStream out, Graph graph) {
+ public static void output(OutputStream out, Graph graph) {
Prologue prologue = Prologue.create(null, null) ; // (null, graph.getPrefixMapping()) ;
Sink<Pair<Node, Map<Node, Set<Node>>>> sink = new SinkEntityOutput(out, prologue, SyntaxLabels.createNodeToLabel()) ;
- write ( sink, graph ) ;
+ output( sink, graph ) ;
}
- public static void write (Writer out, Graph graph) {
+ public static void output(Writer out, Graph graph) {
Prologue prologue = Prologue.create(null, null) ; // (null, graph.getPrefixMapping()) ;
Sink<Pair<Node, Map<Node, Set<Node>>>> sink = new SinkEntityOutput(out, prologue, SyntaxLabels.createNodeToLabel()) ;
- write ( sink, graph ) ;
+ output( sink, graph ) ;
}
- private static void write (Sink<Pair<Node, Map<Node, Set<Node>>>> sink, Graph graph) {
+ private static void output(Sink<Pair<Node, Map<Node, Set<Node>>>> sink, Graph graph) {
ExtendedIterator<Node> subjects = GraphUtil.listSubjects(graph, Node.ANY, Node.ANY) ;
try {
Map<Node, Set<Node>> predicates = new HashMap<Node, Set<Node>>() ;
@@ -82,5 +85,23 @@ public class RDFJSONWriter {
sink.close() ;
}
}
+
+ @Override
+ public Lang getLang()
+ {
+ return Lang.RDFJSON ;
+ }
+
+ @Override
+ public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ output(out, graph) ;
+ }
+
+ @Override
+ public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ output(out, graph) ;
+ }
}
Added: jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLAbbrevWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLAbbrevWriter.java?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLAbbrevWriter.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLAbbrevWriter.java Sat Feb 9 20:01:44 2013
@@ -0,0 +1,60 @@
+/**
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import riot.WriterGraphRIOTBase ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.xmloutput.impl.Abbreviated ;
+
+/** Wrapper to the RDF/XML writer (preRIOT).
+ */
+
+public class RDFXMLAbbrevWriter extends WriterGraphRIOTBase
+{
+ private static RDFWriter create() { return new Abbreviated() ; }
+
+ @Override
+ public Lang getLang()
+ {
+ return Lang.RDFXML ;
+ }
+
+ @Override
+ public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ RDFWriter w = create() ;
+ w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+ }
+
+ @Override
+ public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ RDFWriter w = create() ;
+ w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+ }
+}
+
Added: jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLPlainWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLPlainWriter.java?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLPlainWriter.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLPlainWriter.java Sat Feb 9 20:01:44 2013
@@ -0,0 +1,60 @@
+/**
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import riot.WriterGraphRIOTBase ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.xmloutput.impl.Basic ;
+
+/** Wrapper to the RDF/XML writer (preRIOT).
+ */
+
+public class RDFXMLPlainWriter extends WriterGraphRIOTBase
+{
+ private static RDFWriter create() { return new Basic() ; }
+
+ @Override
+ public Lang getLang()
+ {
+ return Lang.RDFXML ;
+ }
+
+ @Override
+ public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ RDFWriter w = create() ;
+ w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+ }
+
+ @Override
+ public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ RDFWriter w = create() ;
+ w.write(ModelFactory.createModelForGraph(graph), out, baseURI) ;
+ }
+}
+
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriter.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriter.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriter.java Sat Feb 9 20:01:44 2013
@@ -18,97 +18,66 @@
package riot.writer;
-import java.io.OutputStream ;
import java.util.Iterator ;
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.query.Dataset ;
-import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
/** TriG pretty writer */
-public class TriGWriter extends TurtleShell
+public class TriGWriter extends TriGWriterBase
{
- public static final int GRAPH_INDENT = 4 ;
-
- public static void write(OutputStream out, Dataset dataset)
+ @Override
+ protected void output$(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI)
{
- PrefixMap pmap = PrefixMapFactory.create(dataset.getDefaultModel()) ;
- write(out, dataset.asDatasetGraph(), pmap, null) ;
- }
-
- public static void write(OutputStream out, DatasetGraph dsg)
- {
- PrefixMap prefixMap = PrefixMapFactory.create(dsg.getDefaultGraph().getPrefixMapping()) ;
- write(out, dsg, prefixMap, null) ;
- }
-
- public static void write(OutputStream out, DatasetGraph dsg, PrefixMap prefixMap, String baseURI)
- {
- IndentedWriter iOut = new IndentedWriter(out, false) ;
- TriGWriter w = new TriGWriter(iOut, prefixMap, baseURI) ;
+ TriGWriter$ w = new TriGWriter$(iOut, prefixMap, baseURI) ;
w.write(dsg) ;
- iOut.flush() ;
- }
-
- /** Write a model as the default graph of a dataset */
- public static void write(OutputStream out, Model model)
- {
- write(out, model.getGraph()) ;
- }
-
- public static void write(OutputStream out, Graph graph)
- {
- DatasetGraph dsg = DatasetGraphFactory.createOneGraph(graph) ;
- write(out, dsg) ;
}
-
- public TriGWriter(IndentedWriter out, PrefixMap prefixMap, String baseURI)
+ private static class TriGWriter$ extends TurtleShell
{
- super(out, prefixMap, baseURI) ;
- }
+ TriGWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI)
+ {
+ super(out, prefixMap, baseURI) ;
+ }
- private void write(DatasetGraph dsg)
- {
- writePrefixes(prefixMap) ;
- if ( ! prefixMap.isEmpty() && !dsg.isEmpty() )
- out.println() ;
-
- Iterator<Node> graphNames = dsg.listGraphNodes() ;
-
- writeGraph(null, dsg.getDefaultGraph()) ;
-
- for ( ; graphNames.hasNext() ; )
+ private void write(DatasetGraph dsg)
{
- out.println() ;
- Node gn = graphNames.next() ;
- writeGraph(gn, dsg.getGraph(gn)) ;
+ writePrefixes(prefixMap) ;
+ if ( ! prefixMap.isEmpty() && !dsg.isEmpty() )
+ out.println() ;
+
+ Iterator<Node> graphNames = dsg.listGraphNodes() ;
+
+ writeGraph(null, dsg.getDefaultGraph()) ;
+
+ for ( ; graphNames.hasNext() ; )
+ {
+ out.println() ;
+ Node gn = graphNames.next() ;
+ writeGraph(gn, dsg.getGraph(gn)) ;
+ }
}
- }
- private void writeGraph(Node name, Graph graph)
- {
- if ( name != null )
+ private void writeGraph(Node name, Graph graph)
{
- writeNode(name) ;
- out.print(" ") ;
+ if ( name != null )
+ {
+ writeNode(name) ;
+ out.print(" ") ;
+ }
+ out.println("{") ;
+ out.incIndent(WriterConst.INDENT_GRAPH) ;
+ // Pretty Turtle Writer.
+ writeGraphTTL(graph) ;
+
+ out.decIndent(WriterConst.INDENT_GRAPH) ;
+ out.ensureStartOfLine() ;
+ out.println("}") ;
}
- out.println("{") ;
- out.incIndent(GRAPH_INDENT) ;
- // Pretty Turtle Writer.
- writeGraphTTL(graph) ;
-
- out.decIndent(GRAPH_INDENT) ;
- out.ensureStartOfLine() ;
- out.println("}") ;
}
-
}
Added: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBase.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBase.java?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBase.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBase.java Sat Feb 9 20:01:44 2013
@@ -0,0 +1,59 @@
+/**
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import riot.WriterDatasetRIOTBase ;
+import riot.system.IndentedWriterWriter ;
+
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+
+/** TriG writer base class - ways to invoke a TriG writer */
+public abstract class TriGWriterBase extends WriterDatasetRIOTBase
+{
+ @Override
+ public Lang getLang()
+ {
+ return Lang.TRIG ;
+ }
+
+ @Override
+ public void write(Writer out, DatasetGraph dsg, PrefixMap prefixMap, String baseURI)
+ {
+ IndentedWriter iOut = IndentedWriterWriter.create(out) ;
+ output$(iOut, dsg, prefixMap, baseURI) ;
+ iOut.flush() ;
+ }
+
+ @Override
+ public void write(OutputStream out, DatasetGraph dsg, PrefixMap prefixMap, String baseURI)
+ {
+ IndentedWriter iOut = new IndentedWriter(out) ;
+ output$(iOut, dsg, prefixMap, baseURI) ;
+ iOut.flush() ;
+ }
+
+ protected abstract void output$(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI) ;
+}
+
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBlocks.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBlocks.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBlocks.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterBlocks.java Sat Feb 9 20:01:44 2013
@@ -18,50 +18,22 @@
package riot.writer;
-import java.io.OutputStream ;
-
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import org.apache.jena.riot.system.StreamRDF ;
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.query.Dataset ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
/** TriG writer that streams - print in blocks of quads clustered
* by adjacent same graph and same subject
*/
-public class TriGWriterBlocks
+public class TriGWriterBlocks extends TriGWriterBase
{
- public static void write(OutputStream out, Dataset dataset)
- {
- write(out, dataset.asDatasetGraph()) ;
- }
-
- public static void write(OutputStream out, DatasetGraph datasetGraph)
- {
- IndentedWriter iOut = new IndentedWriter(out) ;
- write(iOut, datasetGraph) ;
- }
-
- public static void write(OutputStream out, Graph graph)
- {
- DatasetGraph dsg = DatasetGraphFactory.createOneGraph(graph) ;
- write(out, dsg) ;
- }
-
- public static void write(IndentedWriter out, DatasetGraph datasetGraph)
- {
- PrefixMap pmap = PrefixMapFactory.create(datasetGraph.getDefaultGraph().getPrefixMapping()) ;
- write(out, datasetGraph, pmap, null) ;
- }
-
- public static void write(IndentedWriter out, DatasetGraph datasetGraph, PrefixMap prefixes, String baseURI)
+ @Override
+ protected void output$(IndentedWriter iOut, DatasetGraph dsg, PrefixMap prefixMap, String baseURI)
{
- StreamRDF dest = new WriterStreamRDFBlocks(out) ;
- WriterStreamBase.write(dest, datasetGraph, prefixes, baseURI) ;
+ StreamRDF dest = new WriterStreamRDFBlocks(iOut) ;
+ WriterStreamBase.write(dest, dsg, prefixMap, baseURI) ;
}
}
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java Sat Feb 9 20:01:44 2013
@@ -18,51 +18,23 @@
package riot.writer;
-import java.io.OutputStream ;
-
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import org.apache.jena.riot.system.StreamRDF ;
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.query.Dataset ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
-import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
/** TriG writer that writes quads one per line
* in TriG form with prefixes and short form literals (e.g. integers)
*/
-public class TriGWriterFlat
+public class TriGWriterFlat extends TriGWriterBase
{
- public static void write(OutputStream out, Dataset dataset)
- {
- write(out, dataset.asDatasetGraph()) ;
- }
-
- public static void write(OutputStream out, DatasetGraph datasetGraph)
- {
- IndentedWriter iOut = new IndentedWriter(out) ;
- write(iOut, datasetGraph) ;
- }
-
- public static void write(IndentedWriter out, DatasetGraph datasetGraph)
- {
- PrefixMap pmap = PrefixMapFactory.create(datasetGraph.getDefaultGraph().getPrefixMapping()) ;
- write(out, datasetGraph, pmap, null) ;
- }
-
- public static void write(OutputStream out, Graph graph)
- {
- DatasetGraph dsg = DatasetGraphFactory.createOneGraph(graph) ;
- write(out, dsg) ;
- }
-
- public static void write(IndentedWriter out, DatasetGraph datasetGraph, PrefixMap prefixes, String baseURI)
+ @Override
+ protected void output$(IndentedWriter iOut, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI)
{
- StreamRDF dest = new WriterStreamRDFFlat(out) ;
- WriterStreamBase.write(dest, datasetGraph, prefixes, baseURI) ;
+ StreamRDF dest = new WriterStreamRDFFlat(iOut) ;
+ WriterStreamBase.write(dest, datasetGraph, prefixMap, baseURI) ;
}
}
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleShell.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleShell.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleShell.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleShell.java Sat Feb 9 20:01:44 2013
@@ -39,6 +39,7 @@ import org.apache.jena.riot.system.Prefi
import riot.other.GLib ;
import riot.out.NodeFormatter ;
import riot.out.NodeFormatterTTL ;
+import riot.system.RiotLib ;
import com.hp.hpl.jena.graph.Graph ;
import com.hp.hpl.jena.graph.Node ;
@@ -63,7 +64,7 @@ public abstract class TurtleShell
protected void writePrefixes(PrefixMap prefixMap)
{
- TW2.writePrefixes(out, prefixMap) ;
+ RiotLib.writePrefixes(out, prefixMap) ;
}
protected void writeGraphTTL(Graph graph)
@@ -140,7 +141,7 @@ public abstract class TurtleShell
*/
void findLists()
{
- List<Triple> tails = TW2.triples(graph, Node.ANY, RDF_Rest, RDF_Nil) ;
+ List<Triple> tails = RiotLib.triples(graph, Node.ANY, RDF_Rest, RDF_Nil) ;
for ( Triple t : tails )
{
// Returns the elements, reversed.
@@ -151,7 +152,7 @@ public abstract class TurtleShell
Node headElt = p.getLeft() ;
// Free standing?private
List<Node> elts = p.getRight() ;
- long numLinks = TW2.countTriples(graph, null, null, headElt) ;
+ long numLinks = RiotLib.countTriples(graph, null, null, headElt) ;
if ( numLinks == 1 )
lists.put(headElt, elts) ;
else if ( numLinks == 0 )
@@ -185,15 +186,15 @@ public abstract class TurtleShell
break ;
}
- Triple t = TW2.triple1(graph, x, RDF_First, null) ;
+ Triple t = RiotLib.triple1(graph, x, RDF_First, null) ;
if ( t == null )
return null ;
eltsReversed.add(t.getObject()) ;
listCells.add(x) ;
// Try to move up the list.
- List<Triple> acc2 = TW2.triples(graph, null, null, x) ;
- long numRest = TW2.countTriples(graph, null, RDF_Rest, x) ;
+ List<Triple> acc2 = RiotLib.triples(graph, null, null, x) ;
+ long numRest = RiotLib.countTriples(graph, null, RDF_Rest, x) ;
if ( numRest != 1 )
{
// Head of well-formed list.
@@ -219,13 +220,13 @@ public abstract class TurtleShell
/* Return the triples of the list element, or null if invalid list */
private boolean validListElement(Node x, List<Triple> acc)
{
- Triple t1 = TW2.triple1(graph, x, RDF_Rest, null) ; // Which we came up to get here :-(
+ Triple t1 = RiotLib.triple1(graph, x, RDF_Rest, null) ; // Which we came up to get here :-(
if ( t1 == null )
return false ;
- Triple t2 = TW2.triple1(graph, x, RDF_First, null) ;
+ Triple t2 = RiotLib.triple1(graph, x, RDF_First, null) ;
if ( t2 == null )
return false ;
- long N = TW2.countTriples(graph, x, null, null) ;
+ long N = RiotLib.countTriples(graph, x, null, null) ;
if ( N != 2 )
return false ;
acc.add(t1) ;
@@ -310,7 +311,7 @@ public abstract class TurtleShell
out.println() ;
first = false ;
- Collection<Triple> cluster = TW2.triplesOfSubject(graph, subj) ;
+ Collection<Triple> cluster = RiotLib.triplesOfSubject(graph, subj) ;
writeCluster(subj, cluster) ;
}
return !first ;
@@ -389,7 +390,7 @@ public abstract class TurtleShell
private void nestedObject(Node obj)
{
- Collection<Triple> x = TW2.triplesOfSubject(graph, obj) ;
+ Collection<Triple> x = RiotLib.triplesOfSubject(graph, obj) ;
if ( x.isEmpty() )
{
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriter.java Sat Feb 9 20:01:44 2013
@@ -18,79 +18,33 @@
package riot.writer;
-import java.io.OutputStream ;
-import java.util.Map ;
-
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.rdf.model.Model ;
-public class TurtleWriter extends TurtleShell
+public class TurtleWriter extends TurtleWriterBase
{
- public static void write(OutputStream cxt, Model model)
- {
- write(cxt, model, null) ;
- }
-
- public static void write(OutputStream cxt, Model model, String baseURI)
- {
- write(cxt, model.getGraph()) ;
- }
-
- public static void write(OutputStream out, Graph graph)
+ @Override
+ protected void output$(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI)
{
- PrefixMap pmap = PrefixMapFactory.create(graph.getPrefixMapping()) ;
- IndentedWriter iOut = new IndentedWriter(out, false) ;
- write$(iOut, graph, pmap, null) ;
+ TurtleWriter$ w = new TurtleWriter$(iOut, prefixMap, baseURI) ;
+ w.write(graph) ;
}
-
-// public static void write(OutputStream out, Graph graph, Map<String, String> prefixMap)
-// {
-// PrefixMap pmap = PrefixMapFactory.create(graph.getPrefixMapping()) ;
-// IndentedWriter iOut = new IndentedWriter(out, false) ;
-// write$(iOut, graph, pmap, null) ;
-// }
-
-// static void write(IndentedWriter out, Graph graph, Map<String, String> prefixMap)
-// {
-// write(out, graph, prefixMap, null) ;
-// }
-
- static void write(IndentedWriter out, Graph graph, Map<String, String> prefixMap, String baseURI)
- {
- write$(out, graph, PrefixMapFactory.create(prefixMap), baseURI) ;
- out.flush() ;
- }
-
- static void write$(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI)
- {
- IndentedWriter iOut = new IndentedWriter(out, false) ;
- write$(iOut, graph, prefixMap, baseURI) ;
- }
-
- static void write$(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI)
- {
- TurtleWriter w = new TurtleWriter(out, prefixMap, baseURI) ;
- w.write(graph) ;
- out.flush() ;
-
- }
-
- public TurtleWriter(IndentedWriter out, PrefixMap prefixMap, String baseURI)
- {
- super(out, prefixMap, baseURI) ;
- }
-
- private void write(Graph graph)
+ private static class TurtleWriter$ extends TurtleShell
{
- writePrefixes(prefixMap) ;
- if ( ! prefixMap.isEmpty() && !graph.isEmpty() )
- out.println() ;
- writeGraphTTL(graph) ;
+ public TurtleWriter$(IndentedWriter out, PrefixMap prefixMap, String baseURI)
+ {
+ super(out, prefixMap, baseURI) ;
+ }
+ private void write(Graph graph)
+ {
+ writePrefixes(prefixMap) ;
+ if ( ! prefixMap.isEmpty() && !graph.isEmpty() )
+ out.println() ;
+ writeGraphTTL(graph) ;
+ }
}
}
Added: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBase.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBase.java?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBase.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBase.java Sat Feb 9 20:01:44 2013
@@ -0,0 +1,58 @@
+/**
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.io.Writer ;
+
+import org.apache.jena.atlas.io.IndentedWriter ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.system.PrefixMap ;
+import riot.WriterGraphRIOTBase ;
+import riot.system.IndentedWriterWriter ;
+
+import com.hp.hpl.jena.graph.Graph ;
+
+public abstract class TurtleWriterBase extends WriterGraphRIOTBase
+{
+ @Override
+ public Lang getLang()
+ {
+ return Lang.TURTLE ;
+ }
+
+ @Override
+ public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ IndentedWriter iOut = IndentedWriterWriter.create(out) ;
+ output$(iOut, graph, prefixMap, baseURI) ;
+ iOut.flush() ;
+ }
+
+ @Override
+ public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI)
+ {
+ IndentedWriter iOut = new IndentedWriter(out) ;
+ output$(iOut, graph, prefixMap, baseURI) ;
+ iOut.flush() ;
+ }
+
+ protected abstract void output$(IndentedWriter iOut, Graph graph, PrefixMap prefixMap, String baseURI) ;
+}
+
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterBlocks.java Sat Feb 9 20:01:44 2013
@@ -18,47 +18,22 @@
package riot.writer;
-import java.io.OutputStream ;
-
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import org.apache.jena.riot.system.StreamRDF ;
import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.rdf.model.Model ;
/** Turtle writer that streams - print in blocks of triples formatted
* by adjacent same subject.
*/
-public class TurtleWriterBlocks
+public class TurtleWriterBlocks extends TurtleWriterBase
{
- public static void write(OutputStream out, Model model)
- {
- write(out, model.getGraph()) ;
- }
-
- public static void write(IndentedWriter out, Model model)
- {
- write(out, model.getGraph()) ;
- }
-
- public static void write(OutputStream out, Graph graph)
- {
- IndentedWriter iOut = new IndentedWriter(out) ;
- write(iOut, graph) ;
- }
-
- public static void write(IndentedWriter out, Graph graph)
- {
- PrefixMap pmap = PrefixMapFactory.create(graph.getPrefixMapping()) ;
- write(out, graph, pmap, null) ;
- }
-
- public static void write(IndentedWriter out, Graph graph, PrefixMap pmap, String baseURI)
+ @Override
+ protected void output$(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI)
{
StreamRDF dest = new WriterStreamRDFBlocks(out) ;
- WriterStreamBase.write(dest, graph, pmap, baseURI) ;
+ WriterStreamBase.write(dest, graph, prefixMap, baseURI) ;
}
}
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TurtleWriterFlat.java Sat Feb 9 20:01:44 2013
@@ -18,44 +18,19 @@
package riot.writer;
-import java.io.OutputStream ;
-
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.riot.system.PrefixMap ;
-import org.apache.jena.riot.system.PrefixMapFactory ;
import org.apache.jena.riot.system.StreamRDF ;
import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.rdf.model.Model ;
-/** Write Turtle as one line of prefixed names, with short form literals (e.g. integers) */
-public class TurtleWriterFlat
+/** Write Turtle with omne triple on one line with prefixed names, with short form literals (e.g. integers) */
+public class TurtleWriterFlat extends TurtleWriterBase
{
- public static void write(OutputStream out, Model model)
- {
- write(out, model.getGraph()) ;
- }
-
- public static void write(IndentedWriter out, Model model)
- {
- write(out, model.getGraph()) ;
- }
-
- public static void write(OutputStream out, Graph graph)
- {
- IndentedWriter iOut = new IndentedWriter(out) ;
- write(iOut, graph) ;
- }
-
- public static void write(IndentedWriter out, Graph graph)
- {
- PrefixMap pmap = PrefixMapFactory.create(graph.getPrefixMapping()) ;
- write(out, graph, pmap, null) ;
- }
-
- public static void write(IndentedWriter out, Graph graph, PrefixMap prefixes, String baseURI)
+ @Override
+ protected void output$(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI)
{
StreamRDF dest = new WriterStreamRDFFlat(out) ;
- WriterStreamBase.write(dest, graph, prefixes, baseURI) ;
+ WriterStreamBase.write(dest, graph, prefixMap, baseURI) ;
}
-}
+}
\ No newline at end of file
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterConst.java Sat Feb 9 20:01:44 2013
@@ -41,6 +41,9 @@ public class WriterConst
// Column for start of object
// Usually this is exceeded and predicate, objects are print with min gap.
public static final int INDENT_OBJECT = 8 ;
+
+ // Indent for graphs
+ public static final int INDENT_GRAPH = 4 ;
public static final String iriType = RDF.type.getURI() ;
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDF.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDF.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDF.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDF.java Sat Feb 9 20:01:44 2013
@@ -20,7 +20,9 @@ package riot.writer;
import static org.apache.jena.atlas.lib.Lib.equal ;
+import java.io.BufferedWriter ;
import java.io.OutputStream ;
+import java.io.Writer ;
import org.apache.jena.atlas.io.IndentedWriter ;
import org.apache.jena.atlas.lib.Tuple ;
@@ -29,6 +31,7 @@ import org.apache.jena.riot.system.Prefi
import org.apache.jena.riot.system.PrefixMapFactory ;
import org.apache.jena.riot.system.StreamRDF ;
import riot.out.NodeFormatterTTL ;
+import riot.system.IndentedWriterWriter ;
import com.hp.hpl.jena.graph.Node ;
import com.hp.hpl.jena.graph.Triple ;
@@ -96,6 +99,7 @@ public abstract class WriterStreamRDF im
this(new IndentedWriter(output)) ;
}
+
public WriterStreamRDF(IndentedWriter output)
{
out = output ;
@@ -103,7 +107,15 @@ public abstract class WriterStreamRDF im
fmt = new NodeFormatterTTL(null, pMap, NodeToLabel.createScopeByDocument()) ;
}
-
+ public WriterStreamRDF(Writer output)
+ {
+ if ( ! ( output instanceof BufferedWriter ) )
+ output = new BufferedWriter(output, 32*1024) ;
+ out = IndentedWriterWriter.create(output) ;
+ pMap = PrefixMapFactory.create() ;
+ fmt = new NodeFormatterTTL(null, pMap, NodeToLabel.createScopeByDocument()) ;
+ }
+
@Override
public void start()
{
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFBlocks.java Sat Feb 9 20:01:44 2013
@@ -21,6 +21,7 @@ package riot.writer;
import static org.apache.jena.atlas.lib.Lib.equal ;
import java.io.OutputStream ;
+import java.io.Writer ;
import org.apache.jena.atlas.io.IndentedWriter ;
@@ -42,10 +43,16 @@ public class WriterStreamRDFBlocks exten
{
super(output) ;
}
+
public WriterStreamRDFBlocks(IndentedWriter output)
{
super(output) ;
}
+
+ public WriterStreamRDFBlocks(Writer output)
+ {
+ super(output) ;
+ }
@Override
protected void print(Node g, Node s, Node p, Node o)
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFFlat.java Sat Feb 9 20:01:44 2013
@@ -19,6 +19,7 @@
package riot.writer;
import java.io.OutputStream ;
+import java.io.Writer ;
import org.apache.jena.atlas.io.IndentedWriter ;
@@ -41,7 +42,11 @@ public class WriterStreamRDFFlat extends
public WriterStreamRDFFlat(IndentedWriter output)
{
super(output) ;
-
+ }
+
+ public WriterStreamRDFFlat(Writer output)
+ {
+ super(output) ;
}
@Override
Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java Sat Feb 9 20:01:44 2013
@@ -49,6 +49,13 @@ public class WriterStreamRDFTuples imple
{ throw new RiotException(e) ; }
}
+ public WriterStreamRDFTuples(Writer w)
+ {
+ if ( ! ( w instanceof BufferedWriter ) )
+ w = new BufferedWriter(w, 32*1024) ;
+ out = w ;
+ }
+
@Override
public void start()
{}
Modified: jena/Experimental/riot-output/src/test/java/riot/writer/TS_RiotWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/test/java/riot/writer/TS_RiotWriter.java?rev=1444417&r1=1444416&r2=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/test/java/riot/writer/TS_RiotWriter.java (original)
+++ jena/Experimental/riot-output/src/test/java/riot/writer/TS_RiotWriter.java Sat Feb 9 20:01:44 2013
@@ -23,11 +23,13 @@ import org.junit.BeforeClass ;
import org.junit.runner.RunWith ;
import org.junit.runners.Suite ;
import org.junit.runners.Suite.SuiteClasses ;
+import riot.RDFWriterRegistry ;
@RunWith(Suite.class)
@SuiteClasses(
{
- TestRiotWriter.class
+ TestRiotWriterGraph.class
+ , TestRiotWriterDataset.class
})
public class TS_RiotWriter
@@ -35,5 +37,6 @@ public class TS_RiotWriter
@BeforeClass public static void beforeClass()
{
RIOT.init() ;
+ RDFWriterRegistry.init() ;
}
}
Added: jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterDataset.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterDataset.java?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterDataset.java (added)
+++ jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterDataset.java Sat Feb 9 20:01:44 2013
@@ -0,0 +1,98 @@
+/**
+ * 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 riot.writer;
+
+import java.io.ByteArrayInputStream ;
+import java.io.ByteArrayOutputStream ;
+import java.util.Arrays ;
+
+import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.riot.RiotException ;
+import org.junit.Test ;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Parameterized ;
+import org.junit.runners.Parameterized.Parameters ;
+import riot.RDFFormat ;
+import riot.RDFWriterMgr ;
+import riot.RDFWriterRegistry ;
+import riot.WriterDatasetRIOT ;
+
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.query.DatasetFactory ;
+
+@RunWith(Parameterized.class)
+public class TestRiotWriterDataset extends BaseTest
+{
+ @Parameters(name = "{index}: {0}")
+ public static Iterable<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { RDFFormat.Trig } ,
+ { RDFFormat.TrigPretty } ,
+ { RDFFormat.TrigBlocks } ,
+ { RDFFormat.TrigFlat } ,
+ { RDFFormat.NQuads} ,
+ }) ;
+ }
+
+ private RDFFormat format ;
+
+ public TestRiotWriterDataset(RDFFormat format)
+ {
+ this.format = format ;
+ }
+
+ static String DIR = "testing/RIOT/Writer" ;
+
+ @Test public void writer00() { test("writer-rt-20.trig") ; }
+ @Test public void writer01() { test("writer-rt-21.trig") ; }
+ @Test public void writer02() { test("writer-rt-22.trig") ; }
+ @Test public void writer03() { test("writer-rt-23.trig") ; }
+
+ private void test(String filename)
+ {
+ String displayname = filename.substring(0, filename.lastIndexOf('.')) ;
+ String fn = DIR + "/" + filename ;
+ Dataset m = RDFDataMgr.loadDataset(fn) ;
+ Lang lang = format.getLang() ;
+
+ WriterDatasetRIOT rs = RDFWriterRegistry.getWriterDatasetFactory(format).create(format) ;
+ assertEquals(lang, rs.getLang()) ;
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream() ;
+ RDFWriterMgr.write(out, m, format) ;
+
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
+ String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
+
+ Dataset ds2 = DatasetFactory.createMem() ;
+
+ try {
+ RDFDataMgr.read(ds2, in, lang) ;
+ } catch (RiotException ex)
+ {
+ System.out.println(format) ;
+ System.out.println(s) ;
+ throw ex ;
+ }
+ }
+}
+
Copied: jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterGraph.java (from r1444211, jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriter.java)
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterGraph.java?p2=jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterGraph.java&p1=jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriter.java&r1=1444211&r2=1444417&rev=1444417&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriter.java (original)
+++ jena/Experimental/riot-output/src/test/java/riot/writer/TestRiotWriterGraph.java Sat Feb 9 20:01:44 2013
@@ -31,42 +31,42 @@ import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.junit.runners.Parameterized ;
import org.junit.runners.Parameterized.Parameters ;
-import riot.RDFSerialization ;
+import riot.RDFFormat ;
+import riot.RDFWriterMgr ;
import riot.RDFWriterRegistry ;
-import riot.RiotSerializer ;
+import riot.WriterGraphRIOT ;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.rdf.model.ModelFactory ;
@RunWith(Parameterized.class)
-public class TestRiotWriter extends BaseTest
+public class TestRiotWriterGraph extends BaseTest
{
@Parameters(name = "{index}: {0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][] {
- { RDFWriterRegistry.NTriples } ,
- { RDFWriterRegistry.Turtle } ,
- { RDFWriterRegistry.TurtlePretty } ,
- { RDFWriterRegistry.TurtleBlocks } ,
- { RDFWriterRegistry.TurtleFlat } ,
- { RDFWriterRegistry.RDFXML } ,
- { RDFWriterRegistry.RDFXMLPretty } ,
- { RDFWriterRegistry.RDFXMLPlain } ,
- { RDFWriterRegistry.RDFJSON } ,
-
+ { RDFFormat.NTriples } ,
+ { RDFFormat.Turtle } ,
+ { RDFFormat.TurtlePretty } ,
+ { RDFFormat.TurtleBlocks } ,
+ { RDFFormat.TurtleFlat } ,
+ { RDFFormat.RDFXML } ,
+ { RDFFormat.RDFXMLPretty } ,
+ { RDFFormat.RDFXMLPlain } ,
+ { RDFFormat.RDFJSON } ,
+
// graph in quad formats.
- { RDFWriterRegistry.Trig } ,
- { RDFWriterRegistry.TrigPretty } ,
- { RDFWriterRegistry.TrigBlocks } ,
- { RDFWriterRegistry.TrigFlat } ,
- { RDFWriterRegistry.NQuads} ,
-
- }) ;
+ { RDFFormat.Trig } ,
+ { RDFFormat.TrigPretty } ,
+ { RDFFormat.TrigBlocks } ,
+ { RDFFormat.TrigFlat } ,
+ { RDFFormat.NQuads} ,
+ }) ;
}
- private RDFSerialization format ;
+ private RDFFormat format ;
- public TestRiotWriter(RDFSerialization format)
+ public TestRiotWriterGraph(RDFFormat format)
{
this.format = format ;
}
@@ -98,10 +98,11 @@ public class TestRiotWriter extends Base
Model m = RDFDataMgr.loadModel(fn) ;
Lang lang = format.getLang() ;
- ByteArrayOutputStream out = new ByteArrayOutputStream() ;
- RiotSerializer rs = RDFWriterRegistry.getWriterFactory(format).create(out, m.getGraph(), format) ;
+ WriterGraphRIOT rs = RDFWriterRegistry.getWriterGraphFactory(format).create(format) ;
assertEquals(lang, rs.getLang()) ;
- rs.write() ;
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream() ;
+ RDFWriterMgr.write(out, m, format) ;
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) ;
String s = StrUtils.fromUTF8bytes(out.toByteArray()) ;
Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-20.trig
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-20.trig?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-20.trig (added)
+++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-20.trig Sat Feb 9 20:01:44 2013
@@ -0,0 +1,5 @@
+@prefix : <http://example/> .
+@prefix ns: <http://example/ns#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+# Empty.
Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-21.trig
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-21.trig?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-21.trig (added)
+++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-21.trig Sat Feb 9 20:01:44 2013
@@ -0,0 +1,5 @@
+@prefix : <http://example/> .
+@prefix ns: <http://example/ns#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+{ :s :p :o }
Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-22.trig
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-22.trig?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-22.trig (added)
+++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-22.trig Sat Feb 9 20:01:44 2013
@@ -0,0 +1,5 @@
+@prefix : <http://example/> .
+@prefix ns: <http://example/ns#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+:g { :s :p :o }
Added: jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-23.trig
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-23.trig?rev=1444417&view=auto
==============================================================================
--- jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-23.trig (added)
+++ jena/Experimental/riot-output/testing/RIOT/Writer/writer-rt-23.trig Sat Feb 9 20:01:44 2013
@@ -0,0 +1,18 @@
+@prefix : <http://example/> .
+@prefix ns: <http://example/ns#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+{ :s :p 1,2,3 ;
+ :q (1 2 3) .
+}
+{ :s1 :p 1,2,3 }
+
+:g1 { :s :p 1,2,3 ;
+ :q (1 2 3) .
+}
+
+:g2 { :s :p 1,2,3 ;
+ :q (1 2 3) .
+}
+
+