Monday, November 13, 2006

Early SPARQL Impressions

I postponed blogging this, then had to relearn this morning how I did it -shame!

Spent my first significant amount of time with SPARQL in the middle of last week and had to struggle with it a bit before getting the hang of it. I seem to get more (initially) out of struggling than reading through documentation -but will do that later for the advanced syntax.

TopBraid Composer has a decent SPARQL interface, very handy and has enough smarts that it is aware of local prefixes, they need not be specified via PREFIX. I wish it had a little more sanity checking though, it doesn't complain if you SELECT a variable that is never defined in the WHERE, it silently returns an empty list of results. Some of my typos got through in that way leading me to think I had malformed WHERE syntax.

I've got to find out what "." really means, right now I view it as a pipe where the result set from the first part of a condition are fed into the next. That is each successive predicate operates only on the set found by the preceding predicate. No space is needed after the "." and the end of the predicate string, and the dot after the final predicate is optional.

This took me a number of tries, How to find the rdfs:labels of instances of some subclass:

SELECT ?label
WHERE {
?sub rdfs:subClassOf foo:Bar .
?inst rdf:type ?sub .
?inst rdfs:label ?label
}

Which I read as bottom-to-top as "find all labels, of all instances, of all subclasses of foo:Bar". Or top-to-bottom as "find all subclasses of foo:Bar, then find all instances of the subclasses, then all the labels of the instances". Maybe there is a cdecl for SPARLQ.

The Jena SPARQL page has a tutorial along with a list to other tutorials.

1 comment:

Unknown said...

Not sure about your interpretation of ".", it's just a random bit of punctuation to separate triples, without any real meaning.

I like to imagine such a group of triples as a graph pattern that can match in various ways on the data graph. Each possible way of matching it becomes one solution.