Public
Edited
Apr 8, 2024
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
categories = get_labels(
[
"Q11032",
"Q2001305",
"Q1616075",
"Q14350",
"Q24634210",
"Q17232649",
"Q1002697",
"Q30849",
"Q192283"
],
lang
).then((d) => d.objects())
Insert cell
categories_map = new Map(
categories.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
query = `SELECT ?country ?countryLabel (COUNT(*) AS ?count) WHERE {
?item (wdt:P31/(wdt:P279*)) wd:${category} ;
wdt:${pcountry} ?country.
MINUS { ?item wdt:P576 [] }
?country rdfs:label ?countryLabel.
FILTER(LANG(?countryLabel) = "${lang}")
}
GROUP BY ?country ?countryLabel
ORDER BY DESC (?count)
`
Insert cell
url = `https://query.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) => ({
country: d.country.value,
countryLabel: d.countryLabel.value,
count: parseInt(d.count.value)
}))
Insert cell
df = aq.from(array).dedupe()
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
lang: "en",
category: "Q11032"
};

if (params.has("lang")) {
defaults.lang = params.get("lang");
}

if (params.has("category")) {
defaults.category = params.get("category");
}

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