# HG changeset patch
# User mikel-egana-aranguren
# Date 1351181860 14400
# Node ID 137f9a4a633706d2f4469853ff6975cb435504a0
First version to init the repo, still README etc to add but it works
diff -r 000000000000 -r 137f9a4a6337 SPARQLGalaxy.jar
Binary file SPARQLGalaxy.jar has changed
diff -r 000000000000 -r 137f9a4a6337 SPARQLGalaxy.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SPARQLGalaxy.xml Thu Oct 25 12:17:40 2012 -0400
@@ -0,0 +1,56 @@
+
+ It executes an SPARQL query against the input OWL ontology and generates a two column tab file with the variables and bound entities
+
+ java -Xmx3000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/SPARQLGalaxy.jar $ontology $query_file > $output 2>/dev/null
+
+
+
+
+
+
+
+
+
+
+
+**Usage**
+
+ An OWL ontology in RDF/XML syntax and a plain text file with the SPARQL are needed. See bundle for examples.
+
+**More information**
+
+ Galaxy public instance with SPARQL-Galaxy pre-installed:
+
+ http://biordf.org:8090/
+
+ SPARQL:
+
+ http://www.w3.org/standards/techs/sparql
+
+ JENA:
+
+ http://jena.apache.org/
+
+**Authors and funding**
+
+ Alejandro Rodríguez González is funded by the Isaac Peral Programme and developed the Java wrapper for JENA.
+
+ Mikel Egaña Aranguren is funded by the Marie Curie Cofund programme and developed the XML file for this tool.
+
+ They both belong to the Biological Informatics group of the CBGP, Spain (http://wilkinsonlab.info/).
+
+**Contact**
+
+ Please send any request or comment to mikel.egana.aranguren@gmail.com.
+
+
+
+
diff -r 000000000000 -r 137f9a4a6337 src/es/cbgp/galaxy/sparql/jena/OntologyManager.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/es/cbgp/galaxy/sparql/jena/OntologyManager.java Thu Oct 25 12:17:40 2012 -0400
@@ -0,0 +1,32 @@
+package es.cbgp.galaxy.sparql.jena;
+
+import java.io.File;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+
+public class OntologyManager {
+
+ private String ontFile;
+ private String sparqlFile;
+ private OntModel model;
+ private SPARQLQueryEngine sqe;
+
+ public OntologyManager(String of, String sf) throws Exception {
+ this.ontFile = of;
+ this.sparqlFile = sf;
+ init();
+ }
+
+ private void init() throws Exception {
+ this.model = ModelFactory.createOntologyModel();
+ this.model.read(new File(ontFile).toURI().toString());
+ }
+
+ public void executeQuery() throws Exception {
+ this.sqe = new SPARQLQueryEngine(model);
+ this.sqe.setQueryFile(sparqlFile);
+ String ret = sqe.executeQuery();
+ System.out.println(ret);
+ }
+}
diff -r 000000000000 -r 137f9a4a6337 src/es/cbgp/galaxy/sparql/jena/SPARQLQueryEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/es/cbgp/galaxy/sparql/jena/SPARQLQueryEngine.java Thu Oct 25 12:17:40 2012 -0400
@@ -0,0 +1,66 @@
+package es.cbgp.galaxy.sparql.jena;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.Iterator;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.query.*;
+import com.hp.hpl.jena.shared.Lock;
+
+public class SPARQLQueryEngine {
+
+ private OntModel queryModel;
+ private String sparqlFile;
+
+ public SPARQLQueryEngine(OntModel om) {
+ this.queryModel = om;
+ }
+
+ public String executeQuery() throws Exception {
+ String finalQuery = loadQueryFromFile();
+ // System.out.println("Final query: " + finalQuery);
+ Query query = null;
+ QueryExecution qexec = null;
+ try {
+ queryModel.enterCriticalSection(Lock.READ);
+ query = QueryFactory.create(finalQuery);
+ qexec = QueryExecutionFactory.create(query, queryModel);
+ ResultSet results = qexec.execSelect();
+ String res = "";
+ while (results.hasNext()) {
+ QuerySolution qs = results.next();
+ Iterator vars = qs.varNames();
+ while (vars.hasNext()) {
+ String var = vars.next();
+ if (!qs.getResource(var).isAnon()) {
+ res += "?" + var + "\t" + qs.getResource(var) + "\n";
+ }
+ }
+ }
+ return res;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ queryModel.leaveCriticalSection();
+ if (qexec != null) {
+ qexec.close();
+ }
+ }
+ return null;
+ }
+
+ private String loadQueryFromFile() throws Exception {
+ String query = "";
+ BufferedReader bL = new BufferedReader(new FileReader(this.sparqlFile));
+ while (bL.ready()) {
+ query += bL.readLine();
+ }
+ bL.close();
+ return query;
+ }
+
+ public void setQueryFile(String sparqlFile) {
+ this.sparqlFile = sparqlFile;
+ }
+}
diff -r 000000000000 -r 137f9a4a6337 src/es/cbgp/galaxy/sparql/main/Main.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/es/cbgp/galaxy/sparql/main/Main.java Thu Oct 25 12:17:40 2012 -0400
@@ -0,0 +1,54 @@
+package es.cbgp.galaxy.sparql.main;
+
+import java.io.File;
+
+import es.cbgp.galaxy.sparql.jena.OntologyManager;
+
+public class Main {
+
+ public Main(String args[]) {
+ Result r = check(args);
+ if (r.getBoolValue()) {
+ String ontFile = args[0];
+ String sparqlFile = args[1];
+ run(ontFile, sparqlFile);
+ } else {
+ System.err.println("Error: " + r.getMessage());
+ }
+ }
+
+ private void run(String ontFile, String sparqlFile) {
+ try {
+ OntologyManager om = new OntologyManager(ontFile, sparqlFile);
+ om.executeQuery();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Result check(String[] args) {
+ if (args.length == 2) {
+ String fo = args[0];
+ String fs = args[1];
+ if (new File(fo).exists()) {
+ if (new File(fs).exists()) {
+ return new Result(true);
+ } else {
+ return new Result(false,
+ "Ontology file exists. SPARQL file not!");
+ }
+ }
+ return new Result(false, "Ontology file not exists!");
+ }
+ return new Result(false,
+ "Incorrect number of parameters. Necessary 2: " + args.length);
+ }
+
+ public static void main(String[] args) {
+ /*
+ * Input: ontologia "SELECT .... blala"
+ */
+ new Main(args);
+ }
+
+}
diff -r 000000000000 -r 137f9a4a6337 src/es/cbgp/galaxy/sparql/main/Result.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/es/cbgp/galaxy/sparql/main/Result.java Thu Oct 25 12:17:40 2012 -0400
@@ -0,0 +1,23 @@
+package es.cbgp.galaxy.sparql.main;
+
+public class Result {
+ private boolean boolValue;
+ private String message;
+
+ public Result(boolean b, String m) {
+ this.boolValue = b;
+ this.message = m;
+ }
+
+ public Result(boolean b) {
+ this.boolValue = b;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+
+ public boolean getBoolValue() {
+ return this.boolValue;
+ }
+}