Published 27th July 2011
Type SPARQL Endpoint
Users 11

SPARQL Endpoint

Use the SPARQL 1.1 query language to perform structured queries against a dataset. Useful for performing precise queries against a dataset whose structure you understand.

Documentation

Endpoint URL

http://api.kasabi.com/dataset/global-hunger-index/apis/sparql
Login to test this query using our experimental API explorer

Authentication

You will need your API key (on your dashboard) in order to authenticate to this API. You have two options for authentication:

  • By URL Parameter -- add the apikey parameter to your request URL, with your key as the value
  • By Request Header -- add a custom HTTP header called X_KASABI_APIKEY to your HTTP request, with your key as the value

For more information on Kasabi authentication options read the authentication documentation. Your API key will need to be authorized to use this service.

Parameters

This API supports the following request parameters:

Parameter NameParameter Value(s)Required?Notes
queryURL encoded SPARQL queryYesThis is the query to execute against the dataset
outputShort name for desired response formatNoSupports selecting response format using url parameter rather than HTTP Accept header.

HTTP Response Codes

Clients should be prepared to receive any valid HTTP response code. The following table lists the most frequently used codes

CodeMeaning
200 OKSuccessful Request
400 Bad RequestMissing or malformed SPARQL query
401 Not AuthorizedAPI key is not authorized to access the data

Please also review our additional notes on response codes.

Response Formats

Query Type Response Format Accept Header output parameter Notes
SELECT or ASK application/sparql-results+json application/sparql-results+json json Return results in SPARQL JSON results format
SELECT or ASK application/sparql-results+xml application/sparql-results+json xml Return results in SPARQL XML results format
CONSTRUCT or DESCRIBE application/rdf application/rdf rdf (or xml) Return results as RDF/XML
CONSTRUCT or DESCRIBE application/rdf application/rdf rdf (or xml) Return results as RDF/XML
CONSTRUCT or DESCRIBE application/json application/json json Return results as RDF/JSON
CONSTRUCT or DESCRIBE text/turtle text/turtle turtle Return results as Turtle
CONSTRUCT or DESCRIBE text/plain text/plain ntriples Return results as NTriples

Sample Queries

This query will fetch a hunger index value, and attempt to locate any supporting data for the relevant year and country also.

Modifications:

Replace ?dataset wherever it appears with e.g. <http://data.kasabi.com/dataset/global-hunger-index/2011/data> to get just data from the 2011 GHI publication.

Query: 
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX qb: <http://purl.org/linked-data/cube#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX ghiqb: <http://data.kasabi.com/dataset/global-hunger-index/structure/> SELECT ?area ?period ?ghi ?cuwValue ?cmValue ?punValue ?dataset WHERE { ?observation ghiqb:yearOfGHI ?year. ?observation ghiqb:refArea ?area. ?observation qb:measureType ghiqb:GHI. OPTIONAL {?observation ghiqb:GHI ?ghi.} ?observation ghiqb:refPeriod ?period. # Replace ?dataset where it appears with a dataset URI to restrict values to a particular year. ?observation qb:dataSet ?dataset. # Replace ?ontologiesArea with <http://ontologi.es/place/2-DIGIT-ISO-CODE> to get values for a particular country. ?area owl:sameAs ?ontologiesArea . # Replace ?year wherever it appears with e.g. "2010"^^xsd:init to get just the values for 2010. ?cuwObs a qb:Observation. ?cuwObs qb:dataSet ?dataset. ?cuwObs qb:measureType ghiqb:supportingDataPUW. ?cuwObs ghiqb:refArea ?area. ?cuwObs ghiqb:yearOfGHI ?year. OPTIONAL { ?cuwObs ghiqb:supportingDataPUW ?cuwValue. } ?cmObs a qb:Observation. ?cmObs qb:dataSet ?dataset. ?cmObs qb:measureType ghiqb:supportingDataU5MR. ?cmObs ghiqb:refArea ?area. ?cmObs ghiqb:yearOfGHI ?year. OPTIONAL { ?cmObs ghiqb:supportingDataU5MR ?cmValue. } ?punObs a qb:Observation. ?punObs qb:dataSet ?dataset. ?punObs qb:measureType ghiqb:supportingDataPUN. ?punObs ghiqb:refArea ?area. ?punObs ghiqb:yearOfGHI ?year. OPTIONAL { ?punObs ghiqb:supportingDataPUN ?punValue.} } LIMIT 5
Login to test this query using our experimental API explorer Permalink to this sample query

This query will fetch any available Global Hunger Index values with their country and year from the 2011 GHI publication.

Results:

?area is a geonames area. Lookup this URI for latitude and longitude data.

?ontologiesArea is the same area using the ontologi.es service which includes an ISO code in the URL. Look up this URL for data on regions in this country.

Query: 
PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX qb: <http://purl.org/linked-data/cube#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX ghiqb: <http://data.kasabi.com/dataset/global-hunger-index/structure/> SELECT ?area ?ghi ?referenceYear ?ontologiesArea ?lastRevised WHERE { ?observation qb:dataSet <http://data.kasabi.com/dataset/global-hunger-index/2011/data>. ?observation ghiqb:lastRevised ?lastRevised. ?observation ghiqb:refArea ?area. ?observation qb:measureType ghiqb:GHI. OPTIONAL {?observation ghiqb:GHI ?ghi.} ?observation ghiqb:refPeriod ?referenceYear. ?area owl:sameAs ?ontologiesArea. }
Login to test this query using our experimental API explorer Permalink to this sample query

Using data added to the store from GeoNames this query will fetch back Global Hunger Index values and will include latitude and longitude, and population figures. 

Query: 
PREFIX wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> PREFIX dc: <http://purl.org/dc/terms/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX qb: <http://purl.org/linked-data/cube#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> PREFIX ghiqb: <http://data.kasabi.com/dataset/global-hunger-index/structure/> PREFIX gn: <http://www.geonames.org/ontology#> SELECT * WHERE { # Change this value to fetch details from a different GHI publication ?observation qb:dataSet <http://data.kasabi.com/dataset/global-hunger-index/dataset/2011>. ?observation ghiqb:lastRevised ?lastRevised. ?observation ghiqb:refArea ?area. ?observation qb:measureType ghiqb:GHI. OPTIONAL {?observation ghiqb:GHI ?ghi.} ?observation ghiqb:refPeriod ?referenceYear. ?area owl:sameAs ?ontologiesArea. OPTIONAL { ?area wgs84_pos:lat ?lat. ?area wgs84_pos:long ?long.} OPTIONAL { ?area gn:population ?population. } }
Login to test this query using our experimental API explorer Permalink to this sample query

This store contains Global Hunger Index values from multiple GHI publications.

These should be treated as distinct datasets, and values from different years of GHI publication are not directly comparable. 

The query below will identify all available datasets and their URIs to use in queries. 

Query: 
PREFIX qb: <http://purl.org/linked-data/cube#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/terms/> SELECT * WHERE { ?dataset a qb:DataSet. ?dataset rdfs:label ?label. OPTIONAL { ?dataset dct:description ?description. } OPTIONAL { ?dataset rdfs:comment ?comment1. } OPTIONAL { ?dataset rdfs:comment ?comment2. FILTER(?comment1 != ?comment2) } }
Login to test this query using our experimental API explorer Permalink to this sample query
Create a sample query