How the ingredients.py recogniser pipeline works
masterThe ingredients.py recogniser maps free-text food ingredient strings to FoodOn ontology terms. It uses a three-stage pipeline where the first match wins:
- Assumption rules: If the normalized text is an exact key in the
assumptionsdictionary (e.g.,eggbecomeschicken egg), the value is substituted and the process moves to stage 2. - Global exact match: The (possibly substituted) text is looked up in a single alias + food-form index built from all types. This returns the matched entry's
typeandsubtypedirectly. - Component search: Only attempted if stages 1 and 2 fail. It uses a sequence of stripping techniques including:
- Plant prefix stripping (
wild,whole) - Parenthetical qualifier stripping (
base (qualifier)) - Global adjective stripping
- Characteristic stripping loop
- Trailing-form stripping (e.g.,
L. acidophilus bacterial culture) - Anatomy standalone match.
- Plant prefix stripping (