I'm importing data from DBPedia and as you know, the vocabulary used to describe the information is not very consistent and/or complete. I'm trying to figure out a way to specify in my SPARQL query a "fallback" property in case the property I'm interested in is not set.
Example : I want to retrieve the website of a list of municipalities (one per municipality). Most of them have a property called foaf:homepage, but sometimes they don't. In this case, I want to use the property dbpprop:website instead, if it exists, and if it doesn't, as a last resort dbpedia-owl:wikiPageExternalLink often contains what I need.
The only "documentation" I could find on this matter is this blog post : Fallback with SPARQL. The proposed solution seems to be working quite well but it's, in my sense, very verbose for such a common problem. If I want to retrieve several properties, my query will be 100 lines long and I would very much like to avoid that.
Does anyone know anything about a proper way to solve this problem ?
(edit) DBPedia case
For other endpoints, good solutions can be found in the answers below, but since SPARQL 1.1 is not implemented in DBPedia's Virtuoso, BIND, COALESCE, MINUS, NOT EXISTS or property paths are not available. In addition, its interpretation of OPTIONAL seems to be counter-intuitive (addressed in this question), meaning that the last solution doesn't work.
Can we conclude that there is no way to use fallback properties on DBPedia's endpoint ?
This is possible in SPARQL 1.1 property paths
I am not sure if Virtuoso 6 supports these, but one way of finding out is as follows:
Something like (similar to Bob's blog but avoiding the cross product cases for more than 2 cases)
which makes each (after the first) OPTIONAL clause conditional on not having set
answered 15 Nov '11, 06:59
After reading the comments of the above mentioned blog post (why didn't I read them before ?), it turns out there is a simple solution "taking advantage of the fact that the OPTIONAL keyword is left-associative to express an ordered preference between predicates" (src1, src2).
The query would look like this :
... but somehow I can't make it work...
answered 15 Nov '11, 07:46
Virtuoso does support the features from above. Here is list of example collections re. Virtuoso SPARQL 1.1. support:
answered 14 Jan '13, 08:29