I would like to query like this:
Query WikiData for all entities where the property instance of (P31) has the value human (Q5).
How do I do that using Node.js?
Searching for this on the web leads to things like this, example SPARQL queries, but I am not sure how to run those in Node.js. I see things like https://github.com/RubenVerborgh/SPARQL.js for parsing SPARQL queries, but I'm not sure how to run these queries.
Searching for a Wikidata SPARQL API gives a UI instead https://query.wikidata.org. Basically I am not sure where to start on this.
So basically my question is two parts:
- What is the exact SPARQL query I want?
- How do I paginate using the Wikidata SPARQL API?
const fetch = require('node-fetch')
async function start() {
const query = `SELECT * WHERE {<http://www.wikidata.org/entity/Q3630> <http://www.wikidata.org/prop/direct/P1376> ?o}`
const url = `https://query.wikidata.org/sparql?query=${encodeURI(query)}`
const res = await fetch(url)
// ...
}