Public
Edited
Jun 2, 2024
4 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
get_claim = (article, project = "en.wikipedia.org", property = "P31", lang = "en" ) => {
const query = `SELECT ?value ?valueLabel (COUNT(*) AS ?count)
WHERE {
SERVICE wikibase:mwapi {
bd:serviceParam wikibase:endpoint "` + project + `";
wikibase:api "Generator";
mwapi:generator "links";
mwapi:titles "` + article + `";.
?item wikibase:apiOutputItem mwapi:item.
}
FILTER BOUND (?item)
?item wdt:${property} ?value .
?value rdfs:label ?valueLabel filter (lang(?valueLabel) = "${lang}") .
}
GROUP BY ?value ?valueLabel
ORDER BY DESC(?count)`
return fetch(`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`, {headers: {accept: "application/sparql-results+json"}})
.then(response => response.json())
.then( d => d.results.bindings.map(res => ({
project: project,
article: article,
value: res.value.value,
valueLabel: res.valueLabel.value,
count: res.count.value
}))
)
}
Insert cell
get_claim("Sociologie", "fr.wikipedia.org", "P31", "fr")
Insert cell
get_default = () => {
const params = new URL(document.URL).searchParams;
const defaults = {
article: "Sociology",
wikipedia: "en.wikipedia.org",
lang: "en",
claim: "P31"
} ;
if (params.has("article")) {
defaults.article = params.get("article")
}
if (params.has("wikipedia")) {
defaults.wikipedia = params.get("wikipedia")
}
if (params.has("claim")) {
defaults.claim = params.get("claim")
}
if (params.has("lang")) {
defaults.lang = params.get("lang")
}
return defaults
}
Insert cell
Insert cell
Insert cell
Insert cell
import { wikipedias } from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
import { SearchForm } from "@floatingpurr/input-autocomplete"
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