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/lsoa/E01011049 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01011049 geosparql: asWKT MULTIPOLYGON (((-1.651988646095394 53.74624015900142, -1.6525524758432344 53.745736572326095, -1.6615662180421493 53.74429760793102, -1.6594690128668805 53.74382482095038, -1.6588147893016114 53.74325987021258, -1.662794617019038 53.742943513570594, -1.662531616063332 53.74170241940005, -1.661755136075139 53.74139366802552, -1.6618909239982878 53.74034823765371, -1.6612571220389716 53.739928170372515, -1.6630100264462995 53.7382289669361, -1.6605396931667329 53.737060330857815, -1.6591118415763748 53.73701471961036, -1.6587018023719144 53.734533488727436, -1.6596470693547307 53.734154764993924, -1.6596206292974012 53.73347826817602, -1.6607995525980648 53.73325151399359, -1.6622313282905943 53.73341749966992, -1.661329238420952 53.73440923938432, -1.6626894897640032 53.73472366042981, -1.6628973508112175 53.7354223976554, -1.6641691378866474 53.73597259736414, -1.6639678507013653 53.73459685189834, -1.6643499565506397 53.73420244570016, -1.6665182188430203 53.73471309113193, -1.6677671021174834 53.73400545802869, -1.6666065806050987 53.73339131314265, -1.666834468545799 53.732325146663065, -1.6682231655720519 53.732086566110674, -1.6759827684211586 53.73501970367293, -1.6793334895351664 53.73651290990306, -1.6800228967441435 53.73744708235906, -1.6766057688799485 53.73718419396187, -1.6756336590227194 53.737422703898204, -1.6724270544845703 53.73657320839786, -1.6719244312704835 53.7373372070083, -1.672361185747652 53.73850303888573, -1.6709734062330832 53.73838019681606, -1.6706984313730628 53.73884471082835, -1.6674728363312434 53.739586746970325, -1.6671179464203507 53.74063633541696, -1.670607122693204 53.74147556673627, -1.6709033990473174 53.74280032267243, -1.6734103463471612 53.742568983428015, -1.6766120237818951 53.74522381806179, -1.676815662498725 53.74575472531029, -1.6786217321096464 53.74671662182324, -1.676587274187061 53.749124374780614, -1.6760896622399886 53.748942283675014, -1.6739364763730549 53.750692452735755, -1.6755004880186228 53.751505970223285, -1.6757309924481225 53.75213034331571, -1.6744763611364513 53.752101881661225, -1.6678863509870743 53.74913142006017, -1.6633584081196824 53.74734925079843, -1.65852484614632 53.74672609592515, -1.6583680551068878 53.74548895446362, -1.651988646095394 53.74624015900142)))
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 lang='en'>
<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>