beweinreich commited on
Commit
9a6b725
1 Parent(s): d3d3a5b

fix multi item food detector

Browse files
Files changed (2) hide show
  1. algo.py +4 -1
  2. multi_food_item_detector.py +6 -0
algo.py CHANGED
@@ -308,6 +308,9 @@ class Algo:
308
  weight = float(weight)
309
  except ValueError:
310
  weight = 0
 
 
 
311
 
312
  mapping.update({
313
  'date': date,
@@ -357,7 +360,7 @@ class Algo:
357
 
358
  print()
359
  print(f"Processing: {input_word}")
360
-
361
  if has_delimiters(input_word):
362
  mapping = self.handle_multi_item(input_word)
363
  else:
 
308
  weight = float(weight)
309
  except ValueError:
310
  weight = 0
311
+ except Exception as e:
312
+ print(f" - Error converting weight to float: {e}")
313
+ weight = 0
314
 
315
  mapping.update({
316
  'date': date,
 
360
 
361
  print()
362
  print(f"Processing: {input_word}")
363
+
364
  if has_delimiters(input_word):
365
  mapping = self.handle_multi_item(input_word)
366
  else:
multi_food_item_detector.py CHANGED
@@ -62,6 +62,8 @@ def analyze_text(text):
62
  def determine_delimiter(text):
63
  number_of_slashes = text.count('/')
64
  number_of_commas = text.count(',')
 
 
65
  number_of_spaces = text.count(' ')
66
 
67
  if number_of_slashes > 0 and number_of_slashes >= number_of_commas:
@@ -69,6 +71,10 @@ def determine_delimiter(text):
69
  return '/'
70
  elif number_of_commas > 0:
71
  return ','
 
 
 
 
72
  else:
73
  return ' '
74
 
 
62
  def determine_delimiter(text):
63
  number_of_slashes = text.count('/')
64
  number_of_commas = text.count(',')
65
+ number_of_ampersands = text.count(' & ')
66
+ number_of_ands = text.count(' and ')
67
  number_of_spaces = text.count(' ')
68
 
69
  if number_of_slashes > 0 and number_of_slashes >= number_of_commas:
 
71
  return '/'
72
  elif number_of_commas > 0:
73
  return ','
74
+ elif number_of_ampersands > 0:
75
+ return '&'
76
+ elif number_of_ands > 0:
77
+ return 'and'
78
  else:
79
  return ' '
80