Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active June 22, 2019 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knbknb/580c6a1a11eefe69304699499f76650a to your computer and use it in GitHub Desktop.
Save knbknb/580c6a1a11eefe69304699499f76650a to your computer and use it in GitHub Desktop.
Wikidata: Search for Company/Banks Headquarters
# see https://stackoverflow.com/questions/56539793/wikidata-sparql-get-company-entities-and-the-location-of-their-headquarters
SELECT ?item ?itemLabel ?web ?isin ?hqLabel ?hqloc ?hqCountry ?hqCountryLabel ?inception
WHERE { #values ?item {wd:Q74687}
# for debugging
?item p:P31/ps:P31/wdt:P279* wd:Q783794.
OPTIONAL{?item wdt:P856 ?web.}
# get website
OPTIONAL{?item wdt:P946 ?isin.}
# get ISIN
OPTIONAL{?item wdt:P571 ?inception.} # get inception date
OPTIONAL{?item p:P159 ?hqStmt. # get HQ statement
?hqStmt ps:P159 ?hq. # get HQ item
?hqStmt pq:P625 ?hqloc. # get HQ coordinate location qualifier
optional {?hq wdt:P17 ?hqCountry} # optional, the country of the HQ
}
?article schema:about ?item .
?article schema:inLanguage "en" .
?article schema:isPartOf <https://en.wikipedia.org/>.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment