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/E04009877 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04009877 geosparql: asWKT MULTIPOLYGON (((-0.5841006504297854 50.832454827801435, -0.5924755608496696 50.83144100112009, -0.5961570290699336 50.83179743898362, -0.5999265418582824 50.83215571654189, -0.608673174626421 50.83099590000502, -0.6104553546574529 50.83367559818667, -0.6135673887511549 50.833321415653685, -0.614399270182504 50.835156066493525, -0.6163725523076244 50.83484493409566, -0.6174341204541162 50.83188609709431, -0.6226929205046869 50.832987049185704, -0.6255325512672785 50.834119538069515, -0.6250568310822919 50.83513468348969, -0.6282201699036132 50.83608295821649, -0.6367833046116882 50.836445945047345, -0.6433675483700676 50.83771340207131, -0.6451099838906823 50.83894684097707, -0.6434312380363629 50.842817829710405, -0.6430093695611767 50.84688233439639, -0.6447214275970518 50.84981150548796, -0.6504899299437386 50.85120749643896, -0.6506996597342897 50.85225941522253, -0.6491163235886644 50.85498850276385, -0.6531862532377647 50.85574596898424, -0.6524577235844655 50.857459741608615, -0.6480174133590846 50.8571242373076, -0.6444518862459296 50.856413817959655, -0.6370355698351495 50.85640663575035, -0.6326310465807703 50.85674904353679, -0.6353118272767332 50.853692168028985, -0.6217119048619351 50.85280577292411, -0.6175333120495353 50.852913748844244, -0.6132291411655361 50.85399763497837, -0.6139337605026467 50.857642854991425, -0.6119870831660655 50.86243286253562, -0.6115468797307693 50.86328377492534, -0.6064501022981884 50.861794054699, -0.5974472218871215 50.85969876400216, -0.594501712776878 50.858421368430676, -0.5911705617506168 50.8579234471612, -0.5911766381806792 50.85696662824487, -0.5890865827416849 50.85461119893928, -0.5885466411310766 50.85037328557337, -0.588896411971504 50.8490437910398, -0.5912506740929251 50.846105310918965, -0.5898876010491382 50.844528481121266, -0.5900764183712875 50.84212591753493, -0.5882594336945729 50.84128823718458, -0.5871960806410769 50.839529735375244, -0.5873397225443981 50.83716889549926, -0.586146158599611 50.83525861457705, -0.5838242697630057 50.83389312101505, -0.5841006504297854 50.832454827801435)))
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>