Skip to content

Instantly share code, notes, and snippets.

@lefuturiste
Last active December 14, 2022 20:59
Show Gist options
  • Save lefuturiste/54024821b85f721328df99302dfc30a2 to your computer and use it in GitHub Desktop.
Save lefuturiste/54024821b85f721328df99302dfc30a2 to your computer and use it in GitHub Desktop.
wikidata sparql query
# prfgen get richest countries and sort by gdp
SELECT
?pop ?gdp ?drivingSideLabel
?alpha2 ?alpha3
?country
?countryLabel
?callingCode
(GROUP_CONCAT(DISTINCT ?tldLabel; separator = ", ") AS ?tlds)
(GROUP_CONCAT(DISTINCT ?timezoneOffset; separator = ", ") AS ?timezones)
(GROUP_CONCAT(DISTINCT ?continentLabel; separator = ", ") AS ?continents)
(GROUP_CONCAT(DISTINCT ?currencyCode; separator = ", ") AS ?currencies)
(GROUP_CONCAT(DISTINCT ?voltage; separator = ", ") AS ?voltages)
(GROUP_CONCAT(DISTINCT ?frequency; separator = ", ") AS ?frequencies)
(GROUP_CONCAT(DISTINCT ?plugTypeLabel; separator = ", ") AS ?plugTypes)
(GROUP_CONCAT(DISTINCT ?capitalId; separator = ", ") AS ?capitals)
#(MD5(CONCAT(str(?country),str(RAND()))) as ?random)
WHERE {
?country wdt:P31 wd:Q3624078.
?country wdt:P297 ?alpha2.
?country wdt:P298 ?alpha3.
?country wdt:P1622 ?drivingSide.
?country wdt:P2131 ?gdp.
?country wdt:P1082 ?pop.
?country wdt:P474 ?callingCode.
?country wdt:P36 ?capital.
?capital wdt:P227 ?capitalId.
#FILTER(?pop > 65e6)
# TLD
?country wdt:P78 ?tld.
?tld wdt:P31 wd:Q42032.
?tld rdfs:label ?tldLabel filter (lang(?tldLabel) = "en").
# CONTINENT
?country wdt:P30 ?continent.
?continent rdfs:label ?continentLabel filter (lang(?continentLabel) = "en").
# Currencies
?country wdt:P38 ?currency.
?currency wdt:P498 ?currencyCode.
# Timezones
?country p:P421/ps:P421 ?timezone.
?timezone wdt:P2907 ?timezoneOffset.
#?timezone rdfs:label ?timezoneLabel filter (lang(?timezoneLabel) = "en").
# domestic electricity
?country p:P2884/ps:P2884 ?voltage. # i'm not sure about the divider operator
?country p:P2884 ?voltageStatement.
?voltageStatement pq:P2144 ?frequency.
?country wdt:P2853 ?plugType.
?plugType rdfs:label ?plugTypeLabel filter (lang(?plugTypeLabel) = "en").
#?country wikibase:sitelinks ?articles
FILTER(?gdp > 1e10)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?country ?countryLabel ?alpha2 ?alpha3 ?pop ?gdp ?callingCode ?drivingSideLabel
ORDER BY DESC(?gdp)
LIMIT 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment