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
claim_map = new Map(
claim_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 ?value ?valueLabel
?enddate
WHERE {
?item p:P39 ?statement.
?statement ps:P39 wd:Q27169;
pq:P2937 wd:${term} .
OPTIONAL { ?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,
value: d.value?.value,
valueLabel: d.valueLabel?.value,
enddate: d.enddate?.value
}))
Insert cell
df = aq.from(array)
Insert cell
df.view()
Insert cell
df2 = df.groupby("value", "valueLabel").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",
property: "P21",
term: "Q114425478"
};
if (params.has("property")) {
defaults.property = params.get("property");
}
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