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/par/E04000185 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04000185 geosparql: asWKT MULTIPOLYGON (((-1.6752814771152043 53.6539497468661, -1.6774859642786675 53.65274860347682, -1.6779618204360085 53.65105293546862, -1.6809093517167153 53.651194744738305, -1.6828880701999354 53.652020609389815, -1.6895145340781652 53.65120836615862, -1.6928232957323273 53.652239736606006, -1.6956759043743137 53.65529307007602, -1.6986232734999362 53.65614539700849, -1.7034003231290984 53.655451755912544, -1.707830668582169 53.657837289661984, -1.7119889142729394 53.65891963989328, -1.7116544622521266 53.6604773801679, -1.7149107556194094 53.663184327857635, -1.7143216066888898 53.666607411235, -1.7127220196847672 53.66770195530894, -1.7121600957340262 53.66975266985987, -1.7105577383257093 53.671660636148765, -1.7059768193740952 53.67479446538694, -1.7056180774568772 53.676743172625386, -1.708261451049213 53.67713977471578, -1.715225406712127 53.6806809515092, -1.718090368249017 53.68105267671751, -1.721398320409147 53.6838287839311, -1.7243418617220105 53.684495305377254, -1.7270400168289848 53.6861310204538, -1.7208424230987134 53.687078513429675, -1.7142670000534848 53.6898925110453, -1.7064066327841247 53.691596575592534, -1.7041600013947078 53.69280357083727, -1.6988531522533143 53.696697528551354, -1.6947320775677954 53.693542096969445, -1.6919901274408404 53.694491415257666, -1.6844200181224298 53.69521679939247, -1.6787940413258706 53.694607598518104, -1.674204853067814 53.694487245663055, -1.6711889879357757 53.69341202106984, -1.6661421668120695 53.6937287288727, -1.663476789627875 53.69050518179951, -1.6658342052631383 53.68824674432334, -1.6647727826066334 53.686908090368114, -1.661002968988918 53.68553750171487, -1.6647569013985528 53.684330175979454, -1.6683140376331924 53.68579174026864, -1.6704902635539058 53.685531736502575, -1.6745871440679123 53.67772585569074, -1.6778793224560162 53.6750131004518, -1.6727306746221722 53.67507104152095, -1.6695323828521065 53.6731046606575, -1.663983491294931 53.67288699851032, -1.6639698249683896 53.670986888069145, -1.661892839508231 53.66629377939906, -1.6610079854842235 53.66320837453655, -1.6626982790488203 53.661889201907215, -1.6690906409168753 53.659138698992585, -1.6745335523052542 53.655590736708575, -1.6752814771152043 53.6539497468661)))
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>