mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-04-05 12:35:35 -04:00
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:
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user