Playing more with SPARQL 1.1 property paths

Some fun new features.

I recently wrote about trying SPARQL 1.1 new query features with ARQ, and one thing I briefly tried was the new property paths feature. At the time, the query spec only had a placeholder for property paths, but the new version of it released yesterday has a detailed section on property paths with plenty of examples.

I had seen the separate document where this material was first drafted and tried out its examples, (except for the "Subproperty" and "Elements in an RDF collection" ones) and they all worked fine with ARQ 2.8.5. If you want to try themselves, this zip file has the sample data file that I mocked up and the 12 query files. (Thanks to Andy Seaborne for helping me to straighten out my data and some of my tests.)

They gave me more and more ideas for interesting queries that I can do with very little SPARQL code—for example, how to get a subtree of a hierarchy, or how to find nodes that have the same connection to the same nodes that a particular node has (for example, who likes the same bands that John likes, or who has the same friends that Jane has).

If you didn't see the separate property paths draft document and you're interested in SPARQL, it's definitely worth skimming section 9 of the new query spec draft. There's a lot of neat stuff there.


Re hierarchies, I've not looked into this yet properly,... but perhaps it is then a good fit for SKOS data, which builds hierarchies with skos:broader links?


Hell yeah! I've already used it for that on work-related projects, where I've been getting much deeper into SKOS.

When you say "how to get a subtree of a hierarchy", do you mean something like in the example:

?ancestor (ex:motherOf|ex:fatherOf)+

or did have something more complex in mind, like extracting a subgraph (CONSTRUCT form)?


Something in between, I suppose, but I don't think that a CONSTRUCT form would be that complex. See for a few SKOS examples that I wrote out. A CONSTRUCT version of example 1 there would be something like

CONSTRUCT { ?c ?p ?o }
   ?c skos:broader* i:VariableStars .
   ?c ?p ?o .