Created
September 27, 2017 15:36
-
-
Save CarlQLange/2733a8de1d57b3e0712e03532451082d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WikiDataQuery = Function[query, | |
ImportString[ | |
URLRead[ | |
HTTPRequest[<| | |
"Scheme" -> "https", | |
"Domain" -> "query.wikidata.org", | |
"Path" -> "bigdata/namespace/wdq/sparql", | |
"Query" -> URLQueryEncode[<|"query" -> query|>] | |
|>, <| | |
"Headers" -> <|"Accept" -> "text/csv"|> | |
|>], | |
"Body"], | |
"Dataset", HeaderLines -> 1] | |
]; | |
(* eg | |
recentcardinals = | |
WikiDataQuery[ | |
"SELECT ?link ?linkLabel ?ageAtDeath ?dateOfBirth ?dateOfDeath \ | |
WHERE { | |
?link wdt:P31 wd:Q5. | |
?link p:P39 _:b2. | |
_:b2 ps:P39 wd:Q45722. | |
OPTIONAL { ?link wdt:P569 ?dateOfBirth. } | |
OPTIONAL { ?link wdt:P570 ?dateOfDeath. } | |
BIND((YEAR(?dateOfDeath)) - (YEAR(?dateOfBirth)) AS ?ageAtDeath) \ | |
. | |
FILTER (?dateOfBirth >= \"1900-01-01T00:00:00Z\"^^xsd:dateTime) . | |
SERVICE wikibase:label { bd:serviceParam wikibase:language \ | |
\"en\". } | |
}"] | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment