Eval: Oxigraph + FoodOn ontology for ingredient relationships, substitution, allergen graph #155

Open
opened 2026-07-05 08:50:54 -07:00 by pyr0ball · 0 comments
Owner

Source

https://github.com/oxigraph/oxigraph — Apache 2.0 / MIT dual license
pyoxigraph on PyPI: https://pypi.org/project/pyoxigraph/

What it is

Rust-core embedded RDF graph database with a SPARQL 1.1 query engine. The pyoxigraph
Python binding provides a simple Store() object (in-memory or RocksDB-backed) with
standard store.query('SELECT ...') API. Loads Turtle, JSON-LD, N-Triples, N-Quads,
RDF/XML.

from pyoxigraph import Store
store = Store()
store.load(open("foodon.ttl"), mime_type="text/turtle")
for row in store.query("SELECT ?sub WHERE { ?food food:substitutedBy ?sub . }"):
    print(row["sub"].value)

Kiwi use cases

Ingredient substitution

FoodOn (https://foodon.org/) is an OWL ontology of 12,000+ food entities with
substitution, category, and preparation relationships. Load once at startup into an
in-memory Oxigraph store. Query: "what can substitute for buttermilk?" → SPARQL
traversal returns milk + acid, yogurt, kefir.

Allergen and dietary classification

Query the ontology for allergen parent classes. "Does this ingredient contain gluten?"
becomes a graph reachability question rather than a hardcoded lookup table. Covers
common eight allergens plus CF's extended dietary profiles (vegan, kosher, halal, etc.).

Nutritional family / ingredient relationships

USDA FoodData Central publishes structured data. Combined with FoodOn's taxonomy,
can answer "find ingredients in the same nutritional family as lentils with lower
sodium" — useful for the dietary profile filter in Phase 2 recipe matching.

Pantry category inference

Rather than manually tagging pantry items, infer categories from the ontology.
"black beans" → legume → protein source → vegan-compatible → gluten-free.

Implementation sketch

  • Load FoodOn TTL at cf-core startup (or lazy-load per product)
  • Expose circuitforge_core.food_graph.query(sparql) as thin wrapper
  • Kiwi's recipe engine queries the graph for substitutions and dietary checks
  • In-memory store fits: FoodOn TTL is ~15MB, loads in ~200ms

License

Apache 2.0 / MIT — clean for all CF tiers including commercial/cloud.
pyoxigraph is a pure Python wheel with the Rust core compiled in — no separate
native install required.

  • cf-core#65 (backon retry utility — also a cf-core addition, good batch)
  • kiwi Phase 2 recipe engine work
  • roadmap#53: Oxigraph for Harrier/Robin knowledge graphs (broader tracking)
## Source https://github.com/oxigraph/oxigraph — Apache 2.0 / MIT dual license pyoxigraph on PyPI: https://pypi.org/project/pyoxigraph/ ## What it is Rust-core embedded RDF graph database with a SPARQL 1.1 query engine. The `pyoxigraph` Python binding provides a simple `Store()` object (in-memory or RocksDB-backed) with standard `store.query('SELECT ...')` API. Loads Turtle, JSON-LD, N-Triples, N-Quads, RDF/XML. ```python from pyoxigraph import Store store = Store() store.load(open("foodon.ttl"), mime_type="text/turtle") for row in store.query("SELECT ?sub WHERE { ?food food:substitutedBy ?sub . }"): print(row["sub"].value) ``` ## Kiwi use cases ### Ingredient substitution FoodOn (https://foodon.org/) is an OWL ontology of 12,000+ food entities with substitution, category, and preparation relationships. Load once at startup into an in-memory Oxigraph store. Query: "what can substitute for buttermilk?" → SPARQL traversal returns milk + acid, yogurt, kefir. ### Allergen and dietary classification Query the ontology for allergen parent classes. "Does this ingredient contain gluten?" becomes a graph reachability question rather than a hardcoded lookup table. Covers common eight allergens plus CF's extended dietary profiles (vegan, kosher, halal, etc.). ### Nutritional family / ingredient relationships USDA FoodData Central publishes structured data. Combined with FoodOn's taxonomy, can answer "find ingredients in the same nutritional family as lentils with lower sodium" — useful for the dietary profile filter in Phase 2 recipe matching. ### Pantry category inference Rather than manually tagging pantry items, infer categories from the ontology. "black beans" → legume → protein source → vegan-compatible → gluten-free. ## Implementation sketch - Load FoodOn TTL at cf-core startup (or lazy-load per product) - Expose `circuitforge_core.food_graph.query(sparql)` as thin wrapper - Kiwi's recipe engine queries the graph for substitutions and dietary checks - In-memory store fits: FoodOn TTL is ~15MB, loads in ~200ms ## License Apache 2.0 / MIT — clean for all CF tiers including commercial/cloud. pyoxigraph is a pure Python wheel with the Rust core compiled in — no separate native install required. ## Related - cf-core#65 (backon retry utility — also a cf-core addition, good batch) - kiwi Phase 2 recipe engine work - roadmap#53: Oxigraph for Harrier/Robin knowledge graphs (broader tracking)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/kiwi#155
No description provided.