1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { wikidata } from "https://esm.town/v/stevekrouse/wikidata";
export async function alive(name) {
let data = await wikidata(
`SELECT ?person ?personLabel ?birth_date ?death_date WHERE {
?person rdfs:label "${name}"@en;
wdt:P31 wd:Q5 . # Ensure the entity is a human
OPTIONAL {
?person wdt:P570 ?death_date . # Try to find a date of death
}
OPTIONAL {
?person wdt:P569 ?birth_date . # Date of birth
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}`,
);
if (!data.results.bindings.length)
throw "Could not find " + name;
return data.results.bindings.every((b) => b.birth_date && !b.death_date);
}