Public
Edited
Nov 23, 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
viewof binary_information_table = Inputs.table(binary_information_units)
Insert cell
Insert cell
Insert cell
si_prefixes_json = query_wikidata(si_prefix_query)
Insert cell
si_prefixes = get_identifiers_value_labels(si_prefixes_json)
Insert cell
Insert cell
units_json = query_wikidata(units_query)
Insert cell
units = get_identifiers_labels_units_labels(units_json)
Insert cell
Insert cell
bytes_units_json = query_wikidata(information_units_query)
Insert cell
bytes_information = get_identifiers_value_labels(bytes_units_json)
Insert cell
Insert cell
binary_units_json = query_wikidata(binary_information_units_query)
Insert cell
binary_information_units = get_identifiers_value_labels(binary_units_json)
Insert cell
Insert cell
Insert cell
Insert cell
binary_information_units_query = `SELECT DISTINCT ?item ?value ?label WHERE {
?item wdt:P31 wd:Q110762970;
rdfs:label ?label;
p:P2442 ?ps.
?ps ps:P2442 ?value;
psv:P2442 ?psv.
?psv wikibase:quantityUnit wd:Q8799.
FILTER(((LANG(?label)) = "en") && (CONTAINS(?label, "ibyte")))
}
ORDER BY (?value)
`
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_value_labels(result_values) {
let identifiers_values_labels = result_values.map(function (d) {
let output = {
Identifier: d.item.value.replace("http://www.wikidata.org/entity/", ""),
Value: d.value.value,
Label: d.label.value
};
return output;
});
return identifiers_values_labels;
}
Insert cell
function get_identifiers_value_labels(response_json) {
let response_values = parse_values(response_json);
let values = extract_identifiers_value_labels(response_values);
return values;
}
Insert cell
function extract_identifiers_labels_units_labels(result_values) {
let identifiers_labels_units_labels = result_values.map(function (d) {
let output = {
Identifier: d.item.value.replace("http://www.wikidata.org/entity/", ""),
Label: d.label.value,
Unit: d.item.value.replace("http://www.wikidata.org/entity/", ""),
UnitLabel: d.unitlabel.value
};
return output;
});
return identifiers_labels_units_labels;
}
Insert cell
function get_identifiers_labels_units_labels(response_json) {
let response_values = parse_values(response_json);
let values = extract_identifiers_labels_units_labels(response_values);
return values;
}
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