aboutsummaryrefslogtreecommitdiff
path: root/external/uk/ac/ox/cs/data/WriteToNTriple.java
diff options
context:
space:
mode:
Diffstat (limited to 'external/uk/ac/ox/cs/data/WriteToNTriple.java')
-rw-r--r--external/uk/ac/ox/cs/data/WriteToNTriple.java57
1 files changed, 57 insertions, 0 deletions
diff --git a/external/uk/ac/ox/cs/data/WriteToNTriple.java b/external/uk/ac/ox/cs/data/WriteToNTriple.java
new file mode 100644
index 0000000..27e69b9
--- /dev/null
+++ b/external/uk/ac/ox/cs/data/WriteToNTriple.java
@@ -0,0 +1,57 @@
1package uk.ac.ox.cs.data;
2
3import java.io.FileInputStream;
4import java.io.FileOutputStream;
5import java.io.IOException;
6
7import org.openrdf.model.Statement;
8import org.openrdf.rio.RDFHandler;
9import org.openrdf.rio.RDFHandlerException;
10import org.openrdf.rio.RDFParseException;
11import org.openrdf.rio.RDFParser;
12import org.openrdf.rio.RDFWriter;
13import org.openrdf.rio.ntriples.NTriplesWriter;
14import org.openrdf.rio.turtle.TurtleParser;
15
16
17public class WriteToNTriple {
18
19 public static void main(String... args) throws RDFParseException, RDFHandlerException, IOException {
20 if (args.length == 0)
21 args = new String[] {"/media/krr-nas-share/Yujiao/ontologies/bio2rdf/reactome/data/data.ttl",
22 "http://www.biopax.org/release/biopax-level3.owl#"};
23
24 RDFParser parser = new TurtleParser();
25 final RDFWriter writer = new NTriplesWriter(new FileOutputStream(args[0].replace(".ttl", ".nt")));
26
27 parser.setRDFHandler(new RDFHandler() {
28
29 @Override
30 public void startRDF() throws RDFHandlerException {
31 writer.startRDF();
32 }
33
34 @Override
35 public void handleStatement(Statement arg0) throws RDFHandlerException {
36 writer.handleStatement(arg0);
37 }
38
39 @Override
40 public void handleNamespace(String arg0, String arg1) throws RDFHandlerException {
41 writer.handleNamespace(arg0, arg1);
42 }
43
44 @Override
45 public void handleComment(String arg0) throws RDFHandlerException {
46 writer.handleComment(arg0);
47 }
48
49 @Override
50 public void endRDF() throws RDFHandlerException {
51 writer.endRDF();
52 }
53 });
54
55 parser.parse(new FileInputStream(args[0]), args[1]);
56 }
57}