Install
openclaw skills install query-wikidataTransform natural language questions into SPARQL queries for Wikidata and generate beautiful HTML results pages. Query the Wikidata knowledge base using plain English prompts.
openclaw skills install query-wikidataUse this skill when users want to:
✅ Natural Language to SPARQL: Convert user questions into valid Wikidata SPARQL ✅ Query Execution: Execute queries against Wikidata Query Service ✅ HTML Generation: Create beautiful, interactive HTML result pages ✅ Multiple Output Formats: JSON, Markdown tables, or HTML ✅ Label Service: Automatic label resolution for human-readable results
SPARQL Endpoint: https://query.wikidata.org/sparql
Accept Header: application/sparql-results+json
Method: HTTP GET with URL-encoded query
User-Agent: Required (use Claude-Code-Wikidata-Skill/1.0)
Properties: wdt:P### (e.g., wdt:P57 for director)
Entities: wd:Q### (e.g., wd:Q51566 for Spike Lee)
Service: wikibase:label for automatic label resolution
P31 - instance of
P57 - director
P577 - publication date
P2130 - cost/budget
P50 - author
P170 - creator
P19 - place of birth
P20 - place of death
P569 - date of birth
P570 - date of death
P27 - country of citizenship
P106 - occupation
P735 - given name
P734 - family name
P1082 - population
P36 - capital
When a user provides a natural language prompt:
Find the Wikidata Q-number for the main subject:
wd:Q51566Common mappings:
wdt:P57wdt:P577wdt:P2130wdt:P19wdt:P50wdt:P1082wdt:P36Template with Label Service:
SELECT DISTINCT ?item ?itemLabel ?property
WHERE {
?item wdt:P### wd:Q### ; # property: entity
wdt:P31 wd:Q### . # instance of: type
OPTIONAL { ?item wdt:P### ?property . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY <sort_criteria>
LIMIT <number>
CRITICAL: Always include the label service for human-readable output!
Use curl with proper headers:
curl -s -G "https://query.wikidata.org/sparql" \
-H "Accept: application/sparql-results+json" \
-H "User-Agent: Claude-Code-Wikidata-Skill/1.0" \
--data-urlencode "query=<SPARQL_QUERY>"
Options:
User: "Show me movies directed by Spike Lee"
SPARQL:
SELECT DISTINCT ?film ?filmLabel ?publicationDate ?budget
WHERE {
?film wdt:P57 wd:Q51566 ; # director: Spike Lee
wdt:P31 wd:Q11424 . # instance of: film
OPTIONAL { ?film wdt:P577 ?publicationDate . }
OPTIONAL { ?film wdt:P2130 ?budget . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?publicationDate)
User: "List books written by J.K. Rowling"
SPARQL:
SELECT DISTINCT ?book ?bookLabel ?publicationDate
WHERE {
?book wdt:P50 wd:Q34660 ; # author: J.K. Rowling
wdt:P31 wd:Q7725634 . # instance of: literary work
OPTIONAL { ?book wdt:P577 ?publicationDate . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?publicationDate
User: "Who are famous physicists born in the 20th century?"
SPARQL:
SELECT ?person ?personLabel ?birthDate ?birthPlaceLabel
WHERE {
?person wdt:P106 wd:Q169470 ; # occupation: physicist
wdt:P569 ?birthDate . # date of birth
OPTIONAL { ?person wdt:P19 ?birthPlace . }
FILTER(YEAR(?birthDate) >= 1900 && YEAR(?birthDate) < 2000)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?birthDate
LIMIT 50
User: "What are the capitals of European countries?"
SPARQL:
SELECT ?country ?countryLabel ?capital ?capitalLabel ?population
WHERE {
?country wdt:P30 wd:Q46 ; # continent: Europe
wdt:P36 ?capital . # capital
?capital wdt:P1082 ?population . # population
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?population)
User: "List Nobel Prize in Literature winners"
SPARQL:
SELECT ?person ?personLabel ?awardYear
WHERE {
?person wdt:P166 wd:Q37922 ; # award received: Nobel Prize in Literature
wdt:P569 ?birthDate .
OPTIONAL { ?person wdt:P166 ?award .
?award wdt:P585 ?awardYear . }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?awardYear)
If you need to find a Q-number for an entity:
Method 1: Search Query
SELECT ?item ?itemLabel ?itemDescription
WHERE {
?item rdfs:label "Spike Lee"@en .
?item wdt:P106 wd:Q2526255 . # occupation: film director
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 5
Method 2: Use Wikidata search
When generating HTML results:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>[Query Description] - Wikidata</title>
<style>
/* Blue/green Wikidata theme */
/* Responsive design */
/* Interactive elements */
</style>
</head>
<body>
<div class="container">
<h1>[Question/Title]</h1>
<div class="wikidata-badge">Wikidata</div>
<div class="stats">[Results count]</div>
<table>[Results with Wikidata links]</table>
<div class="sparql-query">[Query code]</div>
<div class="footer">[Attribution + CC0 license]</div>
</div>
</body>
</html>
Wikidata Query Service has query timeout limits:
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }?variableLabel to get human-readable namesUse Wikidata when:
Use DBpedia when:
User: "List all films directed by Christopher Nolan with release dates and budgets"
Assistant: "I'll query Wikidata for Christopher Nolan's films.
First, I need to find his Wikidata ID..." [Searches and finds wd:Q25191]
"Executing SPARQL query against Wikidata Query Service..."
[Constructs and executes query]
"Found 12 films! Would you like the results as:
User: "HTML page"
Assistant: [Generates beautiful HTML page with Wikidata branding]
"✓ HTML page generated and saved to: ./christopher_nolan_films.html ✓ 12 films found ✓ 10 films with release dates ✓ 5 films with budget information"
Always ask the user:
"Would you like the results as:
1. JSON (raw data)
2. Markdown table (terminal display)
3. HTML page (interactive visualization)"
This skill handles:
This skill does NOT handle:
Version: 1.0.0 Endpoint: https://query.wikidata.org/sparql Data Source: Wikidata (collaborative knowledge base) License: CC0 (public domain)