Public
Edited
Apr 20, 2024
1 star
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_label } from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
label = get_label(item, lang)
Insert cell
query = `SELECT ?class ?classLabel ?classDescription ?parent ?parentLabel ?depth ?sitelinks WHERE {
SERVICE gas:service {
gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS";
gas:in wd:${item} ;
gas:linkType wdt:P279;
gas:traversalDirection "${direction}";
gas:out ?class;
gas:out1 ?depth;
gas:out2 ?parent.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}". }
?class wikibase:sitelinks ?sitelinks.
}
ORDER BY (?depth)
`
Insert cell
output = fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`,
{ headers: { accept: "application/sparql-results+json" } }
)
.then((d) => d.json())
.then((d) => d.results.bindings)
Insert cell
data = output.map((d) => ({
class: d.class.value,
classLabel: d.classLabel.value,
classDescription: d.classDescription?.value,
parent: d.parent.value,
parentLabel: d.parentLabel.value,
depth: parseInt(d.depth.value),
sitelinks: parseInt(d.sitelinks.value)
}))
Insert cell
defaults = {
const params = new URL(document.URL).searchParams;
const defaults = {
item: "Q4830453",
direction: "Forward",
lang: "en"
};
if (params.has("item")) {
defaults.item = params.get("item");
}
if (params.has("direction")) {
defaults.direction = params.get("direction");
}
if (params.has("lang")) {
defaults.item2 = params.get("lang");
}
return defaults;
}
Insert cell
import { textcolor } from "@observablehq/text-color-annotations-in-markdown"
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