Dataset Foodista
Published 7th March 2011
Type SPARQL Endpoint
Users 39

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/foodista/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 looks up the identifier (URI) of an ingredient in the Foodista dataset. The names of the foods are associated with the RDF Schema label property. Simply alter the value of the property to look-up a different food name. Names will need to be exactly matched. For fuzzier lookups, use the search API.

Query: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX f: <http://linkedrecipes.org/schema/> SELECT ?uri WHERE { ?uri a f:Food; rdfs:label "Grated Carrot". }
Login to test this query using our experimental API explorer Permalink to this sample query

This is a basic query that allows a list of recipes to be extracted from the dataset. The query will return at most ten results. Add an OFFSET clause to page into the dataset. Additional recipe properties can be added to filter the list.

Query: 
PREFIX dct: <http://purl.org/dc/terms/> PREFIX f: <http://linkedrecipes.org/schema/> SELECT ?uri ?title WHERE { ?uri a f:Recipe; dct:title ?title. } LIMIT 10
Login to test this query using our experimental API explorer Permalink to this sample query

This query illustrates how to find recipes that use specific ingredients. The ingredient property relates recipes to their ingredients. This query references the ingredients (in this case Carrots and Cashews) by their unique identifiers, however labels could be used instead.

The query will return the identifier, title and recipe homepage on the Foodista site for each matched recipe. This could be used to build links to Foodista to allow a user to read the recipe in detail.

Query: 
PREFIX dct: <http://purl.org/dc/terms/> PREFIX f: <http://linkedrecipes.org/schema/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?uri ?title ?recipePage WHERE { ?uri a f:Recipe; dct:title ?title; foaf:isPrimaryTopicOf ?recipePage; f:ingredient <http://data.kasabi.com/dataset/foodista/food/4CXZ7VHS>; f:ingredient <http://data.kasabi.com/dataset/foodista/food/CX8CMQHZ>. } LIMIT 10
Login to test this query using our experimental API explorer Permalink to this sample query

This query finds the URIs and labels of all of the foods used as ingredients.

Rather than query for all things of a particular type it queries instead for all things that are used as an ingredient in a recipe.

 

Query: 
PREFIX f: <http://linkedrecipes.org/schema/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?ingredient ?label WHERE { ?recipe a f:Recipe; f:ingredient ?ingredient; OPTIONAL { ?ingredient rdfs:label ?label } }
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
SELECT ?tool { ?tool a <http://linkedrecipes.org/schema/Tool> }
Login to test this query using our experimental API explorer Permalink to this sample query

This query returns what are the most used techniques or preparation methods (according to the Foodista community).

If you want to learn how to cook, it's better you know this stuff!

Query: 
PREFIX lr: <http://linkedrecipes.org/schema/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/terms/> SELECT ?method (COUNT(?method) AS ?count) ?label ?description { ?recipe lr:uses ?method . ?method a lr:PreparationMethod . ?method rdfs:label ?label . ?method dct:description ?description . } GROUP BY ?method ?label ?description ORDER BY DESC(?count) LIMIT 20
Login to test this query using our experimental API explorer Permalink to this sample query

Stuff you could get away with it.

Query: 
PREFIX lr: <http://linkedrecipes.org/schema/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/terms/> SELECT ?method (COUNT(?method) AS ?count) ?label ?description { ?recipe lr:uses ?method . ?method a lr:PreparationMethod . ?method rdfs:label ?label . ?method dct:description ?description . } GROUP BY ?method ?label ?description ORDER BY ASC(?count) LIMIT 20
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?ingredient { ?i a <http://linkedrecipes.org/schema/Food> . ?i rdfs:label ?ingredient . }
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
PREFIX lr: <http://linkedrecipes.org/schema/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/terms/> SELECT ?ingredient (COUNT(?ingredient) AS ?count) ?label ?description { ?recipe a lr:Recipe . ?recipe lr:ingredient ?ingredient . ?ingredient a lr:Food . ?ingredient rdfs:label ?label . ?ingredient dct:description ?description . } GROUP BY ?ingredient ?label ?description ORDER BY DESC(?count) LIMIT 20
Login to test this query using our experimental API explorer Permalink to this sample query
Query: 
PREFIX lr: <http://linkedrecipes.org/schema/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX dct: <http://purl.org/dc/terms/> SELECT ?ingredient (COUNT(?ingredient) AS ?count) ?label ?description { ?recipe a lr:Recipe . ?recipe lr:ingredient ?ingredient . ?ingredient a lr:Food . ?ingredient rdfs:label ?label . ?ingredient dct:description ?description . } GROUP BY ?ingredient ?label ?description ORDER BY ASC(?count) LIMIT 20
Login to test this query using our experimental API explorer Permalink to this sample query
Create a sample query