Public
Edited
Mar 2, 2024
1 fork
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(
[
"P21",
"P27",
"P106",
"P101",
"P103",
"P1412",
"P6886",
"P140",
"P91",
"P172",
"P69",
"P166",
"P1387",
"P1142",
"P136"
],
lang
).then((d) => d.objects())
Insert cell
labels_map = new Map(
claim_labels.map(({ label, qid }) => [label + " (" + qid + ")", qid])
)
Insert cell
Insert cell
query = `
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?item ?value ?valueLabel
WHERE {
?item ${wdt}:${filtering_property} ${target};
wdt:P31 wd:Q5.
OPTIONAL{
?item wdt:${analytical_property} ?value.
?value rdfs:label ?valueLabel.
FILTER(LANG(?valueLabel) = "${lang}" )}
}
`
Insert cell
data = fetch(
`https://qlever.cs.uni-freiburg.de/api/wikidata?query=${encodeURIComponent(
query
)}`,
{
headers: { accept: "application/sparql-results+json" }
}
).then((d) => d.json())
Insert cell
array = data.results.bindings.map((d) => ({
item: d.item.value,
value: d.value?.value,
valueLabel: d.valueLabel?.value
}))
Insert cell
df = aq
.from(array)
.groupby(["value", "valueLabel"])
.count()
.orderby(aq.desc("count"))
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: "P21"
};
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("Margot1", 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