def Item_based():
    user_id=session['user_id'][0]
    productData = functions.flipPersonToPlaces(reviewdata1.reviews)
    print "Finding similar Places " # for single place
    similar_item=functions.mostSimilar(productData,"4iTRjN_uAdAb7_YZDVHJdg")
    print dict(similar_item)
    b_data=[]
    for bid in dict(similar_item).keys():
        sql = ("SELECT B_NAME, PHOTO_URL,RATING from BUSINESS_CA where B_ID = '%s'" % bid)
        cursor.execute(sql)
        data = cursor.fetchone()
        if data != None:
            b_data.append([data[0],data[1],data[2]])
    print b_data
    print "******************"
    print "Computing Item Similarity" # for entire product data
    itemSimilarity = functions.computeItemSimilarities(productData)
    print itemSimilarity
    print "******************"
    print "Item Based Filtering for Recommendations"
    recommendedplc_ib=functions.itemBasedFiltering(reviewdata1.reviews,str(user_id),itemSimilarity)
    print recommendedplc_ib.keys() #send to shivani

    locations =[]
    for bid in recommendedplc_ib.keys():
        sql = ("SELECT B_NAME, LATITUDE, LONGITUDE, ADDRESS, RATING from BUSINESS_CA where B_ID = '%s'" % bid)
        cursor.execute(sql)
        data_map = cursor.fetchone()
        if data_map!=None:
            value=[str(data_map[0]),float(data_map[1]),float(data_map[2]),str(data_map[3]),data_map[4]]
            locations.append(value)
    print "locations is"
    print locations
    return render_template('ItemRecommend.html',location=locations,similarplaces=b_data)
示例#2
0
# print "Most similar critcs "
# print functions.mostSimilar(data.critics,"Toby")

# print " "

# print "Product Recommendations for a user"
# print functions.getRecommendations(data.critics,person2)   #how much will one user like a particular  movie

# print " "

productData = functions.flipPersonToMovie(data.critics)

# print "Finding similar movies "
# print functions.mostSimilar(productData,"Superman Returns")   #Find similar movies

# print " "

# print "Finding user Recommendations for a product"
# print functions.getRecommendations(productData,"Just My Luck") #Out of the people Who havent seen the movie Who will like this movie ?

# print " "


# print "Computing Item Similarity"
itemSimilarity = functions.computeItemSimilarities(productData)


print "Item Based Filtering for Recommendations"
print functions.itemBasedFiltering(data.critics, "Toby", itemSimilarity)