Skip to content

Retreieve by Path feature in the works for Graphite v2.0

I’ve been working on a rather funky new feature for Graphite v2.0. It’s a logical extension of the existing Resource Description feature, but it won’t replace it as th resource description feature lets you describe very simple paths out from a resource in a SPARQL endpoint, which gives a clear tree structure suitable for turning into JSON so that’s still kinda useful.

This new function uses a modified version of the SPARQL 1.1 path syntax. I’ve added a couple of features and cheated a bit, but it’s damn useful.

foaf:name or <> would match triples having the topic as a subject.

^foaf:member matches triples having the topic resource as the object.

foaf:member/foaf:name matches all the triples having the topic as the subject of a foaf:member triple AND where the object matches the subject of a foaf:name triple (and get that triple too). If wanted all foaf:member triples regardless of the foaf:name you can use foaf:member|foaf:member/foaf:name

You can use ! to negate a set of predicates ie. !(foaf:name|foaf:mbox) gives all triples with the topic as a subject EXCEPT foaf:name or foaf:mbox triples.

You can use regexp style +, ?, * and {n,m} to indicate that a path should be repeated. However I’ve cheated a bit here so it’s not unlimited. By default it repeats things up to 8 times so + is treated as {1,8}. That’s a bit of a cheat but it works and you can change the depth.

The additions I’ve made is “.” to match any predicate. So a path of “.”

The call will be something like this:

$graph = new Graphite();
$graph->ns( “sr”, “” );
$thing = $graph->resource( “” );
$endpoint = “” );
$n = $thing->loadSPARQLPath( $endpoint, “.|(./(rdfs:label|a))|(^sr:within)+/(rdfs:label|a)?” );

$n is set to the number of triples returned.

What this actually does is returns:

all the triples with <…/building/32> as the subject, their label and type, plus all the things within the building, or within things within the building etc. and their label and type, if any.

OK. The above query is a bit much and takes about 5 seconds to return. Turning the + on within into a {1,3} cuts it to a more reasonable 0.8 seconds.

This is just the first cut and I’m posting it here for suggestions. It’s not yet ready for integration into the core library but if you like it, have suggestions or other requests for Graphite v2.0 please leave a comment.

If you would like to help out, we could really do with someone running some kind of user community, but I just don’t have the time.

Update: Try a live demo!

Posted in Graphite.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.