I have this Node.js sparql fetcher from Wikidata:
next()
async function next(offset = 0) {
const sparql = `
SELECT ?person ?pic ?givenName ?familyName ?placeOfBirth
WHERE {
?person wdt:P31 wd:Q5 .
?person wdt:P18 ?pic .
?person wdt:P735 ?givenName .
?person wdt:P734 ?familyName .
?person wdt:P19 ?placeOfBirth .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
OFFSET ${offset}
LIMIT 50`
const query = new URLSearchParams({ query: sparql }).toString();
const url = ` https://query.wikidata.org/bigdata/namespace/wdq/sparql?${query}`
console.log(url)
const res = await fetch(url, { headers: { Accept: 'application/sparql-results+json' } })
const json = await res.json()
const array = json.results.bindings
if (!array.length) {
return
}
console.log(array)
}
However, it is returning an array of values like this:
{
person: { type: 'uri', value: 'http://www.wikidata.org/entity/Q15198783' },
placeOfBirth: { type: 'uri', value: 'http://www.wikidata.org/entity/Q61' },
familyName: { type: 'uri', value: 'http://www.wikidata.org/entity/Q2658150' },
pic: {
type: 'uri',
value: 'http://commons.wikimedia.org/wiki/Special:FilePath/Charles%20Baker%202016.jpg'
},
givenName: { type: 'uri', value: 'http://www.wikidata.org/entity/Q2958359' }
}
The pic
is at least resolved, but everything else is not. How can I just get both the entity ID for each, as well as the resolved literal value for it, for all these properties?