Mercurial > repos > mikel-egana-aranguren > sadi_generic
comparison src/info/wilkinsonlab/sadi/galaxy/RDFSyntaxConverter.java @ 2:977c838e3442 draft default tip
New dir structure, README improved, tests added and RDF merge tool created
author | mikel-egana-aranguren <mikel.egana.aranguren@gmail.com> |
---|---|
date | Fri, 25 Apr 2014 14:41:12 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:bb17b69a74c5 | 2:977c838e3442 |
---|---|
1 package info.wilkinsonlab.sadi.galaxy; | |
2 | |
3 import java.io.InputStream; | |
4 | |
5 import com.hp.hpl.jena.query.Query; | |
6 import com.hp.hpl.jena.query.QueryExecution; | |
7 import com.hp.hpl.jena.query.QueryExecutionFactory; | |
8 import com.hp.hpl.jena.query.QueryFactory; | |
9 import com.hp.hpl.jena.query.QuerySolution; | |
10 import com.hp.hpl.jena.query.ResultSet; | |
11 import com.hp.hpl.jena.rdf.model.Model; | |
12 import com.hp.hpl.jena.rdf.model.ModelFactory; | |
13 import com.hp.hpl.jena.util.FileManager; | |
14 | |
15 public class RDFSyntaxConverter { | |
16 | |
17 /** | |
18 * @param input RDF | |
19 * @param format one of N3, N-TRIPLE, TAB | |
20 * | |
21 */ | |
22 public static void main(String[] args) { | |
23 String input_RDF_path = args[0]; | |
24 String format = args[1]; | |
25 Model model = ModelFactory.createOntologyModel(); | |
26 InputStream in = FileManager.get().open(input_RDF_path); | |
27 model.read(in, null); | |
28 | |
29 if (format.equals("TAB")) { | |
30 String queryString = "SELECT * WHERE { ?s ?p ?o } "; | |
31 Query query = QueryFactory.create(queryString); | |
32 QueryExecution qe = QueryExecutionFactory.create(query, model); | |
33 try { | |
34 ResultSet rs = qe.execSelect(); | |
35 System.out.println("Subject\tPredicate\tObject\n"); | |
36 while (rs.hasNext()) { | |
37 QuerySolution row = rs.nextSolution(); | |
38 System.out.println(row.get("s") + "\t" + row.get("p") | |
39 + "\t" + row.get("o") + "\n"); | |
40 } | |
41 } finally { | |
42 qe.close(); | |
43 } | |
44 } else { | |
45 model.write(System.out, format); | |
46 } | |
47 } | |
48 } |