Mercurial > repos > mikel-egana-aranguren > sadi_generic
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/info/wilkinsonlab/sadi/galaxy/RDFSyntaxConverter.java Fri Apr 25 14:41:12 2014 +0200 @@ -0,0 +1,48 @@ +package info.wilkinsonlab.sadi.galaxy; + +import java.io.InputStream; + +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.util.FileManager; + +public class RDFSyntaxConverter { + + /** + * @param input RDF + * @param format one of N3, N-TRIPLE, TAB + * + */ + public static void main(String[] args) { + String input_RDF_path = args[0]; + String format = args[1]; + Model model = ModelFactory.createOntologyModel(); + InputStream in = FileManager.get().open(input_RDF_path); + model.read(in, null); + + if (format.equals("TAB")) { + String queryString = "SELECT * WHERE { ?s ?p ?o } "; + Query query = QueryFactory.create(queryString); + QueryExecution qe = QueryExecutionFactory.create(query, model); + try { + ResultSet rs = qe.execSelect(); + System.out.println("Subject\tPredicate\tObject\n"); + while (rs.hasNext()) { + QuerySolution row = rs.nextSolution(); + System.out.println(row.get("s") + "\t" + row.get("p") + + "\t" + row.get("o") + "\n"); + } + } finally { + qe.close(); + } + } else { + model.write(System.out, format); + } + } +}