14

Is there a Wikidata dump that maps all Wikipedia URLs to their corresponding Wikidata entity ids, e.g. the Wikipedia URL https://en.wikipedia.org/wiki/Tom_Hanks to the Wikidata entity id Q2263?

  • 1
    What do you mean by "map"? If you just add&action=info to your URL you can see the Wikidata item and URL. – Ainali Jun 19 '15 at 7:23
  • 1
    @Ainali: en.wikipedia.org/wiki/Tom_Hanks&action=info does not give me Q2263, it gives an error page. – Nicolas Raoul Jun 19 '15 at 7:50
  • @nicolasraoul - it'll work if you use the alternative form of the URL (see below). It's a bit fiddly but the data's available. There's also a user script to display it under the page title, which is very handy... – Andrew Jun 19 '15 at 8:44
  • 1
    Typo from me, it should have been ?action=info which should work. – Ainali Jun 21 '15 at 19:38
8

If you want to do this from the dumps, you can use the wb_items_per_site dump (current version, 625 MB; most recent dumps)

For each Wikidata item, this contains rows with the corresponding page name on a given wiki project.

For individual articles, you can use &action=info on Wikipedia as Ainali suggests, but you have to use the /w/index.php?title=PAGENAME&action=info URL format, not /wiki/PAGENAME&action=info

With your example: https://en.wikipedia.org/w/index.php?title=Tom%20Hanks&action=info

6

You could also use the API. The call https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&format=json&titles=Tom%20Hanks will give you the id on Wikidata (as "wikibase_item").

6

You can also use the SPARQL service with query like:

prefix schema: <http://schema.org/>
SELECT * WHERE {
  <https://en.wikipedia.org/wiki/Tom_Hanks> schema:about ?item .
}
  • can you tell me how to execute your query and format the result in JSON (format=json)? – Jay Gray Nov 12 '18 at 14:52
3

You can also use the OpenRefine reconciliation API, which has an additional feature: it will resolve Wikipedia redirects for you.

For instance, say you want to retrieve the Qid corresponding to the page LNCS, which is a redirection to Lecture Notes in Computer Science. You can get it as follows:

https://tools.wmflabs.org/openrefine-wikidata/en/api?query=https://en.wikipedia.org/wiki/LNCS

Retrieving Qids of redirected pages will not work with the SPARQL and MediaWiki API.

1

I created a Python package and command line tool to deal with the issue called wikimapper. It can be installed via pip install wikimapper. It uses the Wikipedia SQL dumps to create an index that then can be used to map many times very fast (much faster than the Wikidata SPARQL endpoint). You could either use one of my precomputed indices and use this sqlite3 database or use the package to map Wikipedia page titles/Wikipedia URLs to Wikidata IDs and vice versa. This should be much faster than going to the network like other answers suggest and also works in 2019.

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.