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?

1 Answer 1

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.

1
  • 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, 2022 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.