s | p_blank | o_blank |
---|---|---|
/id/geography/administration/par/E04009865 | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | geosparql: Geometry |
/id/geography/administration/par/E04009865 | geosparql: asWKT | MULTIPOLYGON (((-0.5533043382256283 50.90145836179579, -0.5505959767724926 50.89886535492784, -0.5459671289125957 50.89936537832073, -0.5435815847699623 50.8976548502981, -0.5463228746182659 50.8957510076869, -0.5489638460342797 50.89295014799511, -0.5596602694545758 50.889744366319135, -0.561119949670007 50.88810044942961, -0.5598858831793901 50.88561035048234, -0.558149258483094 50.88388473651949, -0.5636639455234391 50.88161450291312, -0.5655377180408483 50.88031375570245, -0.5661915482089077 50.87874170088042, -0.5702096665518788 50.878615603143224, -0.570188165484672 50.8762996186361, -0.5716958007925993 50.874873767529984, -0.573602384103211 50.874530147727164, -0.5791042060176111 50.87542548705738, -0.5858241695263507 50.87717257403733, -0.5878563062743896 50.877142304129094, -0.5844415515033508 50.87903448423964, -0.5864449949049756 50.882303460231405, -0.5867607117715702 50.8838495971349, -0.5930633793981221 50.88793570013718, -0.5968267682397782 50.888124863418945, -0.595248221461869 50.890500742523265, -0.5987599642460402 50.89519683220054, -0.6029785962633009 50.89877264210569, -0.6084056548731546 50.90066751144604, -0.6069559249082664 50.90244973477769, -0.6048323211267591 50.90145943538825, -0.593697510333996 50.90280343609258, -0.5931895915035307 50.90172445066374, -0.5903913920584419 50.90184448851009, -0.5844155030920803 50.90076228412348, -0.5795734921716111 50.899253812228196, -0.5750758877937167 50.89984291637649, -0.569808184092311 50.89970927168733, -0.5597335742389358 50.90036514099171, -0.5588878910437809 50.90177741026232, -0.5547575742937623 50.902568116571544, -0.5533043382256283 50.90145836179579)), ((-0.54852316701002 50.89294646949762, -0.5465228176038965 50.89517524391436, -0.5434219299931614 50.896391134602254, -0.543988804460108 50.89481183084418, -0.5429648679166973 50.89121622743673, -0.5454260656987511 50.88948337731781, -0.5472133375263519 50.89002992339062, -0.5472554504407849 50.89219507282082, -0.54852316701002 50.89294646949762))) |
/id/geography/administration/par/E04009865 | geosparql: asWKT | POLYGON ((-0.548 50.899, -0.547 50.899, -0.544 50.898, -0.549 50.893, -0.559 50.89, -0.561 50.888, -0.56 50.886, -0.56 50.885, -0.558 50.884, -0.572 50.875, -0.588 50.877, -0.587 50.884, -0.607 50.902, -0.58 50.899, -0.554 50.902, -0.551 50.899, -0.548 50.899)) |
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
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
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.
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 |
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).
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
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.
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
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>