Public
Edited
Oct 9, 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
qualifier_labels = get_labels(["P4100", "P1268", "P768", "P2715"], lang).then(
(d) => d.objects()
)
Insert cell
qualifier_map = new Map(
qualifier_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
Insert cell
qlegislature = `
SELECT ?item ?itemLabel
WHERE {
?item p:P31 ?statement.
?statement ps:P31 wd:Q15238777;
pq:P642 wd:Q8889.
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}". }
}
`
Insert cell
dlegislature = fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(qlegislature)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((response) => response.json())
Insert cell
alegislature = dlegislature.results.bindings.map((d) => ({
qid: d.item.value.replace("http://www.wikidata.org/entity/", ""),
label: d.itemLabel.value
}))
Insert cell
term_map = new Map(
alegislature.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
query = `SELECT ?item ?itemLabel ?qualifier ?qualifierLabel
?enddate
WHERE {
?item p:P39 ?statement.
?statement ps:P39 wd:Q27169;
pq:P2937 wd:${term} ;
pq:${qualifier} ?qualifier.
OPTIONAL { ?statement pq:P582 ?enddate. }
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,
qualifier: d.qualifier.value,
qualifierLabel: d.qualifierLabel.value,
enddate: d.enddate?.value
}))
Insert cell
df = aq.from(array)
Insert cell
df.view()
Insert cell
df2 = df
.groupby("qualifier", "qualifierLabel")
.count()
.orderby(aq.desc("count"))
Insert cell
Insert cell
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
lang: "en",
qualifier: "P4100",
term: "Q64038205"
};
if (params.has("qualifier")) {
defaults.qualifier = params.get("qualifier");
}
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
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