I recently stumbled upon an interesting Github Repo named “Neural SPARQL Machines” that comprises CSV-based training data that can be used by an LLM to generate SPARQL from natural language-based questions.
Here are some template examples:
- Github: Neural Questions & Answers/dbpedia-201610-place.csv
- Github: Neural Questions & Answers/LC-QuAD_v6_sport.csv
Naturally, I decided to test a sampling of these templates directly via ChatGPT (version 3.5), as presented in the transcript that follows.
Transcript
Q: Given the following template.
What is the country of
<A>;select ?a where { <A> <http://dbpedia.org/ontology/country> ?a };select ?a where { ?a <http://dbpedia.org/ontology/country> [] . ?a a <http://dbpedia.org/ontology/Place> }
Find the country of London using SPARQL.
A:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country WHERE {
dbr:London dbo:country ?country .
}
Q: Repeat, but for Berlin.
A:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?country WHERE {
dbr:Berlin dbo:country ?country .
}
Q: Generate a clickable link for the generated query
A:
Clickable Link for SPARQL Query Solution
Q: Change the &query parameter to &qtxt
A:
Clickable Link for SPARQL Query Editor
Q: Given the template.
<A> is the team of which basketball players?;SELECT DISTINCT ?uri where { ?uri dbp_team <A> . ?uri a dbo_BasketballPlayer };select distinct ?a where { ?uri dbp_team ?a . ?uri a dbo_BasketballPlayer }; Generate a clickable SPARQL Query link that answers the question: What team did Michale Jordan play for.
SPARQL Query Solution: Teams Michael Jordan played for
Q: Repeat, but generating a clickable SPARQL query editor link by changing the &query parameter to &qtxt.
A:
Here’s the clickable SPARQL query editor link for the Michael Jordan teams query using the standard DBpedia SPARQL results link with the &qtxt
parameter:
SPARQL Query Editor: Teams Michael Jordan played for
When you click the link, it will open the DBpedia SPARQL query editor with the query pre-filled in the &qtxt
parameter. You can then run the query, modify it, or experiment with other queries as needed.