def mv_top_tags(self,mvid,top=30): tags = db_info.movie_tag_relevance(mvid) genres = db_info.movie_genres(mvid) if genres: for g in genres: tags[g] = 1 if tags: return util.hash2list(tags)[:top] else: return None
def user_tags(self,top=30): tag_count = {} for m in self.mv_list: top_tags = self.mv_top_tags(m) if not top_tags: continue for t in top_tags: (relevance,tagid) = t[:] if tagid not in tag_count: tag_count.setdefault(tagid,relevance) else: tag_count[tagid] += relevance return util.hash2list(tag_count)[:top]
def recommend_for_user(userid,top_neighbor,top_movie,x): neighbors_map = get_user_neighbors(userid,top_neighbor) neighbors = tuple(neighbors_map.keys()) neighbor_movies = db.get_movie_from_users(neighbors) # movies_count = list_count(neighbor_movies,neighbors_map) # movies_count = filter_item_for_user(movies_count,userid) # candidate_list = util.hash2list(movies_count) # recommend_list = [candidate_list[i][1] for i in range(0,top_movie)] candidate_list = util.hash2list(score_items(userid,neighbors_map,neighbor_movies,x)) recommend_list = [candidate_list[i][1] for i in range(len(candidate_list))] # item_ids = get_candidate_item_list(userid,neighbor_movies) # ratings = recommender.get_ratings(userid, item_ids) # recommendations = ranker.maximizeKGreatItems(top_movie, ratings, db_info.movie_user_ratings) # recommend_list = [r[1] for r in recommendations] return recommend_list[:top_movie]