Public
Edited
Nov 5, 2022
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof labels_table = Inputs.table(labels)
Insert cell
Plot.plot({
color: {
legend: true
},
width: 1000,
marginLeft: 120,
marks: [
Plot.barX(labels, {
x: "Number",
y: "Label",
sort: {
y: "x",
reverse: false
}
}),
Plot.ruleX([0])
]
})
Insert cell
Insert cell
Insert cell
viewof table_descriptions = Inputs.table(descriptions)
Insert cell
Insert cell
Insert cell
Insert cell
viewof table_aliases = Inputs.table(aliases)
Insert cell
Plot.plot({
color: {
legend: true
},
width: 1000,
marginLeft: 120,
marks: [
Plot.barX(aliases, {
x: "Number",
y: "Label",
sort: {
y: "x",
reverse: false
}
}),
Plot.ruleX([0])
]
})
Insert cell
Insert cell
Insert cell
sovereign_state_labels = d3.group(sovereign_states, d => d.Label)
Insert cell
function query_wikidata(query){
let results_json = fetch(`https://query.wikidata.org/sparql?query=${encodeURIComponent(query)}`, {headers: {accept: "application/sparql-results+json"}}).then(response => response.json())
return results_json
}
Insert cell
function parse_values(results_json) {
return results_json.results.bindings
}
Insert cell
function extract_identifiers_labels_number(result_values) {
let identifiers_labels = result_values.map(function (d) {
let output = {
Identifier: d.item.value.replace("http://www.wikidata.org/entity/", ""),
Label: d.label.value,
Number: parseInt(d.number.value)
};
return output;
});
return identifiers_labels;
}
Insert cell
function extract_identifiers_labels_date(result_values) {
let identifiers_labels = result_values.map(function (d) {
let output = {
Identifier: d.item.value.replace("http://www.wikidata.org/entity/", ""),
Label: d.label.value,
Date: d.date.value.slice(0, 10)
};
return output;
});
return identifiers_labels;
}
Insert cell
function extract_identifiers_labels(result_values) {
let identifiers_labels = result_values.map(function(d) {
let output = {
Identifier: d.item.value.replace("http://www.wikidata.org/entity/",""),
Label: d.label.value
};
return output;
})
return identifiers_labels
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cities_sparql_query = `SELECT DISTINCT ?item ?label {
?item wdt:P31 wd:Q515;
wdt:P17 wd:` + sovereign_state.Identifier + `;
rdfs:label ?label.
FILTER (lang(?label) = "en")
}`
Insert cell
cities_json = query_wikidata(cities_sparql_query)
Insert cell
cities = get_identifiers_label(cities_json)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
properties_response_json = query_wikidata(properties_query);
Insert cell
properties = get_identifiers_label_number(properties_response_json)
Insert cell
Insert cell
Insert cell
labels_query = `SELECT DISTINCT ?item ?label (count (?mlabel) as ?number) WHERE {
?item wdt:P31 wd:Q515;
wdt:P17 wd:` +
sovereign_state.Identifier +
`;
rdfs:label ?mlabel;
rdfs:label ?label.
FILTER((LANG(?label)) = "en")
}
GROUP by ?item ?label
`
Insert cell
labels_json = query_wikidata(labels_query)
Insert cell
labels = get_identifiers_label_number(labels_json)
Insert cell
Insert cell
Insert cell
descriptions_json = query_wikidata(descriptions_query)
Insert cell
descriptions = get_identifiers_label_number(descriptions_json)
Insert cell
Insert cell
Insert cell
aliases_query = `SELECT DISTINCT ?item ?label (count (?alias) as ?number) WHERE {
?item wdt:P31 wd:Q515;
wdt:P17 wd:` +
sovereign_state.Identifier +
`;
skos:altLabel ?alias;
rdfs:label ?label.
FILTER((LANG(?label)) = "en")
}
GROUP by ?item ?label`
Insert cell
aliases_json = query_wikidata(aliases_query)
Insert cell
aliases = get_identifiers_label_number(aliases_json)
Insert cell
function get_identifiers_label_number(response_json) {
let response_values = parse_values(response_json);
let values = extract_identifiers_labels_number(response_values);
return values;
}
Insert cell
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