comparison src/info/wilkinsonlab/galaxy/sparql/text/SPARQLGalaxy_TEXT.java @ 2:b8bf1af83841 draft

Paste query added, query engine improved, examples added
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Wed, 04 Dec 2013 08:17:00 +0100
parents
children
comparison
equal deleted inserted replaced
1:117a4b4c002d 2:b8bf1af83841
1 package info.wilkinsonlab.galaxy.sparql.text;
2
3 import java.io.InputStream;
4 import java.util.Iterator;
5
6 import com.hp.hpl.jena.query.Query;
7 import com.hp.hpl.jena.query.QueryExecution;
8 import com.hp.hpl.jena.query.QueryExecutionFactory;
9 import com.hp.hpl.jena.query.QueryFactory;
10 import com.hp.hpl.jena.query.QuerySolution;
11 import com.hp.hpl.jena.query.ResultSet;
12 import com.hp.hpl.jena.rdf.model.Model;
13 import com.hp.hpl.jena.rdf.model.ModelFactory;
14 import com.hp.hpl.jena.rdf.model.RDFNode;
15 import com.hp.hpl.jena.util.FileManager;
16
17 public class SPARQLGalaxy_TEXT {
18
19 /**
20 * @param input
21 * RDF
22 * @param SPARQL
23 * query
24 *
25 */
26 public static void main(String[] args) {
27 String input_RDF_path = args[0];
28 String queryString = args[1];
29 Model model = ModelFactory.createOntologyModel();
30 InputStream in = FileManager.get().open(input_RDF_path);
31 model.read(in, null);
32 Query query = QueryFactory.create(queryString);
33 QueryExecution qe = QueryExecutionFactory.create(query, model);
34 ResultSet results = qe.execSelect();
35 String res = "";
36 while (results.hasNext()) {
37 QuerySolution qs = results.next();
38 Iterator<String> vars = qs.varNames();
39 while (vars.hasNext()) {
40 String var = vars.next();
41 res += "?" + var + "\t" + getValue(qs, var) + "\r\n";
42 System.out.println(res);
43 }
44 }
45 }
46
47 private static String getValue(QuerySolution qs, String var) {
48 RDFNode n = qs.get(var);
49 return n.toString();
50 }
51 }