Public
Edited
Oct 14, 2024
3 stars
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
Insert cell
Insert cell
import { get_labels } from "@pac02/what-kind-of-articles-have-you-created"
Insert cell
claim_labels = get_labels(
[
"P17",
"P21",
"P27",
"P31",
"P106",
"P101",
"P103",
"P1412",
"P6886",
"P140",
"P91",
"P172",
"P69",
"P166",
"P1387",
"P1142",
"P136",
"P1050"
],
lang
).then((d) => d.objects())
Insert cell
labels_map = new Map(
claim_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
Insert cell
query = `SELECT ?value ?valueLabel (COUNT(*) AS ?count)
WHERE {
?item ${wdt}:${filtering_property} ${target}.
?item wdt:${analytical_property} ?value.
?value rdfs:label ?valueLabel.
FILTER(LANG(?valueLabel) = "${lang}" )
}
GROUP BY ?value ?valueLabel
ORDER BY DESC(?count)
`
Insert cell
data = fetch(
`https://query-main.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((response) => response.json())
Insert cell
array = data.results.bindings.map((d) => ({
value: d.value.value,
valueLabel: d.valueLabel.value,
count: parseInt(d.count.value)
}))
Insert cell
df = aq.from(array)
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 = {
filtering_property: "P7818",
filtering_target: "",
reverse: false,
lang: "en",
analytical_property: "P31"
};
if (params.has("filtering_property")) {
defaults.filtering_property = params.get("filtering_property");
}
if (params.has("filtering_target")) {
defaults.filtering_target = params.get("filtering_target");
}
if (params.has("lang")) {
defaults.lang = params.get("lang");
}
if (params.has("reverse")) {
defaults.reverse = params.get("reverse");
}
if (params.has("analytical_property")) {
defaults.analytical_property = params.get("analytical_property");
}
return defaults;
}
Insert cell
get_default()
Insert cell
target = {
if (filtering_target == "") {
return "?target";
} else {
return "wd:" + filtering_target;
}
}
Insert cell
wdt = {
if (reverse == true) {
return "^wdt";
} else {
return "wdt";
}
}
Insert cell
dicopal = require("dicopal@0.7.0")
Insert cell
palette = dicopal.getPalette("Zissou", 5)
Insert cell
d3 = require("d3@6")
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