# HG changeset patch # User Mikel Egana Aranguren # Date 1386141420 -3600 # Node ID b8bf1af83841202b0719d43c18f8a7829371bce9 # Parent 117a4b4c002d0cd897f9262a18c5e72635adf25b Paste query added, query engine improved, examples added diff -r 117a4b4c002d -r b8bf1af83841 README --- a/README Thu Oct 25 18:35:25 2012 +0200 +++ b/README Wed Dec 04 08:17:00 2013 +0100 @@ -1,5 +1,13 @@ -INSTALLATION VIA MERCURIAL (RECOMMENDED) -======================================== +INSTALLATION VIA TOOL-SHED +========================== + +1.- Install through Admin >> Search and browse tool sheds + +2.- Copy SPARQLGalaxy.jar and SPARQLGalaxy_TEXT.jar to galaxy-dist/tool-data/shared/jars/ + + +INSTALLATION VIA MERCURIAL +========================== 1.- Stop Galaxy. @@ -9,7 +17,7 @@ hg clone http://mikel-egana-aranguren@toolshed.g2.bx.psu.edu/repos/mikel-egana-aranguren/sparql_galaxy -4.- Move to galaxy-dist/tools/sparql_galaxy and copy SPARQLGalaxy.jar to galaxy-dist/tool-data/shared/jars/ +4.- Move to galaxy-dist/tools/sparql_galaxy and copy SPARQLGalaxy.jar and SPARQLGalaxy_TEXT.jar to galaxy-dist/tool-data/shared/jars/ 5.- Add the following lines to /galaxy-dist/tool_conf.xml: @@ -45,7 +53,7 @@ 1.- Stop Galaxy. -2.- SPARQLGalaxy.jar to galaxy-dist/tool-data/shared/jars/ +2.- Copy SPARQLGalaxy.jar and SPARQLGalaxy_TEXT.jar to galaxy-dist/tool-data/shared/jars/ 3.- Create directory galaxy-dist/tools/sparql_galaxy/ diff -r 117a4b4c002d -r b8bf1af83841 SPARQLGalaxy.jar Binary file SPARQLGalaxy.jar has changed diff -r 117a4b4c002d -r b8bf1af83841 SPARQLGalaxy.xml --- a/SPARQLGalaxy.xml Thu Oct 25 18:35:25 2012 +0200 +++ b/SPARQLGalaxy.xml Wed Dec 04 08:17:00 2013 +0100 @@ -1,11 +1,28 @@ - - It executes an SPARQL query against the input OWL ontology and generates a two column tab file with the variables and bound entities + + It executes an SPARQL query against the input RDF file 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 + #if $query_type.choose_input_query_type=="query_file" + java -Xmx3000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/SPARQLGalaxy.jar $ontology $query_type.query_file_from_history > $output 2>/dev/null + #else + java -Xmx3000M -Xms250M -DentityExpansionLimit=1000000000 -jar ${__tool_data_path__}/shared/jars/SPARQLGalaxy_TEXT.jar $ontology "$query_type.pasted_query" > $output 2>/dev/null + #end if - - + + + + + + + + + + + + + + + @@ -23,13 +40,17 @@ **Usage** - An OWL ontology in RDF/XML syntax and a plain text file with the SPARQL are needed. See bundle for examples. + An RDF file (in any format that Jena can accept) and a plain text file (pasted or from history) with the SPARQL query are needed. See bundle for examples. **More information** Galaxy public instance with SPARQL-Galaxy pre-installed: - http://biordf.org:8090/ + http://biordf.org:8983/ + + RDF: + + http://www.w3.org/standards/techs/rdf SPARQL: diff -r 117a4b4c002d -r b8bf1af83841 SPARQLGalaxy_TEXT.jar Binary file SPARQLGalaxy_TEXT.jar has changed diff -r 117a4b4c002d -r b8bf1af83841 examples/jbmsquery.rdf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/jbmsquery.rdf Wed Dec 04 08:17:00 2013 +0100 @@ -0,0 +1,11 @@ + + + + + MEEPQSDPSVEPPLSQETFSDLWKLLPENNVLSPLPSQAMDDLMLSPDDIEQWFTEDPGPDEAPRMPEAAPPVAPAPAAPTPAAPAPAPSWPLSSSVPSQKTYQGSYGFRLGFLHSGTAKSVTCTYSPALNKMFCQLAKTCPVQLWVDSTPPPGTRVRAMAIYKQSQHMTEVVRRCPHHERCSDSDGLAPPQHLIRVEGNLRVEYLDDRNTFRHSVVVPYEPPEVGSDCTTIHYNYMCNSSCMGGMNRRPILTIITLEDSSGNLLGRNSFEVRVCACPGRDRRTEEENLRKKGEPHHELPPGSTKRALPNNTSSSPQPKKKPLDGEYFTLQIRGRERFEMFRELNEALELKDAQAGKEPGGSRAHSSHLKSKKGQSTSRHKKLMFKTEGPDSD + + + + \ No newline at end of file diff -r 117a4b4c002d -r b8bf1af83841 examples/query.sparql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/query.sparql Wed Dec 04 08:17:00 2013 +0100 @@ -0,0 +1,4 @@ +SELECT ?o ?s +WHERE { + ?s ?o. +} \ No newline at end of file diff -r 117a4b4c002d -r b8bf1af83841 examples/query_2.sparql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/query_2.sparql Wed Dec 04 08:17:00 2013 +0100 @@ -0,0 +1,1 @@ +SELECT * WHERE { ?s ?p ?o } LIMIT 10 \ No newline at end of file diff -r 117a4b4c002d -r b8bf1af83841 src/es/cbgp/galaxy/sparql/jena/OntologyManager.java --- a/src/es/cbgp/galaxy/sparql/jena/OntologyManager.java Thu Oct 25 18:35:25 2012 +0200 +++ b/src/es/cbgp/galaxy/sparql/jena/OntologyManager.java Wed Dec 04 08:17:00 2013 +0100 @@ -2,14 +2,14 @@ import java.io.File; -import com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.ModelFactory; public class OntologyManager { private String ontFile; private String sparqlFile; - private OntModel model; + private Model model; private SPARQLQueryEngine sqe; public OntologyManager(String of, String sf) throws Exception { @@ -19,7 +19,7 @@ } private void init() throws Exception { - this.model = ModelFactory.createOntologyModel(); + this.model = ModelFactory.createDefaultModel(); this.model.read(new File(ontFile).toURI().toString()); } diff -r 117a4b4c002d -r b8bf1af83841 src/es/cbgp/galaxy/sparql/jena/SPARQLQueryEngine.java --- a/src/es/cbgp/galaxy/sparql/jena/SPARQLQueryEngine.java Thu Oct 25 18:35:25 2012 +0200 +++ b/src/es/cbgp/galaxy/sparql/jena/SPARQLQueryEngine.java Wed Dec 04 08:17:00 2013 +0100 @@ -4,16 +4,17 @@ 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.rdf.model.Model; +import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.shared.Lock; public class SPARQLQueryEngine { - private OntModel queryModel; + private Model queryModel; private String sparqlFile; - public SPARQLQueryEngine(OntModel om) { + public SPARQLQueryEngine(Model om) { this.queryModel = om; } @@ -33,9 +34,8 @@ Iterator vars = qs.varNames(); while (vars.hasNext()) { String var = vars.next(); - if (!qs.getResource(var).isAnon()) { - res += "?" + var + "\t" + qs.getResource(var) + "\n"; - } + res += "?" + var + "\t" + getValue(qs, var) + "\r\n"; + } } return res; @@ -50,6 +50,38 @@ return null; } + private String getValue(QuerySolution qs, String var) { + RDFNode n = qs.get(var); + return n.toString(); + +// System.out.println("RDFNode (" + var + "): " + n); +// try { +// if (!qs.getResource(var).isAnon()) { +// if (qs.getResource(var).isResource()) { +// return qs.getResource(var).toString(); +// } +// if (qs.getResource(var).isLiteral()) { +// return qs.getLiteral(var).toString(); +// } +// } +// } catch (Exception e) { +// +// } +// try { +// if (!qs.getLiteral(var).isAnon()) { +// if (qs.getResource(var).isResource()) { +// return qs.getResource(var).toString(); +// } +// if (qs.getResource(var).isLiteral()) { +// return qs.getLiteral(var).toString(); +// } +// } +// } catch (Exception e) { +// +// } +// return "Error"; + } + private String loadQueryFromFile() throws Exception { String query = ""; BufferedReader bL = new BufferedReader(new FileReader(this.sparqlFile)); diff -r 117a4b4c002d -r b8bf1af83841 src/info/wilkinsonlab/galaxy/sparql/text/SPARQLGalaxy_TEXT.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/info/wilkinsonlab/galaxy/sparql/text/SPARQLGalaxy_TEXT.java Wed Dec 04 08:17:00 2013 +0100 @@ -0,0 +1,51 @@ +package info.wilkinsonlab.galaxy.sparql.text; + +import java.io.InputStream; +import java.util.Iterator; + +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.rdf.model.RDFNode; +import com.hp.hpl.jena.util.FileManager; + +public class SPARQLGalaxy_TEXT { + + /** + * @param input + * RDF + * @param SPARQL + * query + * + */ + public static void main(String[] args) { + String input_RDF_path = args[0]; + String queryString = args[1]; + Model model = ModelFactory.createOntologyModel(); + InputStream in = FileManager.get().open(input_RDF_path); + model.read(in, null); + Query query = QueryFactory.create(queryString); + QueryExecution qe = QueryExecutionFactory.create(query, model); + ResultSet results = qe.execSelect(); + String res = ""; + while (results.hasNext()) { + QuerySolution qs = results.next(); + Iterator vars = qs.varNames(); + while (vars.hasNext()) { + String var = vars.next(); + res += "?" + var + "\t" + getValue(qs, var) + "\r\n"; + System.out.println(res); + } + } + } + + private static String getValue(QuerySolution qs, String var) { + RDFNode n = qs.get(var); + return n.toString(); + } +}