Definitions
- bash: This is the command line, where you can run relatively simple scripted programs, available on all three major computing platforms.
- SPARQL: On the Internet, there are repositories of information. Some of these repositories are in a format called RDF, or Resource Description Framework. Users of these repositories typically need a subset of the information contained in them. In order to get the desired information, they need a way to query these repositories in a structured way to get the information they want. SPARQL is that querying language.
- Wikidata is an RDF repository. It is hosted by the same organization as Wikipedia, but it is subject to different rules. I do not think Notability and some of the cultural problems of Wikipedia extend to Wikidata. I’d be happy to hear if anyone is aware of problems in the dataset, since this is one of the few times I’ve worked with it.
Inspiration
Most mornings, my wife and I read The New York Times The Morning Briefing. Typically, this will include an obituary of a celebrity. If the person is less than 80 years old, my wife will say something like, “They died young.” She thinks everyone should live to be a hundred years of age.
I tend to think more relativistically. Someone died young, if they were younger than me. It got me thinking, “Is it possible to write a script to find out who lived exactly the same number of days I have lived today?”
It turns out to be fairly easy to do using bash, a SPARQL query link and Wikidata.
bash script
#!/bin/bash
# variables
BIRTHDAY=$(date -d '2000-01-01' +%s) # enter birthday in YYYY-MM-DD format
TODAYS_DATE=$(date +%s)
DAYS_ALIVE=$(((TODAYS_DATE - BIRTHDAY) / 86400)) # converts seconds to days
# Test output
# echo "birthday: ${BIRTHDAY} | today's date: ${TODAYS_DATE} | days_alive: ${DAYS_ALIVE}"
#url for sparql query of wikidata can be obtained: https://query.wikidata.org/, click link to it below
firefox 'https://query.wikidata.org/embed.html#SELECT%20DISTINCT%20%3Fperson%20%3FpersonLabel%20%3FpersonDescription%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%22.%20%7D%0A%20%20%7B%0A%20%20%20%20SELECT%20DISTINCT%20%3Fperson%20%3FpersonLabel%20%3FpersonDescription%20%7B%0A%20%20%20%20%20%20%3Fperson%20wdt%3AP31%20wd%3AQ5%3B%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20wdt%3AP569%20%3Fborn%3B%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20wdt%3AP570%20%3Fdied%3B%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20wdt%3AP27%20wd%3AQ30%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20BIND(%3Fdied%20-%20%3Fborn%20AS%20%3FageInDays).%20%0A%20%20%20%20%20%20FILTER(%3FageInDays%20%3D%20'"$DAYS_ALIVE"').%20%20%0A%20%20%20%20%7D%0A%20%20%20%20LIMIT%2025%0A%20%20%7D%0A%7D%0A'
bash script output

SPARQL query
You can input the following into the Wikidata SPARQL query interface and change the perimeters. Specifically, the bash variable $DAYS_ALIVE needs to be changed to an integer to work in the query interface, e.g., FILTER(?ageInDays = 11000). You can also do ranges using multiplication, e.g., FILTER(?ageInDays < (31*365) && ?ageInDays > (30*365)), if you want people between the ages of 30 to 31.
SELECT DISTINCT ?person ?personLabel ?personDescription WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
{
SELECT DISTINCT ?person ?personLabel ?personDescription {
?person wdt:P31 wd:Q5; # any person
wdt:P569 ?born; # that has a birth date
wdt:P570 ?died; # and a death date
wdt:P27 wd:Q30 # that was a citizen of the United States
BIND(?died - ?born AS ?ageInDays). # calculate days they lived
FILTER(?ageInDays = $DAYS_ALIVE). # match the number of days to your current number of days alive
}
LIMIT 25
}
}