Reputation: 89
I have an RDF/XML file like this:
<rdf:RDF
xmlns:go="http://www.geneontology.org/dtds/go.dtd#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<go:term rdf:about="http://www.geneontology.org/go#GO:0000001">
<go:accession>GO:0000001</go:accession>
<go:name>mitochondrion inheritance</go:name>
<go:synonym>mitochondrial inheritance</go:synonym>
<go:definition>The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton.</go:definition>
<go:is_a rdf:resource="http://www.geneontology.org/go#GO:0048308" />
<go:is_a rdf:resource="http://www.geneontology.org/go#GO:0048311" />
</go:term>
</rdf:RDF>
Then I have to convert this RDF/XML into the N-Triples format, and I have done this automatically with Jena:
FileManager.get().addLocatorClassLoader(Converter.class.getClassLoader());
Model model = FileManager.get().loadModel("smallfacts.rdf");
try {
File file= new File("outputsmall.txt");
model.write(new FileOutputStream(file), "N-Triples");
} catch (IOException e) {
e.printStackTrace();
But then I need to shorten each predicate with a prefix. I have to obtain something like this:
<http://www.geneontology.org/go#GO:2000391> is_a <http://www.geneontology.org/go#GO:2000389>.
<http://www.geneontology.org/go#GO:2000391> accession "GO:2000391".
I have read about getNSPrefix()
and have made some attempts, such as:
FileManager.get().addLocatorClassLoader(Converter.class.getClassLoader());
Model model = FileManager.get().loadModel("smallfacts.rdf");
try {
File file= new File("outputsmall.txt");
model.getNsPrefixURI("http://www.geneontology.org/dtds/go.dtd#");
model.write(new FileOutputStream(file), "N-Triples", "http://www.geneontology.org/dtds/go.dtd#");
} catch (IOException e) {
e.printStackTrace();
How do I use getNsPrefixURI()
in this case? Should I use another method?
Upvotes: 1
Views: 780
Reputation: 16630
Try writing your RDF data with RDFDataMgr and RDFFormat.TURTLE_FLAT. https://jena.apache.org/documentation/io/rdf-output.html
Upvotes: 2