SPARQL/SERVICE - Label

You can fetch the label, alias, or description of entities you query, with language fallback, using the specialized service with the URI . 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.

The service can be used in one of the two modes: manual and automatic.

Automatic Label SERVICE
In automatic mode, you only need to specify the service template, e.g.:

and WDQS will automatically generate labels as follows: In each case, the variable in  should be bound, otherwise the service fails.
 * If an unbound variable in  is named , then WDQS produces the label  for the entity in variable.
 * If an unbound variable in  is named , then WDQS produces the alias  for the entity in variable.
 * If an unbound variable in  is named , then WDQS produces the description  for the entity in variable.

Example, showing the list of EU country names and capitals in french. For demonstation also Description and AltLabel are shown

In this example WDQS automatically creates the labels,  ,   and.

Manual Label SERVICE
In the manual mode, you explicitly bind the label variables within the service call, but WDQS will still provide language resolution and fallback.

Manual Label service is mandatory for using labels in some SPARQL functions like
 * Aggregate functions,  ,   or
 * Aggregate functions,  ,   or

Example:

This will consider labels and descriptions in French, German and English, and if none are available, will use the Q-id as the label.

Manual labels can also be used to list labels in more languages, for instance European countries in English, German and French

PS:  is added to prevent error: "there can be only one "run last" join in any group". 

It is also possible to write the above query by using  directly without the    :

Languages
You can specify a list of languages to be used as fallback in case a label does not exist in a language You specify your preferred language(s) for the label with one or more of  triples. Each string can contain one or more language codes, separated by commas. WDQS considers languages in the order in which you specify them. If no label is available in any of the specified languages, the Q-id of the entity (without any prefix) is its label.

The Wikidata Query Service website auto-magically replaces  with the language code of current user's interface. For example, if the user's UI is in French, the SPARQL's code  will be converted to   before being sent to the query service.