Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Wikidata labels in more than one language?

I'm traying to get the regions of Italy in both Italian and English. I can get then in one laguage with this query...

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?RegionITLabel ?ISO_code ?Geo
{
?RegionIT wdt:P31 wd:Q16110;
wdt:P300 ?ISO_code; 
wdt:P625 ?Geo 
           SERVICE wikibase:label { bd:serviceParam wikibase:language "it"  }
}

ORDER BY ?regionITLabel

... but adding another language using the standard SPARQL syntax doesn't work.

like image 538
Ivo Velitchkov Avatar asked Apr 06 '17 14:04

Ivo Velitchkov


People also ask

What is label in wikidata?

The label is the most common name that the item would be known by. It does not need to be unique, in that multiple items can have the same label, however no two items may have both the same label and the same description.

How do I find wikidata?

In the query.wikidata.org query editor, you can press Ctrl + Space (or Alt + Enter or Ctrl + Alt + Enter ) at any point in the query and get suggestions for code that might be appropriate; select the right suggestion with the up / down arrow keys, and press Enter to select it.

What is Wikidata and how do I use it?

So what is Wikidata? Wikidata is a collaboratively edited knowledge base. It is a source of open data that you may want to use in your projects. Wikidata offers a query service for integrations. The query service can be accessed by navigating to query.wikidata.org If we go there, we’ll see the following screen: Figure 2. Wikidata Query Service

Is there a way to query Wikidata in Python?

This may help. There is a python package called wikidata using which you can query. Here is a sample : for entity 'Q5' you can check the label/description in eng (or other language) as shown below:

Why can't Wikidata provide labels for properties in the WD namespace?

Perhaps the problem was that Wikidata supplies labels for entities in the wd: namespace only. In order to provide labels for properties in the wdt: namespace, one have to use the special predicate wikibase:directClaim, which connects the wd: namespace entity for the property to its wdt: namespace representation.

How do I edit a Wikidata page?

The link to edit the Wikidata page, in grey, in the lateral pane. From a Wikipedia page, you can go to the link "Wikidata item", using "Tools" in the lateral pane (in the left), to see and edit it. Also in Tools, there is another link to "page information", where is "Wikidata item ID", that contains the QID (for example: Q171 or "None").


1 Answers

... but adding another language using the standard SPARQL syntax doesn't work.

How are you doing that? This works:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?label (lang(?label) as ?label_lang)  ?ISO_code ?Geo
{
    ?RegionIT wdt:P31 wd:Q16110;
              wdt:P300 ?ISO_code; 
              wdt:P625 ?Geo ;
              rdfs:label ?label
}
order by ?RegionIT

Link to try query

To limit to just Italian and English filter on the lang:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?label ?ISO_code ?Geo
{
    ?RegionIT wdt:P31 wd:Q16110;
              wdt:P300 ?ISO_code; 
              wdt:P625 ?Geo ;
              rdfs:label ?label
    filter(lang(?label) = 'it' || lang(?label) = 'en')
}
order by ?RegionIT

Link to try query

Obviously that multiplies the number of results, one for each language. If that's an issue you can do:

...
rdfs:label ?label_it , ?label_en
filter(lang(?label_it) = 'it' && lang(?label_en) = 'en')
...

which is effectively what the language service does.

like image 182
user205512 Avatar answered Sep 22 '22 13:09

user205512