Semantic Food Recipe Finder is a full-stack semantic web project that builds a recipe ontology, generates an RDF knowledge graph from structured datasets, and exposes a queryable API with a lightweight front-end. Users can explore the knowledge graph with semantic filters such as “vegan lentil recipes under 45 minutes.”
- Ontology-driven graph – Scripts for transforming the Kaggle “Better
Recipes for a Better Life” dataset into a Turtle knowledge graph using
rdflibwith inferred diet categories. - Semantic search API – A Flask backend that performs SPARQL queries over the graph, supporting ingredient keyword searches, cuisine filtering, diet constraints, and total-time limits.
- Interactive front-end – A responsive interface that consumes the API, visualises recipe metadata, and displays full directions straight from the graph.
- Extensible ontology – Classes for recipes, ingredients, cuisines, and dietary types that can be customised for coursework or further research.
.
├── app/ # Flask application and graph helpers
├── data/ # Sample data and RDF graph
├── frontend/ # Static front-end assets
├── scripts/ # Utilities for building the graph
├── requirements.txt # Python dependencies
└── README.md
scripts/build_graph.py– Convert the Kaggle dataset (CSV or JSON) into an RDF Turtle file with inferred dietary categories.data/recipes_sample.ttl– A small demonstration graph generated from the sample JSON dataset.app/main.py– Flask entry-point that exposes the API and serves the static site.app/graph_loader.py– High-level search helpers that wrap SPARQL queries and assemble JSON-friendly objects.frontend/index.html,styles.css,app.js– Search UI that calls the API and renders recipe details.
The easiest way to get started:
# 1. Install dependencies
pip install -r requirements.txt
# 2. Run the automatic startup script
./start.sh # On Mac/Linux
# OR
start.bat # On Windows# 1. Install dependencies
pip install -r requirements.txt
# 2. Run the application (automatically finds free port)
python run.pyThe application will automatically:
- Find a free port (8000, 8001, 8002, etc.)
- Load your recipe database
- Show the URL to open in your browser
- Display recipes immediately when you open the page
Create a virtual environment and install requirements (Python 3.10+ recommended):
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txtThe project includes sample data that works out of the box:
python run.pyThis will:
- Automatically build the sample knowledge graph if needed
- Start the Flask server on http://localhost:5000
- Show you helpful startup information
If you want to use your own recipe data:
-
Download the Kaggle dataset:
- Visit: https://www.kaggle.com/datasets/thedevastator/better-recipes-for-a-better-life
- Download the CSV file and save it as
data/recipes.csv
-
Build your knowledge graph:
python scripts/build_graph.py data/recipes.csv data/recipes.ttl
-
Set the environment variable:
export RECIPE_GRAPH_PATH=$(pwd)/data/recipes.ttl
-
Run the application:
python run.py
If you prefer to use Flask directly:
export FLASK_APP=app.main:create_app
flask runGET /api/search– Query recipes with optionalingredient,cuisine,diet, andmaxTimeparametersGET /api/recipes?uri=<URI>– Retrieve full details for a recipe resourceGET /api/cuisinesandGET /api/diets– Retrieve available filter valuesGET /api/health– Health check endpoint
Visit http://localhost:5000 to load the front-end UI.
The single-page interface provides:
- A search form with ingredient keyword, cuisine dropdown, diet dropdown, and total time filter.
- Live query results that display ratings, cuisine, diets, and cook time badges.
- A details panel that renders the recipe’s ingredients and directions fetched directly from the knowledge graph.
The default ontology defines the following key classes and properties:
rec:Recipe,rec:Ingredient,rec:Cuisine,rec:DietType- Properties:
rec:hasIngredient,rec:hasCuisine,rec:hasDiet,rec:hasTotalTime,rec:hasRating, and more - Ingredient subclasses for
rec:AnimalProductandrec:GlutenIngredient
To extend the ontology, edit scripts/build_graph.py to add new classes or
properties, then regenerate the TTL file. The Flask API automatically reflects
additional data properties because SPARQL queries use labels and groups.