6

I use api.php to get the QID of something using its English label.
Example: MozambiqueQ1029

$ wget --quiet -O - "http://www.wikidata.org/w/api.php?action=wbgetentities \
  &sites=enwiki&titles=Mozambique&format=xml&props="

<?xml version="1.0"?><api success="1"><entities><entity id="Q1029" type="item" /></entities></api>

QUESTION: How to do the same with a single small SPARQL request?

Nicolas Raoul
  • 8,426
  • 5
  • 28
  • 61

1 Answers1

6

Yes, you can, but it isn't short:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE{  
  ?item ?label "Mozambique"@en.  
  ?item wdt:P31 wd:Q6256 .
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}

You can see it here.

Alexan
  • 442
  • 4
  • 13
  • This worked, but when I searched for "I Robot", I got back the 1977 progressive rock album and no way to disambiguate. – Noumenon Jun 27 '22 at 21:47