From 9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8 Mon Sep 17 00:00:00 2001 From: yzhou Date: Tue, 21 Apr 2015 10:34:27 +0100 Subject: initial version --- test/uk/ac/ox/cs/data/WriteToNTriple.java | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/uk/ac/ox/cs/data/WriteToNTriple.java (limited to 'test/uk/ac/ox/cs/data/WriteToNTriple.java') diff --git a/test/uk/ac/ox/cs/data/WriteToNTriple.java b/test/uk/ac/ox/cs/data/WriteToNTriple.java new file mode 100644 index 0000000..27e69b9 --- /dev/null +++ b/test/uk/ac/ox/cs/data/WriteToNTriple.java @@ -0,0 +1,57 @@ +package uk.ac.ox.cs.data; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.openrdf.model.Statement; +import org.openrdf.rio.RDFHandler; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; +import org.openrdf.rio.RDFParser; +import org.openrdf.rio.RDFWriter; +import org.openrdf.rio.ntriples.NTriplesWriter; +import org.openrdf.rio.turtle.TurtleParser; + + +public class WriteToNTriple { + + public static void main(String... args) throws RDFParseException, RDFHandlerException, IOException { + if (args.length == 0) + args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/reactome/data/data.ttl", + "http://www.biopax.org/release/biopax-level3.owl#"}; + + RDFParser parser = new TurtleParser(); + final RDFWriter writer = new NTriplesWriter(new FileOutputStream(args[0].replace(".ttl", ".nt"))); + + parser.setRDFHandler(new RDFHandler() { + + @Override + public void startRDF() throws RDFHandlerException { + writer.startRDF(); + } + + @Override + public void handleStatement(Statement arg0) throws RDFHandlerException { + writer.handleStatement(arg0); + } + + @Override + public void handleNamespace(String arg0, String arg1) throws RDFHandlerException { + writer.handleNamespace(arg0, arg1); + } + + @Override + public void handleComment(String arg0) throws RDFHandlerException { + writer.handleComment(arg0); + } + + @Override + public void endRDF() throws RDFHandlerException { + writer.endRDF(); + } + }); + + parser.parse(new FileInputStream(args[0]), args[1]); + } +} -- cgit v1.2.3