SPARQL API

Statistical LOD of Japan can be retrieved by using SPARQL. Retrieval results are obtained by sending queries via API. We support SPARQL 1.1 query syntax.

To submit a SPARQL query from your code, you issue an HTTP POST to our endpoint:http://data.e-stat.go.jp/lod/sparql/alldata/query, with the query itself as a URL-encoded parameter called “query” as follows.
http://data.e-stat.go.jp/lod/sparql/alldata/query?query=[URL-encoded query]

For example, to run the following SPARQL query and get the results: #obtain the CPI(Consumer Price Index) of July 2015

select  ?cpi  
where {
     ?s <http://data.e-stat.go.jp/lod/ontology/measure/index> ?cpi ; 
        <http://data.e-stat.go.jp/lod/ontology/crossDomain/dimension/timePeriod> "2015-06"^^<http://www.w3.org/2001/XMLSchema#gYearMonth> . 
}

Example1) Using curl

curl -X POST -H "Accept: application/sparql-results+json" http://data.e-stat.go.jp/lod/sparql/alldata/query?query=select+%3Fcpi++%0Awhere+%7B+%3Fs+%3Chttp%3A%2F%2Fdata.e-stat.go.jp%2Flod%2Fontology%2Fmeasure%2Findex%3E+%3Fcpi+%3B+%0A%3Chttp%3A%2F%2Fdata.e-stat.go.jp%2Flod%2Fontology%2FcrossDomain%2Fdimension%2FtimePeriod%3E+%222015-06%22%5E%5E%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23gYearMonth%3E.%0A%7D

The result format is addressed using HTTP Accept header. Available result formats are as follows.

query type formats HTTP Accept header
SELECT
ASK
JSON* application/sparql-results+json
XML application/sparql-results+xml
TEXT text/plain
CSV text/csv
TSV text/tab-separated-values
CONSTRUCT
DESCRIBE
RDF/XML* application/rdf+xml
N-triples application/n-triples
text/plain
Turtle text/turtle

* is a default value

Example2) 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 ?cpi where { ?s <http://data.e-stat.go.jp/lod/ontology/measure/index> ?cpi ; <http://data.e-stat.go.jp/lod/ontology/crossDomain/dimension/timePeriod> "2015-06"^^<http://www.w3.org/2001/XMLSchema#gYearMonth>.}';
      var url = 'http://data.e-stat.go.jp/lod/sparql/alldata/query';
      $.ajax({
            method: 'POST',
            dataType: 'json',
            url: url,
            data: {query: query},
            success: function(data) {
                alert('cpi: ' + data.results.bindings[0].cpi.value);
            }
      });
</script>
</body>
</html>

 

References:
  ・SPARQL 1.1 Protocol(http://www.w3.org/TR/sparql11-protocol/
  ・SPARQL 1.1 Query Results JSON Format(https://www.w3.org/TR/sparql11-results-json/
  ・SPARQL Query Results XML Format (Second Edition)(https://www.w3.org/TR/rdf-sparql-XMLres/
  ・SPARQL 1.1 Query Results CSV and TSV Formats(https://www.w3.org/TR/sparql11-results-csv-tsv/
  ・Open access to Scotland's official statistics(http://statistics.gov.scot/sparql