add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank
http://opendatacommunities.org/id/geography/administration/ua/E06000008 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/ua/E06000008 geosparql: asWKT MULTIPOLYGON (((-2.4109892958350714 53.70513673126661, -2.403134725319068 53.6964225300815, -2.39152762269636 53.688622530883734, -2.374424325871603 53.68725439330033, -2.375934701583339 53.675641563215756, -2.3712361947225076 53.66708067840141, -2.3626410977657266 53.65598871868631, -2.3715154257711304 53.64328367395176, -2.370327937495287 53.63153433579744, -2.3791320989357336 53.6308703666983, -2.3978458672646186 53.632208133358915, -2.401209430827346 53.624599085936865, -2.4053755640768326 53.62514320760335, -2.419928258315156 53.623609906018736, -2.425853480913743 53.6258593993347, -2.4261437860629056 53.63501024507875, -2.43872442831135 53.64604544897465, -2.450270370945647 53.64143202035162, -2.4506439293754214 53.627805287471396, -2.466019461818752 53.62169900415622, -2.4729929209974517 53.61663185121482, -2.5104111496005395 53.626361611805955, -2.511322999287663 53.62699498930541, -2.520061653786685 53.63048163550255, -2.523759708917991 53.639100599214686, -2.522012616704359 53.64742060145953, -2.5323440495460443 53.66490228905979, -2.5255493775448725 53.67467644327618, -2.5191705640954063 53.676287070140695, -2.51537539916116 53.691668818428234, -2.53193145429127 53.696442910640904, -2.539582532017767 53.70210087402319, -2.5432607624106707 53.70989580220484, -2.5394676890942276 53.71466763997019, -2.546174909855741 53.724898921341286, -2.5564298328981936 53.72666551726527, -2.5571550098312987 53.73461207846909, -2.56459132983432 53.74245888366456, -2.561601625339473 53.746901339455036, -2.5539871081541157 53.749707790895705, -2.5512981333953157 53.75638837984822, -2.545724323900731 53.75942754479922, -2.5287791960991175 53.759475606180175, -2.509412473821972 53.76921606043562, -2.4989582698109003 53.76862007283086, -2.480826362579742 53.77399159572309, -2.4770874426468663 53.781047651727725, -2.4658077287671754 53.78081336622232, -2.4555471147138674 53.77406332961967, -2.4463170777329157 53.76658970079995, -2.4521940130108884 53.760937705966896, -2.4517803382514516 53.75645434051915, -2.4468003979347133 53.75538638130195, -2.439651184828875 53.74829976699006, -2.4398667526006768 53.735873960486245, -2.433552656870205 53.72762349360939, -2.433868615744507 53.71918168693074, -2.4109892958350714 53.70513673126661)))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:http://opendatacommunities.org/sparql, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

POST http://opendatacommunities.org/sparql HTTP/1.1
Host: opendatacommunities.org
Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded

query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):

GET http://opendatacommunities.org/sparql.json?query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
text/plain
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,
application/json

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

http://opendatacommunities.org/sparql.json?callback=myCallbackFunction&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

This help topic on the jQuery website has more details.

Examples

Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010" http://opendatacommunities.org/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://opendatacommunities.org/sparql?query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
<html>
<head>
	<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = 'http://opendatacommunities.org/sparql.json';
	$.ajax({
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');
			console.log(data);
		}
	});
</script>
</body>
</html>