Skip to content

Instantly share code, notes, and snippets.

@dpjanes
Created September 28, 2020 23:12
Show Gist options
  • Save dpjanes/1d1429794a39825234f473a76efb4c2e to your computer and use it in GitHub Desktop.
Save dpjanes/1d1429794a39825234f473a76efb4c2e to your computer and use it in GitHub Desktop.
SPARQL - Query dbpedia for cities names Toronto
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