improved ingredient parser handling of amount unit without space

This commit is contained in:
vabene1111
2022-11-09 14:24:12 +01:00
parent 16d0fc38f9
commit 24f331c208
3 changed files with 6 additions and 2 deletions

View File

@@ -235,6 +235,10 @@ class IngredientParser:
# leading spaces before commas result in extra tokens, clean them out
ingredient = ingredient.replace(' ,', ',')
# if amount and unit are connected add space in between
if re.match('([0-9])+([A-z])+\s', ingredient):
ingredient = re.sub(r'(?<=([a-z])|\d)(?=(?(1)\d|[a-z]))', ' ', ingredient)
tokens = ingredient.split() # split at each space into tokens
if len(tokens) == 1:
# there only is one argument, that must be the food