Mercurial > hg > semantic-sia
changeset 76:37d8b5284727
added extra query methods
author | stevenh |
---|---|
date | Fri, 02 Aug 2013 15:48:25 +0100 |
parents | bc2abbaaa23f |
children | 3172307ff0bd |
files | src/org/qmul/eecs/c4dm/sparql/utilities/SparqlWrapperMethods.java |
diffstat | 1 files changed, 99 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/qmul/eecs/c4dm/sparql/utilities/SparqlWrapperMethods.java Fri Aug 02 15:42:04 2013 +0100 +++ b/src/org/qmul/eecs/c4dm/sparql/utilities/SparqlWrapperMethods.java Fri Aug 02 15:48:25 2013 +0100 @@ -2,6 +2,8 @@ import java.util.List; +import com.clarkparsia.pellet.sparqldl.jena.SparqlDLExecutionFactory; +import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.Dataset; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -32,7 +34,37 @@ // SPARQL QueryExecution qe = QueryExecutionFactory.create(q, m); // Jena query -// QueryExecution qe = SparqlDLExecutionFactory.create(q, m); // Pellet query + + // We want to execute a CONSTRUCT query, do it, and return the new + // triples + Model newModel = qe.execConstruct(); + + // Print the query for better understanding + System.out.println(q.toString()); + + // Print the new triples + StmtIterator iter = newModel.listStatements(); + printStmts(iter); + + qe.close(); + + return newModel; + } + + /** + * @param query + * @param m + * @return + */ + public static Model executePelletConstructQuery(String query, Model m) { + + // Now read the query file into a query object + Query q = QueryFactory.read(query, Syntax.syntaxARQ); // only required + // if using + // (e.g.) LET in + // SPARQL + + QueryExecution qe = SparqlDLExecutionFactory.create(q, m); // Pellet query // We want to execute a CONSTRUCT query, do it, and return the new // triples @@ -124,6 +156,72 @@ qe.close(); } + /** + * @param query + * @param ontModel + */ + public static void queryOntModel(String query, OntModel ontModel) { + + // Now read the query file into a query object + Query q = QueryFactory.read(query, Syntax.syntaxARQ); // only required + // if using + // (e.g.) LET in + // SPARQL + + // Create a SPARQL-DL query execution for the given query and + // ontology model + QueryExecution qe = QueryExecutionFactory.create(q, ontModel); + + // We want to execute a SELECT query, do it, and return the result set + ResultSet rs = qe.execSelect(); + + // Print the query for better understanding + System.out.println(q.toString()); + + // There are different things we can do with the result set, for + // instance iterate over it and process the query solutions or, what we + // do here, just print out the results + ResultSetFormatter.out(rs); + + // And an empty line to make it pretty + System.out.println(); + + qe.close(); + } + + /** + * @param query + * @param ontModel + */ + public static void queryPelletOntModel(String query, OntModel ontModel) { + + // Now read the query file into a query object + Query q = QueryFactory.read(query, Syntax.syntaxARQ); // only required + // if using + // (e.g.) LET in + // SPARQL + + // Create a SPARQL-DL query execution for the given query and + // ontology model + QueryExecution qe = SparqlDLExecutionFactory.create(q, ontModel); // Pellet query + + // We want to execute a SELECT query, do it, and return the result set + ResultSet rs = qe.execSelect(); + + // Print the query for better understanding + System.out.println(q.toString()); + + // There are different things we can do with the result set, for + // instance iterate over it and process the query solutions or, what we + // do here, just print out the results + ResultSetFormatter.out(rs); + + // And an empty line to make it pretty + System.out.println(); + + qe.close(); + } + public static void queryDataset(String query, Dataset dataset) { // Now read the query file into a query object