Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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
term_labels = get_labels(
[
"Q64038205",
"Q17315694",
"Q4644021",
"Q4642661",
"Q16836722",
"Q17315706",
"Q17315704",
"Q17315703",
"Q17315702"
],
lang
).then((d) => d.objects())
Insert cell
term_map = new Map(
term_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
Insert cell
query = `
SELECT DISTINCT ?item ?itemLabel ?value ?valueLabel
?sitelinks WHERE {
?item p:P39 ?statement.
?statement ps:P39 wd:Q27169;
pq:P2937 wd:${term}.
?item wikibase:sitelinks ?sitelinks.
OPTIONAL{?item wdt:P21 ?value .}
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}". }
}
`
Insert cell
data = fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((response) => response.json())
Insert cell
array = data.results.bindings.map((d) => ({
item: d.item.value,
itemLabel: d.itemLabel.value,
value: d.value?.value,
valueLabel: d.valueLabel?.value,
sitelinks: parseInt(d.sitelinks.value)
}))
Insert cell
df = aq.from(array)
Insert cell
df.groupby("valueLabel").count().view()
Insert cell
Insert cell
Insert cell
import { qnorm_winitzki, pnorm_hastings } from "@mbostock/error-function"
Insert cell
qnorm_winitzki(0.975)
Insert cell
2 * (1 - pnorm_hastings(1.96))
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
lang: "en",
term: "P21",
};
if (params.has("term")) {
defaults.term = params.get("term");
}
if (params.has("lang")) {
defaults.lang = params.get("lang");
}
return defaults;
}
Insert cell
get_default()
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