Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.table(df)
Insert cell
df = get_people({ occupation: occupation })
Insert cell
get_people = ({
occupation = "Q33999",
citizenship = "Q142",
birthyear = 1970
}) => {
const query = `PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema: <http://schema.org/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?year ?gender ?genderLabel ?father ?mother ?fatherLabel ?motherLabel WHERE {
?item wdt:P31 wd:Q5;
wdt:P21 ?gender;
wdt:P106/wdt:P279* wd:${occupation};
wdt:P27 wd:${citizenship};
wdt:P569 ?birthdate;
rdfs:label ?itemLabel
FILTER(lang(?itemLabel) = "fr") .
?sitelink schema:about ?item;
schema:isPartOf <https://fr.wikipedia.org/>.
?gender rdfs:label ?genderLabel FILTER(lang(?genderLabel) = "fr") .
FILTER(YEAR( ?birthdate ) >= ${birthyear} )
BIND(YEAR(?birthdate) AS ?year)
OPTIONAL {
?item wdt:P25 ?mother.
?motherlink schema:about ?mother;
schema:isPartOf <https://fr.wikipedia.org/>.
?mother rdfs:label ?motherLabel.
FILTER(lang(?motherLabel) = "fr")
}
OPTIONAL {
?item wdt:P22 ?father.
?fatherlink schema:about ?father;
schema:isPartOf <https://fr.wikipedia.org/>.
?father rdfs:label ?fatherLabel.
FILTER(lang(?fatherLabel) = "fr")
}
}`;

return fetch(
`https://qlever.cs.uni-freiburg.de/api/wikidata?query=${encodeURIComponent(
query
)}`,
{ headers: { accept: "application/sparql-results+json" } }
)
.then((response) => response.json())
.then((res) =>
aq
.from(
res.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
year: d.year.value,
gender: d.gender?.value,
genderLabel: d.genderLabel?.value,
father: d.father?.value,
fatherLabel: d.fatherLabel?.value,
mother: d.mother?.value,
motherLabel: d.motherLabel?.value
}))
)
.derive({
number_of_parents: (d) =>
1 * (d.father !== undefined) + 1 * (d.mother !== undefined)
})
);
}
Insert cell
occupation_labels = get_labels(
["Q33999", "Q639669", "Q36180", "Q2066131", "Q82955", "Q2526255"],
"fr"
).then((d) => d.objects())
Insert cell
occupation_map = new Map(occupation_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid]))
Insert cell
Insert cell
Insert cell
import { aq, op } from "@uwdata/arquero"
Insert cell
import {get_labels} from "@pac02/what-kind-of-articles-have-you-created"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more