Exemplo n.º 1
0
 def __init__(self, to_parse: str, parser: Callable[[str], dict] = parse_ingredient):
     """
     :to_parse - ingredient name
     :parser - parser which handles user input (ingredient name)
     """
     self.amount, self.unit, self.measurement, self.name, self.raw_input = parser(
         to_parse
     ).values()
     self.matched_food = match_one_food(self.name)
     if not self.matched_food:
         raise IngredientError(to_parse, f"Couldn't match a food object.")
     if self.unit:
         self.weight = self.amount * unit_to_grams[self.unit]
     else:
         self.weight = self.get_weight()
Exemplo n.º 2
0
 def test_common_name_prevalence(self):
     Food.objects.create(name="Salt")
     food2 = Food.objects.create(name="Salt", common_name="Salt")
     assert match_one_food("Salt").id == food2.id
Exemplo n.º 3
0
 def test_match_one_food(self):
     food = Food.objects.create(name="Chicken")
     assert match_one_food("chicken").id == food.id
     assert match_one_food("") is None
Exemplo n.º 4
0
 def test_common_name_prevalence(self):
     food1 = models.Food.objects.create(name="Salt")
     food2 = models.Food.objects.create(name="Salt", common_name="Salt")
     assert search.match_one_food("Salt").id == food2.id
Exemplo n.º 5
0
 def test_match_one_food(self):
     food = models.Food.objects.create(name="Chicken")
     assert search.match_one_food("chicken").id == food.id
     assert search.match_one_food("") == None
Exemplo n.º 6
0
def getIngredientList(ingredient_name_list):
    ingredient_list_id = [
        match_one_food(singularize(i)) for i in ingredient_name_list
    ]
    ingredient_list_id = [i.id for i in ingredient_list_id if i]
    return ingredient_list_id