예제 #1
0
def getIngs():
    i1 = Ingredient({"ref": "#Mehl"}, ["Mehl"], (3, 3))
    i2 = Ingredient({
        "ref": "#Zucker",
        "quantity": "1",
        "unit": "EL"
    }, ["Zucker"], (0, 0))
    i3 = Ingredient({"ref": "#Weißwein"}, ["weißer", "Wein"], (6, 7))
    return [i1, i2, i3]
예제 #2
0
 def testCompareRef3(self):
     i1 = Ingredient({
         "ref": "#Knollensellerie #Griesmehl",
         "quantity": "1"
     }, ['Sellerieknolle'], (0, 0))
     i2 = Ingredient({
         "ref": "#Knollensellerie",
         "quantity": "8"
     }, ['Sellerieknolle'], (0, 0))
     self.assertFalse(compare(i1, i2, attris=set(("ref", "quantity"))))
예제 #3
0
 def testCompare1(self):
     i1 = Ingredient({
         "ref": "#Knollensellerie",
         "quantity": "1"
     }, ['Sellerieknolle'], (0, 0))
     i2 = Ingredient({
         "ref": "#Knollensellerie",
         "quantity": "8"
     }, ['Sellerieknolle'], (0, 0))
     self.assertTrue(compare(i1, i2, attris=set(("ref", ))))
예제 #4
0
 def testIngInIngsRoughMatch6(self):
     ing = Ingredient({"ref": "#Knollensellerie #Sellerieblätter"},
                      ["Sellerie"], (17, 17))
     goldenStandardIngs = [
         Ingredient({"ref": "#Knollensellerie"}, ["Knollensellerie"],
                    (0, 0))
     ]
     self.assertTrue(
         ingInIngsRoughMatch(ing, goldenStandardIngs,
                             [ing] + goldenStandardIngs, set(("ref", ))))
예제 #5
0
    def get_recipe_ingredients(self) -> list[Ingredient]:

        all_ing = []

        ingredients = self._soup.select(".ingredients")

        for ingredient in ingredients:
            list_of_ing = []
            # collect all rows of Ingredients table
            table_rows = ingredient.select("tbody tr")
            for row in table_rows:
                table_data = row.select("td")
                # amount can be none
                amount = table_data[0].select_one("span")

                if amount:
                    amount = stripify(amount.text)
                else:
                    amount = "1 Stk"

                ing_name = stripify(table_data[1].select_one("span").text)
                quantiy, unit = parse_amount(amount, ing_name)

                list_of_ing.append(asdict(Ingredient(ing_name, quantiy, unit)))

            all_ing += list_of_ing

        return json.dumps(all_ing)
예제 #6
0
 def load_available_ingredients(self):
     """Carga los ingregientes al sistema, leyendo el archivo ingrediens.txt"""
     base_path = Path(__file__).parent
     file_path = (base_path / "../config/ingredients.txt").resolve()
     ingredients_list = self.__read_file_lines(file_path)
     for name, command, price in ingredients_list:
         self.__available_ingredients.append(
             Ingredient(name, command, price))
예제 #7
0
 def testIngInIngsRoughMatch1(self):
     ing = Ingredient({
         "ref": "#Zucker",
         "quantity": "1",
         "unit": "EL"
     }, ["Zucker"], (0, 0))
     self.assertTrue(
         ingInIngsRoughMatch(ing, getIngs(), getIngs(),
                             set(("ref", "quantity", "unit"))))
예제 #8
0
def getIngredients(ocr):
    # okt=konlpy.tag.Okt()
    kkma = Kkma()
    #ocr로 스캔한 문자열에서 명사를 추출한다.
    ocr_couldbe_ingredients=kkma.nouns(ocr)
    print(ocr_couldbe_ingredients)
    #전체 재료를 가져온다.
    all_ingredients = Ingredient.getIngredients()
    array_ingredients=[]
    for item in all_ingredients:
        array_ingredients.append(item['name'])
    
    
    #추출한 명사가 전체 재료에 있으면 재료리스트에 추가
    ingredients =[]
    for item in ocr_couldbe_ingredients:
        for ing in array_ingredients:
            exist = item.find(ing)
            if exist !=-1:
                if ing not in ingredients:
                    ingredients.append(ing)
    
    return ingredients
 def testParseIngsFromRecipeB16(self):
     ings = getIngsFromNode(parseString(getTaggedRecipeB16()))
     self.assertIn(Ingredient({"target":"#Bouillon"}, ["Bouillon"], (11,11)), ings)
     self.assertIn(Ingredient({"ref":"#Rindkochfleisch", "unit":"Pfund", "atLeast":"8", "atMost":"10"}, ["Rindfleisch"], (15,15)), ings)
예제 #10
0
 def testIngInIngsExactMatch4(self):
     ing = Ingredient({"ref": "#Mehl", "quantity": "2"}, ["Mehl"], (3, 3))
     self.assertFalse(
         ingInIngsExactMatch(ing, getIngs(), set(("ref", "quantity"))))
예제 #11
0
 def testIngInIngsExactMatch2(self):
     ing = Ingredient({"ref": "#Mehl"}, ["Mehl"], (4, 4))
     self.assertFalse(ingInIngsExactMatch(ing, getIngs(), set(("ref", ))))
예제 #12
0
 def testIngInIngsExactMatch1(self):
     ing = Ingredient({"ref": "#Mehl"}, ["Mehl"], (3, 3))
     self.assertTrue(ingInIngsExactMatch(ing, getIngs(), set(("ref", ))))
예제 #13
0
 def testIngInIngsRoughMatch5(self):
     ing = Ingredient({"ref": "#asf"}, ["Biokleidung"], (0, 0))
     self.assertFalse(
         ingInIngsRoughMatch(ing, getIngs(), getIngs(),
                             set(("ref", "quantity", "unit"))))
예제 #14
0
 def testIngInIngsRoughMatch4(self):
     ing = Ingredient({"ref": "#Kalsbrühe"}, ["Kalbsbrühe"], (0, 0))
     self.assertTrue(
         ingInIngsRoughMatch(ing, getIngs(), getIngs(),
                             set(("ref", "quantity", "unit"))))
예제 #15
0
 def testIngInIngsRoughMatch3(self):
     ing = Ingredient({"ref": "#Zucker"}, ["Zucker"], (0, 0))
     ingsExtracted = [ing]
     self.assertFalse(
         ingInIngsRoughMatch(ing, getIngs(), ingsExtracted,
                             set(("ref", "quantity", "unit"))))
def ingFromXmlIngElem(xmlIngElem, ingWords, positionInRecipe):
    return Ingredient(
        {
            attriName: getAttriOrNone(xmlIngElem, cueMLName)
            for attriName, cueMLName in Ingredient.allowedAttris.items()
        }, ingWords, positionInRecipe)