{"skill":{"slug":"query-wikidata","displayName":"Query Wikidata using Natural Language","summary":"Transform natural language questions into SPARQL queries for Wikidata and generate beautiful HTML results pages. Query the Wikidata knowledge base using plai...","description":"---\nname: wikidata-query-skill\ndescription: Transform natural language questions into SPARQL queries for Wikidata and generate beautiful HTML results pages. Query the Wikidata knowledge base using plain English prompts.\n---\n\n# Wikidata Query Skill\n\n## When to Use This Skill\n\nUse this skill when users want to:\n- Query Wikidata using natural language\n- Get comprehensive, multilingual data about entities\n- Access property-rich information (Wikidata has extensive properties)\n- Create visualizations of Wikidata query results\n- Generate HTML reports from SPARQL queries\n- Query data with better temporal coverage than DBpedia\n\n## Core Capabilities\n\n✅ **Natural Language to SPARQL**: Convert user questions into valid Wikidata SPARQL\n✅ **Query Execution**: Execute queries against Wikidata Query Service\n✅ **HTML Generation**: Create beautiful, interactive HTML result pages\n✅ **Multiple Output Formats**: JSON, Markdown tables, or HTML\n✅ **Label Service**: Automatic label resolution for human-readable results\n\n## Wikidata Endpoint\n\n**SPARQL Endpoint**: `https://query.wikidata.org/sparql`\n**Accept Header**: `application/sparql-results+json`\n**Method**: HTTP GET with URL-encoded query\n**User-Agent**: Required (use `Claude-Code-Wikidata-Skill/1.0`)\n\n## Wikidata Naming Convention\n\n**Properties**: `wdt:P###` (e.g., `wdt:P57` for director)\n**Entities**: `wd:Q###` (e.g., `wd:Q51566` for Spike Lee)\n**Service**: `wikibase:label` for automatic label resolution\n\n## Common Wikidata Properties\n\n```\nP31  - instance of\nP57  - director\nP577 - publication date\nP2130 - cost/budget\nP50  - author\nP170 - creator\nP19  - place of birth\nP20  - place of death\nP569 - date of birth\nP570 - date of death\nP27  - country of citizenship\nP106 - occupation\nP735 - given name\nP734 - family name\nP1082 - population\nP36  - capital\n```\n\n## Query Conversion Workflow\n\nWhen a user provides a natural language prompt:\n\n### 1. Identify Entity\n\nFind the Wikidata Q-number for the main subject:\n- Use descriptive search if needed\n- Example: \"Spike Lee\" → `wd:Q51566`\n\n### 2. Map to Wikidata Properties\n\n**Common mappings:**\n- \"directed by\" → `wdt:P57`\n- \"release date\" / \"published\" → `wdt:P577`\n- \"budget\" → `wdt:P2130`\n- \"born in\" → `wdt:P19`\n- \"author\" / \"written by\" → `wdt:P50`\n- \"population\" → `wdt:P1082`\n- \"capital\" → `wdt:P36`\n\n### 3. Construct SPARQL Query\n\n**Template with Label Service:**\n```sparql\nSELECT DISTINCT ?item ?itemLabel ?property\nWHERE {\n  ?item wdt:P### wd:Q### ;     # property: entity\n        wdt:P31 wd:Q### .       # instance of: type\n  OPTIONAL { ?item wdt:P### ?property . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY <sort_criteria>\nLIMIT <number>\n```\n\n**CRITICAL**: Always include the label service for human-readable output!\n\n### 4. Execute Query\n\nUse curl with proper headers:\n```bash\ncurl -s -G \"https://query.wikidata.org/sparql\" \\\n  -H \"Accept: application/sparql-results+json\" \\\n  -H \"User-Agent: Claude-Code-Wikidata-Skill/1.0\" \\\n  --data-urlencode \"query=<SPARQL_QUERY>\"\n```\n\n### 5. Generate Output\n\n**Options:**\n- **JSON**: Raw query results\n- **Markdown Table**: Formatted for terminal display\n- **HTML Page**: Interactive, styled results page with Wikidata branding\n\n## Example Query Patterns\n\n### Pattern 1: Films by Director\n**User**: \"Show me movies directed by Spike Lee\"\n\n**SPARQL**:\n```sparql\nSELECT DISTINCT ?film ?filmLabel ?publicationDate ?budget\nWHERE {\n  ?film wdt:P57 wd:Q51566 ;        # director: Spike Lee\n        wdt:P31 wd:Q11424 .         # instance of: film\n  OPTIONAL { ?film wdt:P577 ?publicationDate . }\n  OPTIONAL { ?film wdt:P2130 ?budget . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY DESC(?publicationDate)\n```\n\n### Pattern 2: Books by Author\n**User**: \"List books written by J.K. Rowling\"\n\n**SPARQL**:\n```sparql\nSELECT DISTINCT ?book ?bookLabel ?publicationDate\nWHERE {\n  ?book wdt:P50 wd:Q34660 ;        # author: J.K. Rowling\n        wdt:P31 wd:Q7725634 .      # instance of: literary work\n  OPTIONAL { ?book wdt:P577 ?publicationDate . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY ?publicationDate\n```\n\n### Pattern 3: People by Occupation\n**User**: \"Who are famous physicists born in the 20th century?\"\n\n**SPARQL**:\n```sparql\nSELECT ?person ?personLabel ?birthDate ?birthPlaceLabel\nWHERE {\n  ?person wdt:P106 wd:Q169470 ;     # occupation: physicist\n          wdt:P569 ?birthDate .     # date of birth\n  OPTIONAL { ?person wdt:P19 ?birthPlace . }\n  FILTER(YEAR(?birthDate) >= 1900 && YEAR(?birthDate) < 2000)\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY ?birthDate\nLIMIT 50\n```\n\n### Pattern 4: Geographic Queries\n**User**: \"What are the capitals of European countries?\"\n\n**SPARQL**:\n```sparql\nSELECT ?country ?countryLabel ?capital ?capitalLabel ?population\nWHERE {\n  ?country wdt:P30 wd:Q46 ;         # continent: Europe\n           wdt:P36 ?capital .       # capital\n  ?capital wdt:P1082 ?population .  # population\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY DESC(?population)\n```\n\n### Pattern 5: Award Winners\n**User**: \"List Nobel Prize in Literature winners\"\n\n**SPARQL**:\n```sparql\nSELECT ?person ?personLabel ?awardYear\nWHERE {\n  ?person wdt:P166 wd:Q37922 ;      # award received: Nobel Prize in Literature\n          wdt:P569 ?birthDate .\n  OPTIONAL { ?person wdt:P166 ?award .\n             ?award wdt:P585 ?awardYear . }\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nORDER BY DESC(?awardYear)\n```\n\n## Finding Wikidata Entities\n\nIf you need to find a Q-number for an entity:\n\n**Method 1: Search Query**\n```sparql\nSELECT ?item ?itemLabel ?itemDescription\nWHERE {\n  ?item rdfs:label \"Spike Lee\"@en .\n  ?item wdt:P106 wd:Q2526255 .      # occupation: film director\n  SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }\n}\nLIMIT 5\n```\n\n**Method 2: Use Wikidata search**\n- Go to https://www.wikidata.org\n- Search for the entity\n- Note the Q-number in the URL\n\n## HTML Template Generation\n\nWhen generating HTML results:\n\n### Required Elements\n1. **Title**: Question or query description\n2. **Statistics**: Number of results\n3. **Table**: Results with hyperlinked Wikidata entities\n4. **SPARQL Query Display**: Show the executed query with syntax highlighting\n5. **Footer**: Link to Wikidata, attribution, license info\n\n### Wikidata Branding\n- Use blue/green color scheme (Wikidata colors)\n- Include Wikidata logo reference\n- Link to https://www.wikidata.org\n- Mention collaborative nature\n\n### HTML Template Structure\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>[Query Description] - Wikidata</title>\n    <style>\n        /* Blue/green Wikidata theme */\n        /* Responsive design */\n        /* Interactive elements */\n    </style>\n</head>\n<body>\n    <div class=\"container\">\n        <h1>[Question/Title]</h1>\n        <div class=\"wikidata-badge\">Wikidata</div>\n        <div class=\"stats\">[Results count]</div>\n        <table>[Results with Wikidata links]</table>\n        <div class=\"sparql-query\">[Query code]</div>\n        <div class=\"footer\">[Attribution + CC0 license]</div>\n    </div>\n</body>\n</html>\n```\n\n## Error Handling\n\n### Timeout Errors\nWikidata Query Service has query timeout limits:\n- Add LIMIT clause (default: 100)\n- Simplify complex joins\n- Remove unnecessary OPTIONAL clauses\n\n### No Results\n- Check entity Q-numbers\n- Verify property P-numbers\n- Suggest using Wikidata search\n\n### Label Service Issues\n- Always include: `SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". }`\n- Use `?variableLabel` to get human-readable names\n\n## Best Practices\n\n1. **Always use Label Service**: Makes results human-readable\n2. **Check Q/P numbers**: Verify entity and property identifiers\n3. **Add LIMIT**: Default to LIMIT 100\n4. **Use OPTIONAL**: For properties that may not exist\n5. **Filter by language**: When not using label service\n6. **Order results**: Make output meaningful\n7. **Include User-Agent**: Required by Wikidata Query Service\n\n## Wikidata vs DBpedia\n\n**Use Wikidata when:**\n- Need better temporal data (publication dates, birth dates)\n- Want multilingual support\n- Need comprehensive property coverage\n- Require structured identifiers (Q/P system)\n\n**Use DBpedia when:**\n- Querying Wikipedia-specific data\n- Need budget/financial information (better coverage)\n- Working with English-only queries\n\n## Example Session\n\n**User**: \"List all films directed by Christopher Nolan with release dates and budgets\"\n\n**Assistant**:\n\"I'll query Wikidata for Christopher Nolan's films.\n\nFirst, I need to find his Wikidata ID...\"\n[Searches and finds wd:Q25191]\n\n\"Executing SPARQL query against Wikidata Query Service...\"\n\n[Constructs and executes query]\n\n\"Found 12 films! Would you like the results as:\n1. JSON\n2. Markdown table\n3. HTML page\"\n\n**User**: \"HTML page\"\n\n**Assistant**:\n[Generates beautiful HTML page with Wikidata branding]\n\n\"✓ HTML page generated and saved to: ./christopher_nolan_films.html\n✓ 12 films found\n✓ 10 films with release dates\n✓ 5 films with budget information\"\n\n## Output Preferences\n\nAlways ask the user:\n```\n\"Would you like the results as:\n1. JSON (raw data)\n2. Markdown table (terminal display)\n3. HTML page (interactive visualization)\"\n```\n\n## Scope\n\n**This skill handles:**\n- Queries about entities in Wikidata\n- Structured data extraction with properties\n- Multi-property queries\n- Temporal queries (dates, years)\n- Result formatting and visualization\n\n**This skill does NOT handle:**\n- Full-text search (use Wikidata search instead)\n- Data modification (read-only queries)\n- Non-English labels (configure in label service)\n\n## Important Notes\n\n- **User-Agent Required**: Always include User-Agent header\n- **Rate Limiting**: Be respectful of query service limits\n- **Query Timeout**: 60 seconds maximum\n- **License**: All Wikidata data is CC0 (public domain)\n\n---\n\n**Version**: 1.0.0\n**Endpoint**: https://query.wikidata.org/sparql\n**Data Source**: Wikidata (collaborative knowledge base)\n**License**: CC0 (public domain)\n","topics":["Knowledge Base"],"tags":{"latest":"1.0.0"},"stats":{"comments":0,"downloads":244,"installsAllTime":9,"installsCurrent":0,"stars":0,"versions":1},"createdAt":1771428015510,"updatedAt":1778491574637},"latestVersion":{"version":"1.0.0","createdAt":1771428015510,"changelog":"Initial release of Wikidata Query Skill – enables natural language questions to be converted into SPARQL queries for Wikidata with beautiful HTML results.\n\n- Convert plain English prompts into valid SPARQL queries for Wikidata\n- Execute queries against the Wikidata Query Service with correct headers\n- Generate interactive and branded HTML, Markdown, or JSON results\n- Includes property/entity mapping guidelines and common query templates\n- Provides detailed workflow, error handling, and best practices for Wikidata access","license":null},"metadata":null,"owner":{"handle":"kidehen","userId":"s1773wqn3fkz8v78zj1bq7jpv9842m4y","displayName":"Kingsley Idehen","image":"https://avatars.githubusercontent.com/u/1541745?v=4"},"moderation":null}