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/E04004060 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/par/E04004060 geosparql: asWKT MULTIPOLYGON (((0.6886020388254537 51.709209759332346, 0.6911099668275107 51.70534532435385, 0.6897914179164993 51.705005892447254, 0.6916383256478911 51.70212878990473, 0.6900376846896358 51.701814712827584, 0.6935860352072788 51.694910821376226, 0.6922744366747591 51.69419622573938, 0.6946413727042532 51.691020251016944, 0.6945713740870413 51.68954960115663, 0.6967952317924274 51.68494597695779, 0.6932299038929618 51.68321108952929, 0.6968285858473087 51.680589598094954, 0.703088886524308 51.68176052583414, 0.7049697194243565 51.68129991082982, 0.709316519575525 51.6765382947674, 0.710990289337569 51.675449205412455, 0.7153523609403895 51.67101076668513, 0.7146195985785753 51.67029472584751, 0.7160173696378282 51.66583122862764, 0.7137266572041854 51.66467275838523, 0.710927803564856 51.66449638575591, 0.709367101435204 51.67072092974945, 0.704943113989721 51.670221253655995, 0.7051386112599674 51.666147127933215, 0.7047093400206758 51.66343285756161, 0.7053923526864214 51.6553831819545, 0.7024784266759391 51.65209751678847, 0.7034064387767025 51.649131684101626, 0.7010732428706324 51.646923526069465, 0.7013327383292353 51.64448122075422, 0.6991128354065291 51.64305465009722, 0.6997707900444522 51.64162394715009, 0.7017263819700258 51.64137840413035, 0.7033741341975184 51.63950670361736, 0.7072777034749275 51.64054093403968, 0.7110607916261811 51.63991672385643, 0.7090997594947245 51.63670006459001, 0.7067546713607338 51.636566191009905, 0.6994001378846295 51.63708986370515, 0.6959163292787588 51.63924831221029, 0.6922071915701012 51.63709855430009, 0.6903295034608402 51.637363739825176, 0.6907707252264926 51.64271373592617, 0.6919937100962767 51.64573898137622, 0.6937937991523709 51.64813222354026, 0.6928859392149592 51.64964416743708, 0.6922543868017954 51.651549977718815, 0.693379267941065 51.662177887519455, 0.6930663922472212 51.669971728694684, 0.6781458581392128 51.671179977939495, 0.6775847249574778 51.67454109076102, 0.6758802637178843 51.6761529252925, 0.6649903092957641 51.6745991655686, 0.6630165128375133 51.67281105693502, 0.6588020257215852 51.67351093358129, 0.6517199642791437 51.67256847334137, 0.6462378293349208 51.675493649809226, 0.6425143684557407 51.67387772335204, 0.6369687901750863 51.6725625296737, 0.6362440968625562 51.67542526502205, 0.6333456261665834 51.675332019096544, 0.6290099914520543 51.676399583641995, 0.623930564906415 51.67661663551119, 0.6244641790697559 51.67501285094972, 0.621291720836913 51.67490924707409, 0.6211974897079914 51.67663361451194, 0.617987895880087 51.67724213864734, 0.613140741810143 51.68026402169925, 0.6091485076776589 51.681458107326016, 0.6091589862594022 51.68420629464087, 0.6111522806809114 51.684098130693265, 0.6123894012465171 51.68731547575259, 0.6105623214724792 51.68976097618745, 0.6106894730821186 51.692673845900494, 0.6122570043101704 51.69494042505868, 0.6111852518824746 51.69638343692585, 0.6125905358166462 51.69864462592181, 0.610362572112401 51.700570215131684, 0.6065336325637347 51.70083513170407, 0.6045641281440685 51.700387784126626, 0.6030499196403263 51.70275246898131, 0.6037865988983188 51.705069947491154, 0.6020119092748648 51.70885146735408, 0.604527463777506 51.70839100093021, 0.6100875322926458 51.708337713712176, 0.6140975846002479 51.70748767502475, 0.6221707680109639 51.7045107162299, 0.6229351465445164 51.702060900703245, 0.6222750876109662 51.700033213495175, 0.6253980979592119 51.69905239134456, 0.6258539276885214 51.696926921599214, 0.6329801986303927 51.69852289409183, 0.635610744210708 51.699731973591895, 0.639038842964109 51.6982789717496, 0.6411051864787574 51.69869478489814, 0.6427925067221286 51.70209236072276, 0.6497673895909853 51.70025698997269, 0.6564121985998088 51.69971565535599, 0.6584454987712719 51.700058167432715, 0.6594943662253397 51.69832384224061, 0.6569659199873946 51.697779404569815, 0.657925082804042 51.69604532370893, 0.6635392035028446 51.697383178870346, 0.6665823831476175 51.699246838793464, 0.6724097337829597 51.699698060839154, 0.6712999363786789 51.70257607621944, 0.6788808707781964 51.703570765546395, 0.6784573819076068 51.70478107005619, 0.6827561945257815 51.70534038336421, 0.6854948859889282 51.70622032252649, 0.686032533516235 51.709234376125536, 0.6886020388254537 51.709209759332346)))
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>