feat: Pass user defined units as custom units to parse_ingredient function. (#7334)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
Tom Strange
2026-03-27 16:48:03 +00:00
committed by GitHub
parent fc8b1f3719
commit 453d40dab1

View File

@@ -252,7 +252,17 @@ class NLPParser(ABCIngredientParser):
return self.find_ingredient_match(parsed_ingredient)
async def parse_one(self, ingredient_string: str) -> ParsedIngredient:
parsed_ingredient = parse_ingredient(ingredient_string)
database_units = {}
for ingredient_unit in self.data_matcher.units_by_id.values():
if ingredient_unit.name:
plural_name = ingredient_unit.plural_name or ingredient_unit.name
database_units[plural_name] = ingredient_unit.name
if ingredient_unit.abbreviation:
plural_abbr = ingredient_unit.plural_abbreviation or ingredient_unit.abbreviation
database_units[plural_abbr] = ingredient_unit.abbreviation
parsed_ingredient = parse_ingredient(ingredient_string, custom_units=database_units)
return self._convert_ingredient(parsed_ingredient)
async def parse(self, ingredients: list[str]) -> list[ParsedIngredient]: