SPARQL/Wikidata Query Service
Wikimedia runs the public service instance of WDQS (Wikidata Query Service), which is available for use at http://query.wikidata.org/.
GUI
[edit | edit source]The GUI at the home page of http://query.wikidata.org/ allows you to edit and submit SPARQL queries to the query engine. The results are displayed as an HTML table. Note that every query has a unique URL which can be bookmarked for later use. Going to this URL will put the query in the edit window, but will not run it - you still have to click "Execute" for that.
One can also generate a short URL for the query via a URL shortening service by clicking the "Generate short URL" link on the right - this will produce the shortened URL for the current query.
The "Add prefixes" button generates the header containing standard prefixes for SPARQL queries. The full list of prefixes that can be useful is listed in the RDF format documentation. Note that most common prefixes work automatically, since WDQS supports them out of the box.
The GUI also features a simple entity explorer which can be activated by clicking on the "🔍" symbol next to the entity result. Clicking on the entity Q-id itself will take you to the entity page on wikidata.org.
Default views
[edit | edit source]If you run the query in the WDQS GUI, you can choose which view to present by specifying a comment: #defaultView:viewName
at the beginning of the query. Supported views are:
Table
- default view, displays the results as a table of valuesMap
- displays coordinate points if any present in the resultImageGrid
- displays images present in the result as a gridBubbleChart
- displays bubble chart for numbers found in the resultTreeMap
- displays hierarchical tree map for numbers found in the resultTimeline
- for results having dates, displays timeline placing each row at appropriate timeDimensions
- displays rows as lines between points on the scales representing each columnGraph
- displays result as a connected graph, usinglinkTo
column
SPARQL endpoint
[edit | edit source]SPARQL queries can be submitted directly to the SPARQL endpoint with a GET request to https://query.wikidata.org/sparql?query=SPARQL
POST requests can be sent to query.wikidata.org/bigdata/namespace/wdq/sparql
. The result is returned as XML by default, or as JSON if either the query parameter format=json
or the header Accept: application/sparql-results+json
are provided.
JSON format is standard SPARQL 1.1 Query Results JSON Format.
Supported formats
[edit | edit source]The following output formats are currently supported by the SPARQL endpoint:
Format | HTTP Header | Query parameter | Description |
---|---|---|---|
XML | Accept: application/sparql-results+xml | format=xml | XML result format, is returned by default. As specified in https://www.w3.org/TR/rdf-sparql-XMLres/ |
JSON | Accept: application/sparql-results+json | format=json | JSON result format, as in: https://www.w3.org/TR/sparql11-results-json/ |
TSV | Accept: text/tab-separated-values | As specified in https://www.w3.org/TR/sparql11-results-csv-tsv/ | |
CSV | Accept: text/csv | As specified in https://www.w3.org/TR/sparql11-results-csv-tsv/ | |
Binary RDF | Accept: application/x-binary-rdf-results-table |
Query timeout
[edit | edit source]There is a hard query deadline configured which is set to 60 seconds. That is true both for the GUI and the public SPARQL endpoint. If your query does not execute in the allowed time, try to optimize it, or reduce the amount of data it returns.
Every query will timeout when it takes more time to execute than this configured deadline. You may want to optimize the query or report a problematic query here mw:Wikidata_query_service/Problematic_queries
Introduction to Wikidata Query Service
[edit | edit source]See SPARQL/Wikidata Query Service - Introduction
References
[edit | edit source]Other SPARQL Endpoints
[edit | edit source]See www.w3.org/wiki/SparqlEndpoints for a list of other SPARQL Endpoints.