Public
Edited
Jan 3
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { get_labels } from "@pac02/what-kind-of-articles-have-you-created"
Insert cell
import { aq, op } from "@uwdata/arquero"
Insert cell
import { wikipedias } from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
occupations = get_labels(
["Q33999", "Q901", "Q482980", "Q82955", "Q639669", "Q1930187", "Q483501"],
lang
).then((d) => d.objects())
Insert cell
occupations1 = get_labels(["Q901", "Q482980", "Q82955"], lang).then((d) =>
d.objects()
)
Insert cell
genders = get_labels(
["Q6581072", "Q1052281", "Q2449503", "Q48270", "Q6581097"],
lang
).then((d) => d.objects())
Insert cell
occupation_map = new Map(
occupations.map(({ label, qid }) => [label + " (" + qid + ")", "wd:" + qid])
)
Insert cell
occupation_map.set("Any occupation", "[]")
Insert cell
gender_map = new Map(
genders.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
query = `SELECT ?item ?itemLabel ?itemDescription ?sitelinks WHERE {
?item wdt:P31 wd:Q5 ;
(wdt:P106/(wdt:P279*)) ${occupation} ;
wdt:P21 wd:${gender} ;
wdt:P27 wd:${country};
wikibase:sitelinks ?sitelinks.
MINUS { ?sitelink schema:about ?item;
schema:isPartOf <https://${wiki}/>.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}". }
}
ORDER BY DESC (?sitelinks)
LIMIT 100`
Insert cell
url = `https://query-main.wikidata.org/sparql?query=${encodeURIComponent(
query
)}`
Insert cell
data = fetch(url, {
headers: { accept: "application/sparql-results+json" }
}).then((d) => d.json())
Insert cell
array = data.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
itemDescription: d.itemDescription?.value,
sitelinks: d.sitelinks.value
}))
Insert cell
df = aq
.from(array)
.dedupe()
.derive({ item2: (d) => `<a href="${d.item}"> ${d.itemLabel}` })
Insert cell
codes = FileAttachment("query.json").json()
Insert cell
// https://query.wikidata.org/#SELECT%20%3Fcodeiso2%20%3Fcodeiso3%20%3Fitem%20%3FitemLabel%20%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22.%20%7D%0A%20%20%3Fitem%20p%3AP463%20%3Fstatement.%0A%20%20%3Fstatement%20ps%3AP463%20wd%3AQ1065.%0A%20%20MINUS%20%7B%20%3Fstatement%20pq%3AP582%20%3Fend.%20%7D%0A%20%20%3Fitem%20wdt%3AP297%20%3Fcodeiso2%3B%20wdt%3AP298%20%3Fcodeiso3.%20%0A%7D%0AORDER%20BY%20%28%3Fstart%29
Insert cell
codes2 = codes.map((d) => ({
code: d.codeiso2,
country: d.itemLabel,
qid: d.item.replace("http://www.wikidata.org/entity/", "")
}))
Insert cell
codes_map = new Map(
codes2.map(({ code, country, qid }) => [country + " (" + qid + ")", qid])
)
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
country: "Q1009",
lang: "en",
wiki: "fr.wikipedia.org",
occupation: "[]",
gender: "Q6581072"
};
if (params.has("country")) {
defaults.country = params.get("country");
}
if (params.has("lang")) {
defaults.lang = params.get("lang");
}
if (params.has("wiki")) {
defaults.wiki = params.get("wiki");
}
if (params.has("occupation")) {
defaults.occupation = params.get("occupation");
}
if (params.has("gender")) {
defaults.gender = params.get("gender");
}

return defaults;
}
Insert cell
import { textcolor } from "@observablehq/text-color-annotations-in-markdown"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more