Merge branch 'mealie-next' into fix/translation-issues-when-scraping

This commit is contained in:
Michael Genson
2024-02-07 09:58:45 -06:00
committed by GitHub
47 changed files with 419 additions and 217 deletions

View File

@@ -12,7 +12,7 @@
"user-updated": "Gebruiker bijgewerkt",
"password-updated": "Wachtwoord bijgewerkt",
"invalid-current-password": "Ongeldig huidig wachtwoord",
"ldap-update-password-unavailable": "Kan het wachtwoord niet bijwerken. De gebruiker wordt beheerd door LDAP."
"ldap-update-password-unavailable": "Kan het wachtwoord niet bijwerken, de gebruiker wordt beheerd door LDAP"
},
"group": {
"report-deleted": "Rapport verwijderd."
@@ -20,7 +20,7 @@
"exceptions": {
"permission_denied": "Je hebt geen toestemming om deze actie uit te voeren",
"no-entry-found": "Het opgevraagde is niet gevonden",
"integrity-error": "Integriteitsprobleem voor database",
"integrity-error": "Database integriteitsfout",
"username-conflict-error": "Deze gebruikersnaam is al in gebruik",
"email-conflict-error": "Dit e-mailadres is al in gebruik"
},

View File

@@ -132,7 +132,7 @@ def parse_ingredient(tokens) -> tuple[str, str]:
return ingredient, note
def parse(ing_str) -> BruteParsedIngredient:
def parse(ing_str, parser) -> BruteParsedIngredient:
amount = 0.0
unit = ""
ingredient = ""
@@ -192,12 +192,20 @@ def parse(ing_str) -> BruteParsedIngredient:
# which means this is the ingredient
ingredient = tokens[1]
except ValueError:
try:
# can't parse first argument as amount
# -> no unit -> parse everything as ingredient
ingredient, note = parse_ingredient(tokens)
except ValueError:
ingredient = " ".join(tokens[1:])
# can't parse first argument as amount
# try to parse as unit and ingredient (e.g. "a tblsp salt"), with unit in first three tokens
# won't work for units that have spaces
for index, token in enumerate(tokens[:3]):
if parser.find_unit_match(token):
unit = token
ingredient, note = parse_ingredient(tokens[index + 1 :])
break
if not unit:
try:
# no unit -> parse everything as ingredient
ingredient, note = parse_ingredient(tokens)
except ValueError:
ingredient = " ".join(tokens[1:])
if unit_note not in note:
note += " " + unit_note

View File

@@ -126,22 +126,24 @@ class ABCIngredientParser(ABC):
return store_map[fuzz_result[0]]
def find_food_match(self, food: IngredientFood | CreateIngredientFood) -> IngredientFood | None:
def find_food_match(self, food: IngredientFood | CreateIngredientFood | str) -> IngredientFood | None:
if isinstance(food, IngredientFood):
return food
match_value = IngredientFoodModel.normalize(food.name)
food_name = food if isinstance(food, str) else food.name
match_value = IngredientFoodModel.normalize(food_name)
return self.find_match(
match_value,
store_map=self.foods_by_alias,
fuzzy_match_threshold=self.food_fuzzy_match_threshold,
)
def find_unit_match(self, unit: IngredientUnit | CreateIngredientUnit) -> IngredientUnit | None:
def find_unit_match(self, unit: IngredientUnit | CreateIngredientUnit | str) -> IngredientUnit | None:
if isinstance(unit, IngredientUnit):
return unit
match_value = IngredientUnitModel.normalize(unit.name)
unit_name = unit if isinstance(unit, str) else unit.name
match_value = IngredientUnitModel.normalize(unit_name)
return self.find_match(
match_value,
store_map=self.units_by_alias,
@@ -155,6 +157,16 @@ class ABCIngredientParser(ABC):
if ingredient.ingredient.unit and (unit_match := self.find_unit_match(ingredient.ingredient.unit)):
ingredient.ingredient.unit = unit_match
# Parser might have wrongly split a food into a unit and food.
if isinstance(ingredient.ingredient.food, CreateIngredientFood) and isinstance(
ingredient.ingredient.unit, CreateIngredientUnit
):
if food_match := self.find_food_match(
f"{ingredient.ingredient.unit.name} {ingredient.ingredient.food.name}"
):
ingredient.ingredient.food = food_match
ingredient.ingredient.unit = None
return ingredient
@@ -164,7 +176,7 @@ class BruteForceParser(ABCIngredientParser):
"""
def parse_one(self, ingredient: str) -> ParsedIngredient:
bfi = brute.parse(ingredient)
bfi = brute.parse(ingredient, self)
parsed_ingredient = ParsedIngredient(
input=ingredient,