I notice that some books on Wikidata have Project Gutenberg ebook IDs. Is it possible to construct a query on the Wikidata Query Service that looks for all books that have this property? I'm new to SPARQL.
Asked
Active
Viewed 210 times
0
-
Can you show an example of a book on Wikidata that has this ebook ID? – Jeen Broekstra Feb 27 '19 at 22:58
-
Sure: https://www.wikidata.org/wiki/Q6511 – Jonathan Feb 28 '19 at 00:40
1 Answers
4
As you can see if you hover over the link for the Project Gutenberg e-book Id on https://www.wikidata.org/wiki/Q6511, the actual property code to be used in SPARQL is https://www.wikidata.org/wiki/Property:P2034, or wdt:P2034
for short.
To retrieve all items with e-book IDs through SPARQL is then simply a matter of doing a basic triple match:
SELECT ?work ?bookId
WHERE { ?work wdt:P2034 ?bookId }
Of course you can extend this query how you see fit. For example to retrieve the (English) title of the book instead of just the identifier, you can do something like this:
SELECT ?title ?ebook_id
WHERE {
?work rdfs:label ?title;
wdt:P2034 ?ebook_id.
FILTER(langMatches(lang(?title), "en"))
}
It's all a matter of adding the right combination of triple patterns and filters.

Jeen Broekstra
- 21,642
- 4
- 51
- 73