5

When I want to know the Wikidata identifier of a Wikivoyage article like Barcelona, I usually run this API call:

wget --quiet -O - "http://www.wikidata.org/w/api.php?action=wbgetentities&sites=enwikivoyage&titles=Barcelona&format=xml&props=" | sed -e "s/.id=\"//" | sed -e "s/\".//"

Barcelona -> Q1492

But now I want to get the identifiers for all articles.

How can I get them without making thousands of API calls?
And also without downloading the WHOLE Wikidata database, which is probably huge.
Is there a file that contains just the Wikivoyage article name to Wikidata identifier mapping?

  • Like this ? – Stanislav Kralin Jun 28 '17 at 21:47
  • I just put LIMIT clause. I'm not sure I understand your question correctly: do you want to get all Wikiwoyage articles about Barcelona (in English, Spanish etc.), or do you want to get Wikidata entities for all Wikivoyage articles (e. g. for all en.wikivoyage.org articles)? Try this query. – Stanislav Kralin Jun 29 '17 at 7:34
  • @StanislavKralin: Sorry I did not remember my own question, I should have read it carefully. Indeed I ws asking for the identifiers of all articles, so your query is perfect. Could you please post it as an answer? Thanks! – Nicolas Raoul Jun 29 '17 at 7:45
4

Some history.

Approximately since April 2016 you can do it in this way:

SELECT ?item ?sitelink
WHERE 
{
  ?sitelink schema:about ?item .
# ?sitelink schema:inLanguage "en" .
  ?sitelink schema:isPartOf <https://en.wikivoyage.org/> 
}

Try it!

7

The dump that you want is wb_items_per_site.sql.gz. Though it contains mapping between article titles and wikidata ids for all wikis, so it's relatively big (~600 MB compressed).

And it's an SQL dump, so you can either import it into a MySQL database and query that, or you can try to parse it based on the unspecified (but reasonably stable) format.

Since you're interested in English Wikivoyage, look for enwikivoyage in the ips_site_id column.

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.