-1

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:

  1. What is the exact SPARQL query I want?
  2. 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)
  // ...
}
Lance
  • 75,200
  • 93
  • 289
  • 503
  • any SPARQL tutorial would make you able to write the query, especially given that the exercise already contains the identifiers ... here we go: `SELECT * WHERE {?s }` – UninformedUser Oct 27 '20 at 04:16
  • And "pagination" has to be done via `limit` and `offset`, e.g. `select ... where { ... } limit 10 offset 20` would give you a chunk of size 10 starting from "position" 20. But to be honest, for proper pagination you also need `order by` which is sometimes expensive, so without it's faster but you have to hope that the triple store does something deterministic, otherwise `select ... where { ... } limit 10 offset 20 order by ...` – UninformedUser Oct 27 '20 at 04:27
  • Try also LDF: https://query.wikidata.org/bigdata/ldf – Stanislav Kralin Oct 27 '20 at 09:06
  • This just a parser, it does not aim to do anything more. – fetahokey Nov 17 '21 at 20:37

1 Answers1

0

This Lib is just a parser, it does not aim to do anything more.

Other projects (that use SPARQL.js) exist that do what you need, such as:

fetahokey
  • 185
  • 2
  • 16