Created
September 28, 2020 23:12
-
-
Save dpjanes/1d1429794a39825234f473a76efb4c2e to your computer and use it in GitHub Desktop.
SPARQL - Query dbpedia for cities names Toronto
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
const unirest = require('unirest') | |
const query = ` | |
SELECT * | |
WHERE | |
{ | |
?id | |
rdf:type <http://schema.org/City>; | |
rdf:type ?type; | |
rdfs:label ?city; | |
dbo:country ?country. | |
FILTER(STRSTARTS(LCASE(?city), "toron")) | |
FILTER(lang(?city) = 'en') | |
} | |
LIMIT 10 | |
` | |
const url = 'http://dbpedia.org/sparql/?query=' + encodeURI(query) | |
unirest | |
.get(url) | |
.headers({ | |
'Accept': 'application/json', | |
}) | |
.type('json') | |
.end((result) => { | |
if (result.error) { | |
console.log("#", result.error) | |
console.log("+", result.body) | |
} else { | |
console.log("+", JSON.stringify(result.body, null, 2)) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment