Public
Edited
Oct 17, 2024
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_label } from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
label1 = get_label(item1, lang)
Insert cell
label2 = get_label(item2, lang)
Insert cell
query1 = `SELECT ?item1 ?item1Label ?item2 ?item2Label ?wd ?wdLabel ?target ?targetLabel WHERE {
BIND(wd:${item1} AS ?item1)
BIND(wd:${item2} AS ?item2)
?item1 ?p ?statement1.
?statement1 ?ps ?target.
?wd wikibase:claim ?p;
wikibase:statementProperty ?ps.
?item2 ?p ?statement2.
?statement2 ?ps ?target.
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}". }
}
`
Insert cell
baseurl = `https://query-main.wikidata.org/sparql`
Insert cell
output1 = fetch(`${baseurl}?query=${encodeURIComponent(query1)}`, {
headers: { accept: "application/sparql-results+json" }
}).then((response) => response.json())
Insert cell
data1 = output1.results.bindings.map((d) => ({
item1: d.item1.value,
item1Label: d.item1Label.value,
item2: d.item2.value,
item2Label: d.item2Label.value,
property: d.wd.value,
propertyLabel: d.wdLabel.value,
target: d.target.value,
targetLabel: d.targetLabel?.value
}))
Insert cell
output3 = fetch(`${baseurl}?query=${encodeURIComponent(qualifier1)}`, {
headers: { accept: "application/sparql-results+json" }
}).then((response) => response.json())
Insert cell
output5 = fetch(`${baseurl}?query=${encodeURIComponent(ref1)}`, {
headers: { accept: "application/sparql-results+json" }
}).then((response) => response.json())
Insert cell
qualifier1 = `
SELECT ?item1 ?item1Label ?item2 ?item2Label ?property ?propertyLabel ?qualifier ?qualifierLabel ?target ?targetLabel WHERE {
{
SELECT ?item1 ?item2 ?property ?target ?qualifier WHERE {
BIND(wd:${item1} AS ?item1)
BIND(wd:${item2} AS ?item2)
?qualifier wikibase:qualifier ?pq.
?property wikibase:claim ?p;
wikibase:statementProperty ?ps.
?item1 ?p ?statement1.
?statement1 ?ps ?value1;
?pq ?target.
?item2 ?p ?statement2.
?statement2 ?ps ?value2;
?pq ?target.
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang} ". }
}`
Insert cell
data3 = output3.results.bindings.map((d) => ({
item1: d.item1.value,
item1Label: d.item1Label.value,
item2: d.item2.value,
item2Label: d.item2Label.value,
property: d.property.value,
propertyLabel: d.propertyLabel.value,
qualifier: d.qualifier.value,
qualifierLabel: d.qualifierLabel.value,
target: d.target.value,
targetLabel: d.targetLabel.value
}))
Insert cell
data5 = output5.results.bindings.map((d) => ({
item1: d.item1.value,
item1Label: d.item1Label.value,
item2: d.item2.value,
item2Label: d.item2Label.value,
property: d.property.value,
propertyLabel: d.propertyLabel.value,
reference: d.reference.value,
referenceLabel: d.referenceLabel.value,
target: d.target.value,
targetLabel: d.targetLabel.value
}))
Insert cell
ref1 = `SELECT DISTINCT ?item1 ?item1Label
?item2 ?item2Label
?property ?propertyLabel ?reference ?referenceLabel ?target ?targetLabel WHERE {
{
SELECT ?item1?item2 ?property ?value ?reference ?target WHERE {
BIND(wd:${item1} AS ?item1)
BIND(wd:${item2} AS ?item2)
?reference wikibase:reference ?pr.
?ref1 ?pr ?target.
?statement1 prov:wasDerivedFrom ?ref1.
?item1 ?p ?statement1.
?property wikibase:claim ?p;
wikibase:statementProperty ?ps.
?item2 ?p ?statement2.
?statement2 prov:wasDerivedFrom ?ref2.
?ref2 ?pr ?target.
}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "${lang}, en". }
}`
Insert cell
defaults = {
const params = new URL(document.URL).searchParams;
const defaults = {
item1: "Q3718",
item2: "Q8673",
lang: "en"
};
if (params.has("item1")) {
defaults.item1 = params.get("item1");
}
if (params.has("item2")) {
defaults.item2 = params.get("item2");
}
if (params.has("lang")) {
defaults.item2 = params.get("lang");
}
return defaults;
}
Insert cell
import { aq, op } from "@uwdata/arquero"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more