Install
openclaw skills install query-dbpediaTransform natural language questions into SPARQL queries for DBpedia and generate beautiful HTML results pages. Query the DBpedia knowledge graph using plain...
openclaw skills install query-dbpediaUse this skill when users want to:
✅ Natural Language to SPARQL: Convert user questions into valid SPARQL queries ✅ Query Execution: Execute queries against DBpedia endpoint ✅ HTML Generation: Create beautiful, interactive HTML result pages ✅ Multiple Output Formats: JSON, Markdown tables, or HTML ✅ Error Handling: Graceful handling of malformed queries or no results
SPARQL Endpoint: https://dbpedia.org/sparql
Format: JSON results (format=json)
Method: HTTP GET with URL-encoded query
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dct: <http://purl.org/dc/terms/>
When a user provides a natural language prompt:
Common mappings:
dbo:directordbp:date or dbo:releaseDatedbo:budgetdbo:birthPlacedbo:populationTotaldbo:capitaldbo:authordbo:starringTemplate:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?variable ?label
WHERE {
?variable <predicate> <object> ;
rdfs:label ?label .
FILTER(LANG(?label) = 'en')
}
ORDER BY <sort_criteria>
LIMIT <number>
Use curl to execute against DBpedia:
curl -s -G "https://dbpedia.org/sparql" \
--data-urlencode "query=<SPARQL_QUERY>" \
--data-urlencode "format=json"
Options:
User: "Show me movies directed by Christopher Nolan"
SPARQL:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?film ?title ?releaseDate
WHERE {
?film dbo:director dbr:Christopher_Nolan ;
a dbo:Film ;
rdfs:label ?title .
OPTIONAL { ?film dbo:releaseDate ?releaseDate }
FILTER(LANG(?title) = 'en')
}
ORDER BY DESC(?releaseDate)
User: "What are the 10 most populous cities in France?"
SPARQL:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?city ?name ?population
WHERE {
?city dbo:country dbr:France ;
a dbo:City ;
rdfs:label ?name ;
dbo:populationTotal ?population .
FILTER(LANG(?name) = 'en')
}
ORDER BY DESC(?population)
LIMIT 10
User: "Tell me about Albert Einstein - when was he born and where?"
SPARQL:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?birthDate ?birthPlace ?placeLabel
WHERE {
dbr:Albert_Einstein dbo:birthDate ?birthDate ;
dbo:birthPlace ?birthPlace .
?birthPlace rdfs:label ?placeLabel .
FILTER(LANG(?placeLabel) = 'en')
}
When generating HTML results:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>[Query Description] - DBpedia</title>
<style>
/* Modern, responsive styling */
/* Gradient backgrounds */
/* Hover effects */
/* Mobile-first design */
</style>
</head>
<body>
<div class="container">
<h1>[Question/Title]</h1>
<div class="stats">[Results count]</div>
<table>[Results]</table>
<div class="sparql-query">[Query code]</div>
<div class="footer">[Attribution]</div>
</div>
</body>
</html>
If query returns 0 results:
If SPARQL syntax error:
If query times out:
Always ask the user:
"Would you like the results as:
1. JSON (raw data)
2. Markdown table (terminal display)
3. HTML page (interactive visualization)"
FILTER(LANG(?label) = 'en')User: "List books written by J.K. Rowling with publication dates"
Assistant: "I'll query DBpedia for books authored by J.K. Rowling.
Executing SPARQL query against DBpedia endpoint..."
[Constructs and executes query]
"Found 15 books! Would you like the results as:
User: "HTML page"
Assistant: [Generates beautiful HTML page with results]
"✓ HTML page generated and saved to: ./jk_rowling_books.html ✓ 15 books found with publication dates"
This skill handles:
This skill does NOT handle:
Version: 1.0.0 Endpoint: https://dbpedia.org/sparql Data Source: DBpedia (Wikipedia structured data)