コード例 #1
0
def readIngredientFromLine(line):
    tokens = tokenizeLine(line)
    output = objects.Ingredient()
    output.category = tokens[1]
    output.descriptor = tokens[2].lower()
    output.name = tokens[3]
    output.protein = tokens[11]
    output.fat = tokens[12]
    output.carbs = tokens[13]
    return output
コード例 #2
0
def changeToIndian(recipe):
    cuisine = "indian"
    ingredients = recipe.ingredients
    cuisineMeats = cuisines[cuisine]["meats"]
    cuisineCheese = cuisines[cuisine]['cheese']
    cuisineSpiceHerb = cuisines[cuisine]['spicesAndHerbs']
    cuisineSauces = cuisines[cuisine]['sauces']
    cuisineVegGarn = cuisines[cuisine]['veggiesAndGarnish']

    modifiedIngredients = []
    addSpices = False
    vegIndex = 0
    for ing in ingredients:
        category = ing.category
        #check the meats used in recipe
        if category in meatsCategories or ing.name in meats:

            if fitsCuisineForCategory(ing, cuisineMeats):
                (meat, meatInDescriptor) = findIngNames(ing, cuisineMeats)
                if meat in (poultryAndGame + seafood) or meatInDescriptor in (
                        poultryAndGame + seafood):
                    # chicken
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineMeats[0], "boneless", ""))
                else:
                    # lamb/mutton
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineMeats[1], "", ""))

        #replace cheese with indian cheese
        elif category in cheeseCategory:
            pat = re.search("cheese*", ing.name.lower())
            pat2 = re.search("cheese*", ing.descriptor.lower())
            if pat or pat2:
                if fitsCuisineForCategory(ing, cuisineCheese):
                    (cheese,
                     cheeseInDescriptor) = findIngNames(ing, cuisineCheese)
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineCheese[0], "", ""))

        #replace spices and herbs
        elif category in spiceHerbsCategory:
            if fitsCuisineForCategory(ing, cuisineSpiceHerb):
                if not addSpices:
                    addSpices = True
                    modifiedIngredients.append({
                        ing.name + "$" + ing.descriptor:
                        ', '.join(cuisineSpiceHerb[0:3])
                    })
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))
                else:
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))

        #replace sauces....
        elif category in sauce or ing.name in stocks:
            if fitsCuisineForCategory(ing, cuisineSauces):
                modifiedIngredients.append(
                    updateIngredient(ing, cuisineSauces[0],
                                     "tomato puree based", ""))

        elif category in veggiesGarnish:
            veggieGarName = ing.name
            veggieDescriptor = ing.descriptor
            isVeggie = findVeggies(veggieGarName, veggieDescriptor, cuisine)
            if not isVeggie:
                if vegIndex < len(cuisineVegGarn):
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineVegGarn[vegIndex], "",
                                         ""))
                    vegIndex += 1
                else:
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))
    if addSpices:
        for spiceHerb in cuisineSpiceHerb[0:3]:
            newIng = parsing.findIngredient(spiceHerb)
            if not newIng.name:
                newIng = objects.Ingredient(name=spiceHerb)
            ingredients.append(newIng)

    recipe.ingredients = sanitizeIngredients(ingredients)
    recipe.steps = replaceDirections(modifiedIngredients, recipe.steps)
    recipe.name = "Indian Version of -" + recipe.name
    print recipe.unicode()
