Trying SPARQL 1.1 new query features with ARQ
Just about all there.
When I learned that release 2.8.5 of ARQ implements all of SPARQL 1.1 Query (“except for corner cases of property paths”, and Andy Seaborne recently told me that they’ve finished up that part) I decided to try out some of the SPARQL 1.1 features, and it was all pretty easy. I used ARQ from the command line and went through Lee Feigenbaum’s slides on the status of SPARQL 1.1 as a checklist of things to try. For sample queries and data I tried to use the examples in the SPARQL 1.1 spec wherever possible, but sometimes expanded on them a bit.
Projected expressions
When I tried projected expressions using the spec’s example I got an error because of the sample query’s use of the fn:concat function, but when I added the following prefix declaration to the query it worked with no problem:
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
Aggregates
To test aggregates, the spec’s example works, but I added the following two lines to the end of the example’s data file so that org2’s author had a book with a price greater than 10:
:auth3 :writesBook :book5 .
:book5 :price 17 .
This helped to demonstrate the GROUP BY part of the query better.
Negation
The MINUS keyword and the ability to use the NOT operator with EXISTS both provide a cleaner alternative to the FILTER(!bound(?varName)) trick used in SPARQL 1.0 to make missing values part of the retrieval criteria. Lee has a slide on MINUS, but not on NOT EXISTS. I tried NOT EXISTS as well because it’s new and is grouped together with MINUS in the spec. The spec even has a subsection on the relationship and difference between NOT EXISTS and MINUS.
Using ARQ, the spec’s examples for both MINUS and NOT EXISTS worked just fine.
Property paths
The spec only has a placeholder for this for now, but when I made up my own example after looking at Lee’s slide it worked fine. Here’s my sample data:
@prefix : <http://rdfdata.org/whatever#> .
:jane :knows :frank .
:frank :knows :sarah .
:sarah :knows :steve .
The query asks for everyone that jane knows and whoever they know, transitively.
PREFIX : <http://rdfdata.org/whatever#>
SELECT ?person
WHERE {
:jane :knows+ ?person .
}
I may not have perfectly described the semantics of what that plus sign does here (an asterisk is another option), but you get the idea when you see the result:
----------
| person |
==========
| :frank |
| :sarah |
| :steve |
----------
This will let SPARQL-based applications do even more without needing an OWL inference engine, especially when used with the rdfs:subClassOf property.
Federated queries and subqueries
SPARQL 1.1 uses the same syntax for these that Jena (the framework behind ARQ) always had as an extension, so I’ve demonstrated these before in my Federated SPARQL queries blog entry of last January.
Time to play more with SPARQL 1.1
SPARQL 1.1 is no longer just a specification and something to debate about, but something we can actually play with, so go and do so and let the SPARQL Working Group know what you think. (See the paragraph beginning “Comments on this document…” in the Working Draft.) Personally, I’d prefer to see the spec include variable assignment, which are already part of Jena and ARQ (and Open Anzo) as an extension. I know that SPARQL 1.1’s new projected expressions and subqueries features can be combined for a similar effect, but that’s going to be pretty verbose. What do you think?
Share this post