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/ua/E06000055 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://opendatacommunities.org/id/geography/administration/ua/E06000055 geosparql: asWKT MULTIPOLYGON (((-0.4653657285884102 52.32295328062055, -0.4441835679545031 52.314231640395136, -0.4360886866239525 52.31447086595143, -0.4357611897911068 52.29665683771358, -0.4226424380545013 52.28937565623125, -0.4217674706152316 52.28494748338339, -0.4101588853020365 52.28449680351288, -0.4069073439276001 52.28747581624833, -0.3989795599735732 52.27872889004148, -0.3926259321471079 52.28242965530801, -0.3750100426927999 52.280469342308, -0.3721750451926886 52.27349981030552, -0.3810134746627625 52.273134940791984, -0.381967562820838 52.268707236391876, -0.3743756664378689 52.2329982421561, -0.3590380916626655 52.234735255171174, -0.3410108466902276 52.2306474477653, -0.3434689015846655 52.24187443213018, -0.3344937181242748 52.242920568463404, -0.3199966394710606 52.24270786596499, -0.3136880795038388 52.23899884611832, -0.293209025606008 52.24051618858387, -0.2856938160927986 52.23740142569395, -0.2937585490217899 52.22843875730485, -0.299965119836661 52.21805781678603, -0.2943564416014389 52.20835350344175, -0.2742047232314345 52.208720348687336, -0.2619275410129417 52.209632553246294, -0.2649120218273907 52.20572111956165, -0.2407230042191149 52.19019317232911, -0.2440018630408295 52.18268459942398, -0.2497852366954016 52.184371060629886, -0.2891170959698945 52.19092580841636, -0.301678109521824 52.17822504146221, -0.3042745460037763 52.16690689083011, -0.3212645290799532 52.16883761123976, -0.3300652492430691 52.165341608372, -0.3350686455024026 52.15609706475228, -0.3491497678291227 52.145329906369405, -0.3577989953169988 52.146003673760084, -0.3620335829922188 52.1429200558311, -0.3448041875043257 52.11595581165108, -0.353015137762955 52.10636448848821, -0.3561088749030124 52.107728527713164, -0.3678128580422551 52.09928629717201, -0.3811875401302952 52.093565080768634, -0.3769084643326558 52.08773995367805, -0.3891489582539154 52.0808800869431, -0.3849023722670007 52.07557449034549, -0.3970169059327777 52.071003155400966, -0.4298627491303981 52.067773163576945, -0.4400332891104374 52.06328744867848, -0.4577528234349087 52.072835886098886, -0.4715269825503147 52.08800863590715, -0.4861227132009867 52.083880161587494, -0.5044742466636314 52.07072789019292, -0.4996030260551645 52.06744343503667, -0.5044889843923135 52.056781376366715, -0.5098143740437426 52.05502535335887, -0.5115176002610674 52.05955880972755, -0.5178957193038396 52.06033063103248, -0.5178163642393842 52.067890565190964, -0.5415856490320818 52.08188281488325, -0.5500855428837359 52.080704585639126, -0.5618034167866914 52.09232475229422, -0.5676220475470719 52.09497072114651, -0.5782973717811621 52.09411447728353, -0.5825263433498384 52.09835986223636, -0.5891859906154788 52.09749921764273, -0.5832326749532154 52.10454897318446, -0.5918103141427135 52.11069190717148, -0.6072494617654375 52.133868789994594, -0.6192842884672272 52.13306599236565, -0.6354516529371944 52.13925357719387, -0.640781600734089 52.152772307320404, -0.6306708392823759 52.154923937306734, -0.6349068456306719 52.168133013955426, -0.6282545173530263 52.17253631799084, -0.6274467038359484 52.18154541898431, -0.6395100658952912 52.18343490837354, -0.643160327146651 52.188844871524026, -0.6574481212399219 52.189775305725725, -0.668135726975178 52.195034104197056, -0.6614603980966016 52.20812617414236, -0.6373316775883229 52.22731761483517, -0.642748493714586 52.23344003369615, -0.6536555304790674 52.26828927595365, -0.6399083154759075 52.27244204508385, -0.6314125736708451 52.270047600731175, -0.6269781763465377 52.27487735350053, -0.6106170641428181 52.27949794088449, -0.6056970542665581 52.27886000600693, -0.5883487155435989 52.273817442610245, -0.5656931054666853 52.25346820599839, -0.554738110650652 52.25817983479237, -0.5409036902478843 52.25652620051503, -0.5393250192524092 52.266094904571624, -0.531190162743437 52.27040243245115, -0.5340031343160757 52.2811907951904, -0.542039351767858 52.28973200073589, -0.5140512228912262 52.31469705193968, -0.5198298799848902 52.31769257138901, -0.4871403355203625 52.32108266968805, -0.4762613503539042 52.3180638508874, -0.4653657285884102 52.32295328062055)))
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>