blob: 27e69b9f7d43d44091ec8472a3b8793dcb50b29f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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]);
}
}
|