es.ucm.fdi.gaia.ontobridge
Class SPARQL

java.lang.Object
  extended by es.ucm.fdi.gaia.ontobridge.SPARQL

public class SPARQL
extends java.lang.Object

This class allows to ask SPARQL queries to the reasoner

Author:
Antonio A. Sánchez Ruiz-Granados

Constructor Summary
SPARQL(OntoBridge ob)
           
 
Method Summary
 boolean execAskQuery(java.lang.String queryStr)
          Executes a SPARQL query of type ASK (boolean query).
 com.hp.hpl.jena.rdf.model.Model execConstructQuery(java.lang.String queryStr)
          Executes a SPARQL query of type CONSTRUCT and returns a new model with the results.
 com.hp.hpl.jena.rdf.model.Model execDescribeQuery(java.lang.String queryStr)
          Executes a SPARQL query of type DESCRIBE and returns a new model with the results.
 java.util.Iterator<com.hp.hpl.jena.query.QuerySolution> execSelectQuery(java.lang.String queryStr)
          Executes a SPARQL query of type SELECT and returns an iterator over the solutions.
 void execSelectQueryAndPrint(java.lang.String queryStr, java.io.PrintStream outStream)
          Executes a SPARQL query of type SELECT and prints the result as a table in the specified stream (usually System.out)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPARQL

public SPARQL(OntoBridge ob)
Method Detail

execAskQuery

public boolean execAskQuery(java.lang.String queryStr)
Executes a SPARQL query of type ASK (boolean query). Returns true if the query has any results and false if there are no matches.


execSelectQuery

public java.util.Iterator<com.hp.hpl.jena.query.QuerySolution> execSelectQuery(java.lang.String queryStr)
Executes a SPARQL query of type SELECT and returns an iterator over the solutions. This method creates a list in memory with all the results so it must be use carefully. A query with a lot of results can exhaust the memory. To make a select query without taken care of memory, the next template must be used:
                // Create a new query
                Query query = QueryFactory.create(queryStr);

                // Execute the query and obtain results
                QueryExecution qe = QueryExecutionFactory.create(query, ONT_MODEL);
                ResultSet results = qe.execSelect();

                // Use the results as needed...
                QuerySolution sol;
                while(results.hasNext()) {
                        sol = results.nextSolution();
                        ...;
                }

                // Important - free up resources used running the query
                qe.close();
 


execSelectQueryAndPrint

public void execSelectQueryAndPrint(java.lang.String queryStr,
                                    java.io.PrintStream outStream)
Executes a SPARQL query of type SELECT and prints the result as a table in the specified stream (usually System.out)


execConstructQuery

public com.hp.hpl.jena.rdf.model.Model execConstructQuery(java.lang.String queryStr)
Executes a SPARQL query of type CONSTRUCT and returns a new model with the results.


execDescribeQuery

public com.hp.hpl.jena.rdf.model.Model execDescribeQuery(java.lang.String queryStr)
Executes a SPARQL query of type DESCRIBE and returns a new model with the results. The DESCRIBE query returns a single result RDF graph containing RDF data about resources. This data is not prescribed by a SPARQL query, where the query client would need to know the structure of the RDF in the data source, but, instead, is determined by the SPARQL query processor. The query pattern is used to create a result set. The DESCRIBE form takes each of the resources identified in a solution, together with any resources directly named by IRI, and assembles a single RDF graph by taking a "description" from the target knowledge base. The description is determined by the query service. The syntax DESCRIBE * is an abbreviation that identifies all of the variables in a query.