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