Food Ontology and Semantic Web
Table of Contents
1. Overview
Food ontologies provide formal, machine-readable representations of food-related knowledge, enabling semantic interoperability between nutrition databases, recipe systems, dietary applications, and scientific research platforms.
2. Background
The food domain presents unique ontological challenges due to its inherent complexity: foods exist as biological entities, cultural artifacts, commercial products, and nutritional compositions simultaneously. Early efforts to standardize food data focused on hierarchical classification systems like USDA food codes, but these lacked the expressivity needed for modern applications requiring inference, cross-database mapping, and multilingual support.
The semantic web movement provided the technological foundation for food ontologies through RDF (Resource Description Framework), OWL (Web Ontology Language), and SPARQL query capabilities. Projects like FoodOn emerged from the need to unify disparate food vocabularies across agriculture, nutrition science, food safety, and consumer applications.
3. Key Concepts
3.1. Core Food Ontologies
3.1.1. FoodOn
FoodOn's GitHub project began 2016-03 and its first ontology paper published 2018-12 (Dooley et al., NPJ Sci Food), both after this note's 2015-09-01 date; also, per EBI OLS4 (checked 2026-10-08), FOODON:00001002 is labeled "food product" (not "apple (whole, raw)") and FOODON:00001714 is labeled "food material component" (not "pome fruit") -- the example below uses real-looking IDs with invented labels.
The Food Ontology (FoodOn) provides a comprehensive vocabulary for food description:
@prefix foodon: <http://purl.obolibrary.org/obo/FOODON_> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
foodon:00001002 a owl:Class ;
rdfs:label "apple (whole, raw)" ;
rdfs:subClassOf foodon:00001714 ; # pome fruit
foodon:has_food_substance_analog foodon:03301710 .
3.1.2. Open Food Facts
Open Food Facts launched 2012-05-19, which predates this note's 2015-09-01 date; but Nutri-Score, listed below, was not introduced until 2017 in France -- it could not have been one of Open Food Facts's calculations as of 2015.
Community-driven product database with structured nutritional data:
- Barcode-indexed products
- Nutritional composition
- Ingredients parsing
- Nutri-Score calculations
3.1.3. USDA FoodData Central
USDA FoodData Central launched in 2019, per USDA's own FoodData Central about-us page, four years after this note's 2015-09-01 date; in 2015 the standard US reference was the USDA National Nutrient Database for Standard Reference, not FoodData Central.
Authoritative nutritional composition database:
- Foundation Foods
- SR Legacy
- Branded Foods
- Survey Foods (FNDDS)
3.2. Ontology Design Patterns
3.2.1. Food Product Hierarchy
@prefix : <http://example.org/food#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:Food a owl:Class .
:PlantFood a owl:Class ;
rdfs:subClassOf :Food .
:Fruit a owl:Class ;
rdfs:subClassOf :PlantFood .
:Apple a owl:Class ;
rdfs:subClassOf :Fruit ;
:hasNutrient :Fiber, :VitaminC ;
:typicalServingSize "182"^^xsd:decimal ;
:servingUnit "gram" .
3.2.2. Nutritional Composition
:NutrientContent a owl:Class .
:AppleNutrition a :NutrientContent ;
:food :Apple ;
:nutrient :Calories ;
:amount "95"^^xsd:decimal ;
:unit "kcal" ;
:per "182g serving" .
:Macronutrient a owl:Class .
:Micronutrient a owl:Class .
:Fiber a :Macronutrient ;
rdfs:label "Dietary Fiber" ;
:dailyValue "28"^^xsd:decimal ;
:unit "gram" .
3.2.3. Recipe Modeling
:Recipe a owl:Class .
:ApplePie a :Recipe ;
:hasIngredient [
:food :Apple ;
:quantity "6"^^xsd:integer ;
:preparation "sliced"
] ;
:hasIngredient [
:food :Sugar ;
:quantity "150"^^xsd:decimal ;
:unit "gram"
] ;
:cookingMethod :Baking ;
:cookingTime "PT45M"^^xsd:duration .
3.3. Linked Data Integration
Food ontologies connect to broader knowledge graphs:
- DBpedia: General encyclopedic knowledge
- Wikidata: Structured Wikipedia data
- schema.org: Web-scale structured data (Recipe, NutritionInformation)
- AGROVOC: FAO agricultural vocabulary
4. Implementation
4.1. SPARQL Queries
# Find foods high in vitamin C
PREFIX food: <http://example.org/food#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?food ?vitaminC
WHERE {
?food a food:Food ;
food:hasNutrientContent ?content .
?content food:nutrient food:VitaminC ;
food:amount ?vitaminC .
FILTER (?vitaminC > 50)
}
ORDER BY DESC(?vitaminC)
4.2. Schema.org Integration
{
"@context": "https://schema.org",
"@type": "Recipe",
"name": "Apple Pie",
"nutrition": {
"@type": "NutritionInformation",
"calories": "320 calories",
"carbohydrateContent": "45 g",
"fiberContent": "3 g"
},
"recipeIngredient": [
"6 medium apples",
"3/4 cup sugar"
]
}
4.3. Python Implementation with RDFLib
from rdflib import Graph, Namespace, Literal, URIRef
from rdflib.namespace import RDF, RDFS, XSD
FOOD = Namespace("http://example.org/food#")
g = Graph()
g.bind("food", FOOD)
# Add food item
apple = URIRef(FOOD.Apple)
g.add((apple, RDF.type, FOOD.Fruit))
g.add((apple, RDFS.label, Literal("Apple")))
g.add((apple, FOOD.calories, Literal(95, datatype=XSD.integer)))
# Query
for s, p, o in g.triples((None, FOOD.calories, None)):
print(f"{s} has {o} calories")
5. References
- FoodOn - Food Ontology
- Open Food Facts
- USDA FoodData Central
- OWL 2 Web Ontology Language
- Schema.org Recipe
- OBO Foundry - Biomedical ontology standards
6. Notes
- Food identity is context-dependent (biological vs. culinary vs. commercial)
- Multilingual support is essential for global food vocabularies
- Provenance and traceability require supply chain ontology integration
- Allergen and dietary restriction modeling needs careful attention
- Consider cultural and regional food naming variations
- Integration with agricultural ontologies enables farm-to-fork tracking