Shlomi Uziel
Shlomi Uziel

Reputation: 908

Fetching entities label data using SPARQL in Wikidata

I am using wikidata Query Service to fetch data: https://query.wikidata.org/

I have already managed to use an entity's label using 2 methods:

  1. Using wikibase label service. For example:
SELECT ?spouse ?spouseLabel WHERE {
   wd:Q1744 wdt:P26 ?spouse.
   SERVICE wikibase:label {
     bd:serviceParam wikibase:language "en" .
   }
}
  1. Using the rdfs:label property:
SELECT ?spouse ?spouseLabel WHERE {
   wd:Q1744 wdt:P26 ?spouse.
   ?spouse rdfs:label ?spouseLabel. filter(lang(?spouseLabel) = "en").
}

However, it seems that for complex queries, the second method performs faster, in contrary to what the MediaWiki user manual states:

The service is very helpful when you want to retrieve labels, as it reduces the complexity of SPARQL queries that you would otherwise need to achieve the same effect.

(https://www.mediawiki.org/wiki/Wikidata_query_service/User_Manual#Label_service)

What does the wikibase add that I can't achieve using just rdfs:label? It seems odd since they both seemingly achieve the same purpose, but rdfs:label method seems faster (which is logical, becuase the query does not need to join data from external sources).

Thanks!

Upvotes: 5

Views: 1030

Answers (1)

atineoSE
atineoSE

Reputation: 4107

As I understand from the documentation, the wikibase label service simplifies the query by removing the need to explicitly search for labels. In that regard it reduces complexity of the query you need to write, in terms of syntax.

I would assume that the query is then expanded to another representation, maybe with the rdfs namespace like in your second option, before actually being resolved.

As per the second option being faster, have you done a systematic benchmarking? In a couple of tries of mine, the first option was faster. I would assume that performance of the public endpoint is anyways subject to fluctuation based upon demand, caching, etc so it may be tricky to draw conclusions on performance for similar queries.

Upvotes: 5

Related Questions