Public
Edited
Mar 25, 2024
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
claim_labels = get_labels(
[
"P21",
"P27",
"P106",
"P101",
"P103",
"P1412",
"P6886",
"P140",
"P91",
"P172",
"P69",
"P166",
"P1387",
"P1142"
],
lang
).then((d) => d.objects())
Insert cell
term_labels = get_labels(["Q64038205"], lang).then((d) => d.objects())
Insert cell
groupby_labels = get_labels(["P4100", "P1268", "P768"], lang).then((d) =>
d.objects()
)
Insert cell
labels_map = new Map(
claim_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
term_map = new Map(
term_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
groupby_map = new Map(
groupby_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
Insert cell
query = `
SELECT ?item ?itemLabel
?groupby ?groupbyLabel
?value ?valueLabel WHERE {
?item p:P39 ?statement.
?statement ps:P39 wd:Q27169;
pq:P2937 wd:${term} ;
pq:${groupby} ?groupby.
MINUS { ?statement pq:P582 ?enddate. }
OPTIONAL {?item wdt:${property} ?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,
groupby: d.groupby.value,
groupbyLabel: d.groupbyLabel.value,
value: d.value?.value,
valueLabel: d.valueLabel?.value
}))
Insert cell
df = aq.from(array)
Insert cell
df.view()
Insert cell
df.groupby("groupbyLabel").count().view()
Insert cell
df.groupby("valueLabel").count().view()
Insert cell
dfshare = df
.groupby(["groupbyLabel", "valueLabel"])
.count()
.groupby("groupbyLabel")
.derive({ share: (d) => (100 * d.count) / op.sum(d.count) })
Insert cell
dfshare.view()
Insert cell
Plot.plot({
marginLeft: 150,
color: { legend: true },
y: { grid: true },
marks: [
Plot.barX(dfshare, { x: "share", y: "groupbyLabel", fill: "valueLabel" })
]
})
Insert cell
Plot.plot({
marginLeft: 150,
color: { legend: true },
y: { grid: true },
marks: [
Plot.barX(dfshare, { x: "count", y: "groupbyLabel", fill: "valueLabel" })
]
})
Insert cell
Insert cell
Insert cell
import { BubbleChart } from "@d3/bubble-chart"
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
lang: "en",
property: "P21",
groupby: "P4100" };
if (params.has("property")) {
defaults.property = params.get("property");
}
if (params.has("groupby")) {
defaults.groupby = params.get("groupby");
}
if (params.has("lang")) {
defaults.lang = params.get("lang");
}
return defaults;
}
Insert cell
get_default()
Insert cell
dicopal = require("dicopal@0.7.0")
Insert cell
palette = dicopal.getPalette("Zissou", 5)
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