Wikidata with SPARQL and ChatGPT
Tue Apr 18 2023I’ve never enjoyed SPARQL syntax and found it confussing coming from SQL. That has made me not use or explore Wikidata as much as I wanted.
This, however, seems to have changed after being able to use ChatGPT to generate the queries for me. Or at least to guide me through the process. It’s an amazing way to explore Wikidata without having to learn SPARQL syntax!
I wanted to get some data about asteroids and I was able to do it with the following query… to ChatGPT! Definitely not as accurate or detailed as an official source could be, but useful to quickly check some facts.
After some small tweaks, I got to the following query:
SELECT
?asteroidLabel
?discovered
?discovererLabel
WHERE {
?asteroid wdt:P31 wd:Q3863; # Retrieve instances of "asteroid"
wdt:P61 ?discoverer; # Retrieve discoverer of the asteroid
wdt:P575 ?discovered; # Retrieve discovered date of the asteroid
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?discovered)
The most interesting thing is that while crafting the query, I was able to learn different things that I haven’t even noticed in the past as I was mostly copy pasting queries form the examples.
For example, I didn’t know that you can use SERVICE wikibase:label
to get the labels of the entities.
This opens a whole new world of datasets and I’m looking forward to exploring more of them!