BocaQuery
From IBM Semantic Layered Research Platform
Contents |
Overview
The Boca Programming Model tutorial contains an example of issuing SPARQL queries against the data stored on a Boca server. On this page, we describe the semantics of SPARQL queries on the Boca server.
Querying a Boca RDF Database
The pertinent code from the example linked to above is:
(53) String query = "SELECT ?s ?p ?o WHERE { ?s ?p ?o }";
(54) HashSet<String> defaultGraphs = new HashSet<String>();
(55) defaultGraphs.add(namedGraphURI);
(56) Graph results = datasetService.getModelService().execQuery(defaultGraphs, new HashSet<String>(), query, "http://jena.hpl.hp.com/2003/07/query/SPARQL");
(57) RDFInput rdfi = new RDFInput(ModelFactory.createModelForGraph(results));
(58) while (rdfi.hasNext()) {
(59) QuerySolution qs = rdfi.nextSolution();
(60) RDFNode s = qs.get("s");
(61) RDFNode p = qs.get("p");
(62) RDFNode o = qs.get("o");
(63) System.err.println(new StatementImpl(ResourceFactory.createResource(s.toString()), ResourceFactory.createProperty(p.toString()), ResourceFactory.createResource(o.toString())));
(64) }
And the meat of this code is call to IModelService#execQuery on line (56). The execQuery method sends a SPARQL query to the Boca server which queries the current state of the RDF data on the server. Because the query is executed directly against Boca database, any uncommitted data in this or any other client's transaction queue will not be visible to the query.
An examination of the parameters to execQuery demonstrates the semantics of querying a Boca database:
Parameter 1: Set<String> defaultNamedGraphs
A SPARQL query gets executed against an RDF dataset which is composed of a default graph and a collection of named graphs. While executing the query, triple patterns that are not within a GRAPH clause are matched against the default graph.
This parameter specifies the URIs of zero or more Boca named graphs and metadata graphs which together form the default graph for this SPARQL query. In particular, the default graph for the SPARQL query is the RDF merge of all of the graphs identified in this Set.
If a graph is explicitly mentioned in the defaultNamedGraphs set to which the logged in user does not have read access, the server will throw an exception.
If the defaultNamedGraphs set is empty, then the default graph contains no triples and any triple pattern in the query which are not within a GRAPH clause will fail to match.
Boca supports three reserved graph URIs which have special meaning. They are:
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/namedGraphs/ALL -- if this URI is present in defaultNamedGraphs, then the default graph is the merge of all Boca graphs explicitly mentioned along with all Boca named graphs on the server (modulo read access rights).
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/metadataGraphs/ALL -- if this URI is present in defaultNamedGraphs, then the default graph is the merge of all Boca graphs explicitly mentioned along with all Boca metadata graphs on the server (modulo read access rights).
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/graphs/ALL -- if this URI is present in <tt>defaultNamedGraphs, then the default graph is the merge of all Boca graphs explicitly mentioned along with all Boca named graphs and all Boca metadata graphs on the server (modulo read access rights).</tt>
Parameter 2: Set<String> namedGraphs
This parameter specifies the URIs of zero or more Boca named graphs and metadata graphs which act as the named graphs of the RDF dataset against which this query is executed. While evaluating triple patterns within a GRAPH <u> clause, the triple pattern can only match data from the graph with name u, and only if u is included in the RDF dataset. While evaluating triple patterns within a GRAPH ?g clause, ?g can be any URI of a named graph within the RDF dataset and the enclosed triple patterns can match any of those graphs. See the SPARQL specification for more details.
If a graph is explicitly mentioned in the namedGraphs set to which the logged in user does not have read access, the server will throw an exception.
If the namedGraphs set is empty, then the default graph contains no triples and any triple pattern in the query which are not within a GRAPH clause will fail to match.
Boca supports three reserved graph URIs which have special meaning. They are:
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/namedGraphs/ALL -- if this URI is present in namedGraphs, then the RDF dataset contains all Boca graphs explicitly mentioned along with all Boca named graphs on the server (modulo read access rights).
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/metadataGraphs/ALL -- if this URI is present in namedGraphs, then the RDF dataset contains all Boca graphs explicitly mentioned along with all Boca metadata graphs on the server (modulo read access rights).
- http://boca.adtech.internet.ibm.com/namedGraphs/reserved/graphs/ALL -- if this URI is present in <tt>namedGraphs, then the RDF dataset contains all Boca graphs explicitly mentioned along with all Boca named graphs and metadata graphs on the server (modulo read access rights).
Parameter 3: String query
This parameter is the SPARQL query string itself. See the SPARQL specification for the complete details on the SPARQL language. Or see a collection of SPARQL frequently asked questions.
Parameter 4: String queryLanguage
This parameter specifies the query language of query. Currently, only SPARQL queries are supported, and this parameter should be set to: <tt>http://jena.hpl.hp.com/2003/07/query/SPARQL</tt>
Return Value: Graph
The result of a CONSTRUCT or DESCRIBE query is an RDF graph. The results of a SELECT or ASK query are represented as an RDF graph using this vocabulary. A SELECT query result set is most easily processed by wrapping it in a Jena RDFInput object which allows iteration over the rows of the result set.