コード例 #3
0
def changeToChinese(recipe):
    cuisine = "chinese"
    ingredients = recipe.ingredients
    cuisineMeats = cuisines[cuisine]["meats"]
    cuisineSpiceHerb = cuisines[cuisine]['spicesAndHerbs']
    cuisineSauces = cuisines[cuisine]['sauces']
    cuisineVegGarn = cuisines[cuisine]['veggiesAndGarnish']
    cuisineAlcohol = cuisines[cuisine]['alcohol']

    modifiedIngredients = []
    addSpices = False
    vegIndex = 0
    for ing in ingredients:
        category = ing.category
        if category in meatsCategories or ing.name in meats:
            if fitsCuisineForCategory(ing, cuisineMeats):
                (meat, meatInDescriptor) = findIngNames(ing, cuisineMeats)
                if meat in (poultryAndGame + seafood) or meatInDescriptor in (
                        poultryAndGame + seafood):
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineMeats[0], "boneless", ""))
                else:
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineMeats[1], "tenderloin",
                                         "cubed"))

        elif category in spiceHerbsCategory:
            if fitsCuisineForCategory(ing, cuisineSpiceHerb):
                if not addSpices:
                    addSpices = True
                    modifiedIngredients.append({
                        ing.name + "$" + ing.descriptor:
                        ', '.join(cuisineSpiceHerb)
                    })
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))

                    # Add in garlic, chili pepper, basil combo at end
                else:
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))

        elif category in sauce:
            if fitsCuisineForCategory(ing, cuisineSauces):
                modifiedIngredients.append(
                    updateIngredient(ing, cuisineSauces[0], "", ""))

        elif category in veggiesGarnish:
            veggieGarName = ing.name
            veggieDescriptor = ing.descriptor
            isVeggie = findVeggies(veggieGarName, veggieDescriptor, cuisine)
            if not isVeggie:
                if vegIndex < len(cuisineVegGarn):
                    modifiedIngredients.append(
                        updateIngredient(ing, cuisineVegGarn[vegIndex], "",
                                         ""))
                    vegIndex += 1
                else:
                    modifiedIngredients.append(
                        updateIngredient(ing, "", "", ""))

        elif ing.name == "wine":
            newIng = parsing.findIngredient(cuisineAlcohol[0])
            modifiedIngredients.append(
                updateIngredient(ing, newIng.name, newIng.descriptor, ""))

    if addSpices:
        for spiceHerb in cuisineSpiceHerb:
            newIng = parsing.findIngredient(spiceHerb)
            if not newIng.name:
                newIng = objects.Ingredient(name=spiceHerb)
            ingredients.append(newIng)

    recipe.ingredients = sanitizeIngredients(ingredients)
    recipe.steps = replaceDirections(modifiedIngredients, recipe.steps)
    recipe.name = "Chinese Version of -" + recipe.name
    print recipe.unicode()
    return recipe
