0

I'm trying to retrieve thumbnail links for a given entity name. My current query looks like the following and works for most of the cases.

select ?value { 
     <http://dbpedia.org/resource/Angela_Merkel> dbpedia-owl:thumbnail ?value 
}

However, for some cases e.g "CDU" it fails, because the entity is ambiguous. See this Example in the SPARQL Explorer.

In these cases I would like to return the thumbnail of the first wikiPageDisambiguates entry. So, for "CDU" it would be the thumbnail of this page. Can somebody tell me how to do this in SPARQL?

user2715478
  • 1,273
  • 12
  • 17

1 Answers1

0

In these cases I would like to return the thumbnail of the first wikiPageDisambiguates entry. So, for "CDU" it would be the thumbnail of this page. Can somebody tell me how to do this in SPARQL?

There's no order on these. Any representation necessarily has to put them in some order, but they're not actually ordered in the underlying RDF. You can retrieve an arbitrary one, but not "the first". For instance, look at the results from select * where { dbpedia:CDU ?p ?o }. There are a bunch of disambiguation links. Now, you can follow those links, if they are there, to get thumbnails:

select ?thumbnail where {
  dbpedia:CDU dbpedia-owl:wikiPageDisambiguates?/dbpedia-owl:thumbnail ?thumbnail
}

SPARQL results

The property path dbpedia-owl:wikiPageDisambiguates?/dbpedia-owl:thumbnail uses a question mark after the wiki page disambiguation property. That means that there can be either zero or one occurrences of the the property. Then it has to be followed by a dbpedia-owl:thumbnail link. That means that if dbpedia:CDU has a thumbnail property, you'll get it, or if it has a a disambiguation that has a thumbnail, you'll get that.

If you do want to impose some ordering, you can do that, but you'll have to determine what it should be. You can use order by to specify the ordering, and limit to specify that you want just the first one. E.g., you could do:

select ?thumbnail where {
  dbpedia:CDU dbpedia-owl:wikiPageDisambiguates? ?cdu .
  ?cdu dbpedia-owl:thumbnail ?thumbnail ;
       rdfs:label ?label
}
order by ?label
limit 1

SPARQL results

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thank you! I think it will be hard to define a general ordering for several instances. For one instance the label could work for another not. Here the label doesn't work, because "CDU" means [this](http://dbpedia.org/page/Christian_Democratic_Union_(Germany)). However, you said there is no ordering. I wonder, because in your first query the thumbnails do have the same ordering as the wikiPageDisambiguates values. Is this just pure chance? The result also seems to be deterministic. – user2715478 May 16 '15 at 15:51
  • "the same ordering as the wikiPageDisambiguates values" There *is* no ordering on the values. http://dbpedia.org/page/CDU is an HTML page, so it has to write things in some order, but there's no actual order *in the data*. If you look at [the raw data](http://dbpedia.org/data/CDU.ntriples), for instance, you'll notice that the things appear in a different order. – Joshua Taylor May 16 '15 at 15:57
  • You're right, the raw data is really not sorted. Thank you, this semantic web topic is relative new to me. I have another related question. Is it also possible to incorporate the "dbpedia-owl:wikiPageRedirects" into your presented queries? For example, "Wladimir Putin" is the same as "Vladimir Putin" [See](http://dbpedia.org/page/Vladimir_Putin). But your query returns only for the latter a result. – user2715478 May 16 '15 at 16:29
  • Sure, have a look at [Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value?](http://stackoverflow.com/q/23871225/1281433) – Joshua Taylor May 16 '15 at 16:32
  • You're really helpful and answered all my questions :) For the other readers: `select ?thumbnail where { dbpedia:Wladimir_Putin dbpedia-owl:wikiPageRedirects*/dbpedia-owl:thumbnail ?thumbnail }`. Will try to combine the redirect and disambiguation on my own. – user2715478 May 16 '15 at 16:48
  • Wait. This doesn't work for "Bayern_München" which should actually redirect to [FC_Bayern_München](http://dbpedia.org/page/FC_Bayern_Munich). The redirect is there. Any ideas? – user2715478 May 16 '15 at 17:03
  • I'm not sure what issue you're running into. It appears that the following works: `select * where { dbpedia-owl:wikiPageRedirects?/dbpedia-owl:thumbnail ?thumbnail }` – Joshua Taylor May 16 '15 at 17:07
  • Ah I see, you have to escape umlauts. Thanks again. That' it! – user2715478 May 16 '15 at 17:11
  • I know that the HTML rendering shows `is dbpedia-owl:wikiPageRedirects of dbpedia:Bayern_München`, but if you look at the results of `select * { dbpedia:FC_Bayern_Munich ^dbpedia-owl:wikiPageRedirects ?fromWhere }`, you'll notice that characters with additional diacritics are actually percent encoded. – Joshua Taylor May 16 '15 at 17:11
  • 1
    @user2715478 You don't *have* to in SPARQL or in RDF, which both use IRIs (internationalized resource identifiers), but DBpedia uses that encoding, so you need to in order to work with their data. – Joshua Taylor May 16 '15 at 17:11