improved ingredient parser handling of amount unit without space
This commit is contained in:
parent
16d0fc38f9
commit
24f331c208
@ -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
|
||||
|
@ -54,7 +54,7 @@ def test_ingredient_parser():
|
||||
"3,5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"3.5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"400 g Karotte(n)": (400, "g", "Karotte(n)", ""),
|
||||
"400g unsalted butter": (400, "g", "butter", "unsalted"),
|
||||
"400g unsalted butter": (400, "g", "unsalted butter", ""),
|
||||
"2L Wasser": (2, "L", "Wasser", ""),
|
||||
"1 (16 ounce) package dry lentils, rinsed": (1, "package", "dry lentils, rinsed", "16 ounce"),
|
||||
"2-3 c Water": (2, "c", "Water", "2-3"),
|
||||
|
@ -438,7 +438,7 @@ def test(request):
|
||||
parser = IngredientParser(request, False)
|
||||
|
||||
data = {
|
||||
'original': '1 Porreestange(n) , ca. 200 g'
|
||||
'original': '90g golden syrup'
|
||||
}
|
||||
data['parsed'] = parser.parse(data['original'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user