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/E01017542 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/lsoa/E01017542 geosparql: asWKT MULTIPOLYGON (((-0.2422419253637868 52.1870682931013, -0.2440578773111319 52.18292663280999, -0.2472699825498439 52.18322954478662, -0.2470445652291444 52.18375459442554, -0.2497850633765217 52.184371004108634, -0.2542081847890243 52.18581905354797, -0.2562498285865599 52.185818339475134, -0.2663235983974745 52.1869528584458, -0.2675686043148082 52.18730145090963, -0.2725090051108652 52.187527624176006, -0.275559711180615 52.18860053803247, -0.2811032042701915 52.18955040462266, -0.2816633689143841 52.18933534330879, -0.2864018753501662 52.19076524060347, -0.289116907953652 52.19092575174035, -0.2916577885034121 52.18636169417489, -0.2945399769342897 52.18254477692967, -0.2978649792110779 52.18109100943473, -0.3016783903423322 52.178224964580274, -0.3031771536318497 52.173718548407244, -0.3028220994589242 52.17172349067488, -0.3018290683633779 52.17100294554291, -0.3032859749846217 52.17076173998865, -0.3038529801701942 52.16908199759814, -0.3034155210576436 52.16819649828463, -0.3048157771197883 52.16644920959706, -0.3061342609149836 52.16635912560106, -0.3060261993877297 52.16555901066551, -0.3073974217207238 52.16546320510916, -0.3083077157213631 52.165809006351886, -0.3083654258607691 52.166493564953164, -0.310781886309472 52.16712795009394, -0.3138116458255886 52.16724408221757, -0.3153301409798362 52.16769019862326, -0.3169615436020528 52.16746987547571, -0.3214014803238622 52.168836215132174, -0.3230259949633026 52.16948016144985, -0.3236471316923716 52.17092399269873, -0.3262344819448832 52.17219327815074, -0.331852870695065 52.17408416423201, -0.3370549924759046 52.174669145690075, -0.3420720964635134 52.174985829467744, -0.3491171537714019 52.17481220516797, -0.349938287672007 52.17505058529138, -0.3506768309936704 52.175780101186355, -0.3531228005217351 52.176004494989435, -0.357283428512854 52.176990597438284, -0.3640895340083525 52.17665975931762, -0.3643647053696249 52.178128978236565, -0.3695451036851125 52.17751303854922, -0.3719235153152828 52.17683864774639, -0.374779471413299 52.17646511761096, -0.3821876227593967 52.17403219370364, -0.3857031656873415 52.173407681596025, -0.389481537226968 52.17167735828812, -0.3938951698372442 52.1713327378031, -0.3961076529653303 52.17142837704984, -0.3980965649305268 52.17100471694181, -0.4129160705233985 52.17292791397869, -0.4140660395229697 52.174967701361524, -0.418030104297188 52.177413149971684, -0.4187247774197602 52.17914827837515, -0.419484446759381 52.17957319411204, -0.4180907531338898 52.18074894488404, -0.4184494943408967 52.182090935854674, -0.4199283949773009 52.18385324746511, -0.4227033026784022 52.185707495094164, -0.4237115933074588 52.18753526526582, -0.4229058918358292 52.188859575528895, -0.4256697080872378 52.191009912498615, -0.4247129376535381 52.1914778757226, -0.4262580301058864 52.19408762300698, -0.4224802263840743 52.19404364107735, -0.4203442414458194 52.19347177784227, -0.4191144386175362 52.19412672356059, -0.4206187004773732 52.195391629720596, -0.4191101543056102 52.19895525617818, -0.4156392162336517 52.199516341069604, -0.4144030548939897 52.198813565523864, -0.4089671303622147 52.20266914756224, -0.4058605230579483 52.20409336158064, -0.4034094448680076 52.2013934110319, -0.3998235366868569 52.19994834135623, -0.4000269803624371 52.19961841346553, -0.3983276990384449 52.19872852203292, -0.3967667151388097 52.19730112800905, -0.3946669967915798 52.19624754506113, -0.3942494619444399 52.195246608578536, -0.3918582151682558 52.19330503160433, -0.3873558039869991 52.191466912599175, -0.3795656238732155 52.191331388359714, -0.3757023881404592 52.19027658228032, -0.3746987013510523 52.19329105961316, -0.3738455648104477 52.193530214204344, -0.3715356240252902 52.19328256945027, -0.3683135597958864 52.19353379854704, -0.3653308160635993 52.19320576458805, -0.362110425054551 52.19204349308965, -0.3601550295375607 52.19096070274798, -0.3594800562851868 52.19291594201459, -0.3573669302400625 52.19261594268609, -0.3558532392449088 52.19418720890152, -0.3550684052827039 52.19392099132352, -0.3535784095768376 52.195292919373294, -0.3514307200751451 52.19630876564949, -0.3511119644637815 52.19769433229835, -0.3570685826912186 52.198205382018465, -0.3572782615909331 52.19946359180644, -0.3610848911084474 52.20036440032657, -0.3603512058103643 52.20110317898393, -0.3613140943768449 52.20169286163646, -0.3610539785584755 52.202523775640486, -0.3580771233735173 52.20435710791528, -0.3570912398864064 52.20581701519572, -0.3565895039575378 52.205928762142186, -0.3548630452884084 52.20516109171391, -0.3529025126144704 52.203327413504816, -0.351948085406797 52.2030928130479, -0.3465561665295466 52.20350474345914, -0.3395699562581552 52.20358465705422, -0.3395094085736607 52.20392112395992, -0.332645766277394 52.2042306483602, -0.3282140109602623 52.20408970748694, -0.3241962312118455 52.20511800521123, -0.3206944012237585 52.20650237143323, -0.3175877961577332 52.20711547776983, -0.3127057394173738 52.209790535086476, -0.3075154928290252 52.209750432461774, -0.3060607249563201 52.20940011299212, -0.3063733193588325 52.20569009765381, -0.3072830367906768 52.204755413580244, -0.3093447478899587 52.20366128020936, -0.3110009374423813 52.20305185459071, -0.312769288188443 52.203590778911256, -0.3159788102724446 52.20292532212698, -0.316665151359739 52.20151309526191, -0.3183154322917786 52.20121293213999, -0.3181439039345184 52.200329306528495, -0.3175319811329675 52.19987101377347, -0.3181434412796839 52.1991783894123, -0.3182573087117571 52.19671662135506, -0.3166806223721275 52.19611586405672, -0.312193464164749 52.19543706437258, -0.3109284442691116 52.196891960331264, -0.3093817375037664 52.19719855852656, -0.3079840384820375 52.19678521484488, -0.3050474564325974 52.196668923211774, -0.3056612114317081 52.19765107481505, -0.3039292247143454 52.197786942411454, -0.3009131414015342 52.19871969897471, -0.3010218813500367 52.20078191174725, -0.3002908331299042 52.202133015788114, -0.2987576525371399 52.203531614810636, -0.2948753473724671 52.20557296813732, -0.2947422963571167 52.2050016693036, -0.2927262190339514 52.205673843097266, -0.2900905016514249 52.20723614708518, -0.2884312658978458 52.207377724888396, -0.2803113447614173 52.20843075378298, -0.2742050878879052 52.20872075863982, -0.2670424575807687 52.209454327977625, -0.2618592625923391 52.20986552420582, -0.2640728050820785 52.20636408359327, -0.2649119319673187 52.20572117218901, -0.2604462500279606 52.20542021980386, -0.2611840813746889 52.20415029956216, -0.2605674504705396 52.2036394355597, -0.256521945105842 52.2028334104515, -0.2555026201629362 52.201243693446514, -0.2547437103004826 52.201448686414146, -0.2545094332716344 52.19947944057709, -0.25195772543256 52.19652023687274, -0.2516167400884973 52.19556136612648, -0.2495248766183116 52.19472237087136, -0.2478558698123631 52.192852638869454, -0.2469001819208432 52.19256461046163, -0.2462209785689861 52.19186174949518, -0.2442853287530482 52.19149787564667, -0.2420604432522309 52.1903767584056, -0.2407228344363668 52.19019302593155, -0.2422419253637868 52.1870682931013)))
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>