Public
Edited
Nov 3
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
labels = get_labels([filtering_property, filtering_target], lang).then((d) =>
d.objects()
)
Insert cell
Insert cell
query = `SELECT ?property ?propertyLabel (COUNT(*) AS ?count) WHERE {
SELECT DISTINCT ?item ?itemLabel ?property ?propertyLabel WHERE {
?item ${wdt}:${filtering_property} ${target}.
?item ?p ?statement.
?statement ?ps ?ps_.
?property wikibase:claim ?p;
wikibase:statementProperty ?ps.
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang},mul,en". }
}
}
GROUP BY ?property ?propertyLabel
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) => ({
property: d.property.value,
propertyLabel: d.propertyLabel.value,
count: parseInt(d.count.value)
}))
Insert cell
df = aq
.from(array)
.derive({
property2: (d) =>
op.replace(d.property, "http://www.wikidata.org/entity/", "")
})
.derive({
property3: (d) => d.propertyLabel + " (" + d.property2 + ")"
})
Insert cell
Insert cell
Insert cell
import { get_labels } from "@pac02/what-kind-of-articles-have-you-created"
Insert cell
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
filtering_property: "P179",
filtering_target: "Q7888355",
reverse: false,
lang: "en"
};
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");
}

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