コード例 #4
0
def findIngredient(ingr):   #Maps a string to the corresponding ingredient in the ingredient database
    ingr = ingr.lower()
    items = ingr.split()

    descriptors = []
    preparations = []

    soupOrSauce = False
    spiceOrPowder = False
    babyFood = False
    dairyProduct = False
    rawFood = False
    meatProduct = False
    sweetProduct = False
    snackProduct = False
    grainProduct = False
    
    beefProduct = False
    porkProduct = False
    poultryProduct = False
    fishProduct = False
    gameProduct = False

    groundProduct = False

    primeIng = ''

    for item in items:
        if item.endswith(','):
            if item.endswith('less,'):
                pass
            else:
                primeIng = item
                break

    if primeIng == '':
        filter = []
        if 'for' in items:
            ind = items.index('for')
            for j in range(0, ind):
                filter.append(items[j])
        elif 'with' in items:
            ind = items.index('with')
            for j in range(0, ind):
                filter.append(items[j])
        else:
            filter = items

        primeIng = filter[len(filter) - 1]

    primeIndex = items.index(primeIng)

    for x in range(0, primeIndex):
        if items[x].endswith('ed') and not items[x] == 'red':
            preparations.append(items[x])
        else:
            descriptors.append(items[x])

    p = items[(primeIndex + 1):]
    for item in p:
        preparations.append(item)

    if primeIng.endswith(','):
        primeIng = primeIng[:-1]

    if primeIng == 'zucchinis':
        primeIng = 'zucchini'

    primeIng = primeIng.lower()

    if (primeIng == 'soup' 
        or primeIng == 'sauce' 
        or primeIng == 'paste'
        or primeIng == 'bouillon'
        or primeIng == 'spread'):
        soupOrSauce = True

    if (primeIng == 'spice' 
        or primeIng == 'powder' 
        or primeIng == 'salt'
        or primeIng == 'cinnamon'
        or primeIng == 'nutmeg'):
        spiceOrPowder = True

    if 'baby' in items:
        babyFood = True

    if ('cheese' in primeIng 
        or 'milk' in primeIng 
        or 'cream' in primeIng 
        or 'yogurt' in primeIng 
        or 'whey' in primeIng 
        or 'egg' in primeIng 
        or 'butter' in primeIng
        or 'yolk' in primeIng):
        dairyProduct = True
        rawFood = True

    if 'fresh' in items or 'raw' in items:
        rawFood = True

    if ('meat' in items 
        or 'beef' in items 
        or 'pork' in items 
        or 'chicken' in items
        or 'turkey' in items
        or 'lamb' in items 
        or 'fish' in items
        or 'bacon' in items
        or 'mutton' in items):
        meatProduct = True
        rawFood = True

    if 'ground' in items:
        groundProduct = True

    if ('beef' in items
        or 'steak' in items):
        beefProduct = True

    if ('bacon' in items
        or 'pork' in items):
        porkProduct = True

    if ('chicken' in items
        or 'duck' in items
        or 'poultry' in items
        or 'turkey' in items):
        poultryProduct = True

    if ('lamb' in items
        or 'mutton' in items
        or 'veal' in items):
        gameProduct = True

    if ('fish' in items):
        fishProduct = True

    if ('sugar' in items 
        or 'syrup' in items 
        or 'sweetener' in items 
        or 'pudding' in items 
        or 'candies' in items 
        or 'candy' in items 
        or 'honey' in items 
        or 'frosting' in items
        or 'topping' in items
        or 'pie filling' in items
        or 'pectin' in items
        or 'marmalade' in items
        or 'molasses' in items
        or 'jelly' in items
        or 'jam' in items
        or 'fruit butter' in items
        or 'dessert' in items
        or 'flan' in items
        or 'rennin' in items
        or 'custard' in items
        or 'cocoa' in items
        or 'gum' in items
        or 'gelatin' in items
        or 'chocolate' in items
        or 'sherbet' in items):
        sweetProduct = True

    if ('cracker' in primeIng
        or 'crumbs' in primeIng):
        snackProduct = True

    if ('flour' in primeIng
        or 'grain' in primeIng
        or 'barley' in primeIng
        or 'cornmeal' in primeIng
        or 'millet' in primeIng
        or 'rice' in primeIng
        or 'pasta' in primeIng
        or 'noodle' in primeIng
        or 'oat' in primeIng
        or 'wheat' in primeIng
        or 'macaroni' in primeIng
        or 'spaghetti' in primeIng
        or 'hominy' in primeIng
        or 'sorghum' in primeIng
        or 'teff' in primeIng
        or 'quinoa' in primeIng
        or 'triticale' in primeIng
        or 'rye' in primeIng
        or 'couscous' in primeIng
        or 'bulgur' in primeIng
        or 'amaranth' in primeIng):
        grainProduct = True

    matches = []

    for DBing in lists.ingredientDB:

        matchScore = 0.0

        match = False
        soup = False
        spice = False
        baby = False
        dairy = False
        raw = False
        meat = False
        sweet = False
        snack = False
        grain = False
        pork = False
        beef = False
        poultry = False
        game = False
        fish = False
        meatMix = False
        ground = False

        if primeIng == 'flour':
            primeIng = 'flr'

        des = DBing.descriptor.split()
        nam = DBing.name.split(',')

        if DBing.category == '0600':
            soup = True

        if DBing.category == '0200':
            spice = True

        if DBing.category == '0300':
            baby = True

        if DBing.category == '0100':
            dairy = True

        if (DBing.category == '0500' 
            or DBing.category == '0700' 
            or DBing.category == '1000' 
            or DBing.category == '1300' 
            or DBing.category == '1500' 
            or DBing.category == '1700'):
            meat = True

        if 'BY-PRODUCTS' in DBing.name:
            meatMix = True

        if 'ground' in DBing.descriptor:
            gound = True

        if DBing.category == '0500':
            poultry = True

        if DBing.category == '1000':
            pork = True

        if DBing.category == '1300':
            beef = True

        if DBing.category == '1500':
            fish = True

        if DBing.category == '1700':
            game = True

        if DBing.category == '1900':
            sweet = True

        if DBing.category == '1800':
            snack = True

        if DBing.category == '2000':
            grain = True

        if 'RAW' in DBing.name:
            raw = True

        for word in nam:
            if primeIng not in word.lower():
                pass
            else:
                match = True
                if primeIng == word.lower():
                    matchScore += 100
                else:
                    matchScore += 50
                break

        for word in descriptors:
            if word == 'and':
                pass
            else:
                if word not in DBing.descriptor.lower():
                    pass
                else:
                    match = True
                    if word in lists.colors:
                        r = .1
                    elif descriptors.index(word) == len(descriptors) - 1:
                        r = .8 
                    else:
                        r = 1 #float(len(des)) / float(len(sItems))
                    for d in des:
                        if word in d.lower():
                            if word == 'crumbs':
                                pass
                            c = ''
                            if d.endswith(','):
                                c = d[:-1]
                            if word == c or word == d.lower():
                                matchScore += 2.0 / ((des.index(d) + 1.0) * r)
                            else:
                                matchScore += 1.0 / ((des.index(d) + 1.0) * r)
                            break
        if match:
            ing = objects.Ingredient()
            
            if primeIng == 'flr':
                ing.name += 'flour'
            else:
                ing.name += primeIng
            ing.origName = primeIng # VF: I need this for transformer, remove after search is fixed
            if len(descriptors) != 0:
                ing.descriptor = ''
            for i in descriptors:
                ing.descriptor += i + ' '
            ing.id = DBing.id
            
            if preparations == []:
                pass
            else:
                if ing.preparation == 'None':
                    ing.preparation = ''
                for word in preparations:
                    ing.preparation += word + ' '
            
            ing.category = DBing.category
            if DBing.protein != '' and DBing.protein != '\n':
                ing.protein = DBing.protein
            if DBing.carbs != '' and DBing.carbs != '\n':
                ing.carbs = DBing.carbs
            if DBing.fat != '' and DBing.fat != '\n':
                ing.fat = DBing.fat

            if soup and not soupOrSauce:
                matchScore = matchScore / 3.0
            if spice and not spiceOrPowder:
                matchScore = matchScore / 2.0
            if baby and not babyFood:
                matchScore = matchScore / 2.0
            if dairy and not dairyProduct:
                matchScore = matchScore / 2.0
            if rawFood and not raw:
                matchScore = matchScore / 2.0
            if meat and not meatProduct:
                matchScore = matchScore / 2.0
            if meatProduct and meatMix:
                matchScore = matchScore / 2.0
            if porkProduct and not pork:
                matchScore = matchScore / 5.0
            if beefProduct and not beef:
                matchScore = matchScore / 5.0
            if poultryProduct and not poultry:
                matchScore = matchScore / 5.0
            if fishProduct and not fish:
                matchScore = matchScore / 5.0
            if gameProduct and not game:
                matchScore = matchScore / 5.0
            if sweet and not sweetProduct:
                matchScore = matchScore / 2.0
            if sweetProduct and not sweet:
                matchScore = matchScore / 2.0
            if snack and not snackProduct:
                matchScore = matchScore / 2.0
            if grain and not grainProduct:
                matchScore = matchScore / 2.0
            if grainProduct and not grain:
                matchScore = matchScore / 2.0
            if ground and not groundProduct:
                matchScore = matchScore / 2.0

            tup = (ing, matchScore)
            matches.append(tup)

    result = objects.Ingredient()
    topIndex = 0
    topScore = 0
    for find in matches:
        if find[1] > topScore:
            result = find[0]
            topIndex = matches.index(find)
            topScore = find[1]

    if result.name == 'flr':
        result.name = 'flour'

    if '.' not in result.carbs:
        result.carbs = '0.00'
    if '.' not in result.fat:
        result.fat = '0.00'
    if '.' not in result.protein:
        result.protien = '0.00'

    return result