def aiSub(ingredients, unwantedIng): #First get frequent item sets L = ap.readFromFile() if not(unwantedIng in ingredients): return "error" ingredients.remove(unwantedIng) wantedIngredients = set(ingredients) a = 0 bestFit = None for thing in L: if thing <= wantedIngredients: continue counter = 0 for ing in thing: if ing in wantedIngredients: counter += 1 if counter > a and not('butter' in thing) and not('bread' in thing): a = counter bestFit = thing elif counter == a: pass #do something clever here return bestFit - set(ingredients)
def retrievePatterns(ingredient): # For generating local patterns instead of global patterns # db = connect(host="localhost", db="sandwiches", user="******", passwd="root") # cursor = db.cursor() # cursor1 = db.cursor() # cursor2 = db.cursor() # cursor.execute("""SELECT recipes.recipeId, recipeName FROM ingredients, recipes, ingredientsForRecipe WHERE ingredients.ingredientId = ingredientsForRecipe.ingredientId and recipes.recipeId = ingredientsForRecipe.recipeId and ingredientName = %s """, ingredient) # l = [] # for row in cursor: # cursor1.execute("""SELECT ingredientId FROM ingredientsForRecipe WHERE recipeId = %s""", row[0]) # temp = [] # for r in cursor1: # # temp.append(int(r[0])) # cursor2.execute("""SELECT ingredientName FROM ingredients WHERE ingredientId = %s""", r[0]) # t = cursor2.fetchone() # temp.append(t) # l.append(temp) # result, supp = ap.apriori(l, minsupport=0.02) return ap.readFromFile()