Wikidata and the Chain of Death

A quick demonstration of how you can put Wikidata to use

In 2012, I conducted an interview with Lydia Pintscher, who was at the time Head of Communications for the Wikidata project. As we talked, Wikidata was still under development but its potential was nevertheless clear and exciting.

Wikidata is a knowledge base, something that allows you to store facts about the world and then process those facts to deduce conclusions. Wikidata people use the ‘Female Mayors Problem’ as an illustrative example: A user wishes to know how many mayors are female and so consults Wikidata. The system keeps records of every mayor in the world and stores discrete pieces of information about each (date of birth, gender, etc). When the user enters their query, Wikidata inspects every mayor and counts how many of them have a female gender.

Mayors are not the only things it knows about. As of May 2016 it contains over 17 million items covering an encyclopaedic range of knowledge. This shouldn’t surprise, given that it is run by the Wikimedia Foundation, the body behind Wikipedia. They have put Wikidata to use as an information source for the famous online encyclopaedia. But the Foundation also makes Wikidata openly available to anyone. As you can imagine, anyone who helps users seek out information relishes the prospects.

I decided to explore Wikidata, see what can be done with it and how easy it is to use. I created a little program I call the Chain of Death. Let me explain it.

Stephen Fry tells an anecdote about meeting the late journalist, Alastair Cooke. When they shook hands, Cooke pointed out that his own hand had also shook the hand of Bertrand Russell. Fry was impressed.

“No, no,” said Cooke, “it goes further than that. Bertrand Russell’s aunt danced with Napoleon. That’s how close we all are to history. Just a few handshakes away.”¹

To get a sense of how close we are to history, I wrote a program that uses Wikidata to build a chain of famous people that starts with you and goes backwards in time. The program starts by finding the record of a random person who died on your birthdate. When you run the program once more, it finds a second random person (one who died on the previous person’s birthdate), and so on. After just half a dozen runs, the program should have produced a chain stretching back to the Middle Ages.

The program is a web page with a few lines of JavaScript code behind it. The really interesting part is where the code makes use of Wikidata. Let’s break it down.

var url = wdk.sparqlQuery(query)

This creates a URL which, when you request it, returns from Wikidata a list of people who died on that date. wdk is a Wikidata library imported by the web page. Let’s look at the query we’re supplying (which was created in the buildQueryfunction).

return `
SELECT DISTINCT ?h ?dob ?dod ?hLabel ?hDescription ?article
?h wdt:P31 wd:Q5 .
?h wdt:P569 ?dob .
?h wdt:P570 ?dod .
?h schema:description ?hDescription .
?article schema:inLanguage "en" .
?article schema:about ?h
FILTER (?dod = "${date}"^^xsd:dateTime)
    SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .

This is the typical way of getting information from Wikidata: using SparQL, a query language reminiscent of SQL. There’s no space here to go into SparQL, but it is a more complex tool to use than classic SQL. For me, this was the trickiest part of the project (although the Query Tool helped immensely). Put simply, the query returns up to 50 matching items and several of their properties (birthdate, deathdate, description and a Wikipedia link).

The results are returned in the form of a JSON object. My program picks one of them at random and adds it to the chain.

My program demonstrates just one frivolous way you can use Wikidata (it’s available on my GitHub). With the whole of human knowledge becoming available, the possibilities of Wikidata are endless.

This article was written for 4K Byte Size, a series of articles that are a maximum of 4,096 characters in length.


¹ Stephen Fry, The Fry Chronicles.