Platform
Resources
Pricing
Sign in
Get started
John Samuel
Workspace
Fork
Public
By
John Samuel
Edited
Nov 5, 2022
GNU GPLv3
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
sitelinks_response_json
=
query_wikidata
(
sitelinks_query
)
Insert cell
Insert cell
sitelinks
=
get_identifiers_label_number
(
sitelinks_response_json
)
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
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sovereign_state
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table_cities
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table_sitelinks
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
properties_table
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
labels_table
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table_descriptions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
table_aliases
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sovereign_state_labels
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
query_wikidata
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parse_values
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
extract_identifiers_labels_number
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
extract_identifiers_labels_date
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
extract_identifiers_labels
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sparql_query
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sovereign_states_json
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sovereign_states
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cities_sparql_query
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cities_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cities
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sitelinks_query
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sitelinks_response_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
properties_query
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sitelinks
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
properties_response_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
properties
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
labels_query
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
labels_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
labels
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
descriptions_query
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
descriptions_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
descriptions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
aliases_query
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
aliases_json
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
aliases
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
get_identifiers_label_number
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
get_identifiers_label
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML