def __init__(self): self.load_conf() getters = self.build_vec_getter() self.ranking = Ranking(self.builder, self.distance, getters[1], getters[2]) self.ad_c_cache, self.ad_cache = self.loader.load_ads() self.number_content() self.retrival = CategoryRetrivalStrategyCenter(self.builder, self.distance, getters[0], getters[2])
class RetrivalAndRankingChooseController(RankingChooseController): '''Use the retrival ad category firstly, and ranking the ads. ''' def __init__(self): self.load_conf() getters = self.build_vec_getter() self.ranking = Ranking(self.builder, self.distance, getters[1], getters[2]) self.ad_c_cache, self.ad_cache = self.loader.load_ads() self.number_content() self.retrival = CategoryRetrivalStrategyCenter(self.builder, self.distance, getters[0], getters[2]) def get_content_ads(self, num): '''Get the content whose id is num and the recommend ads Args: num : content id Returns: (content, [list of ad content]) ''' if num >= self.count: return (('', ''), []) print num, self.content_key[num] content_obj = self.loader.load_content(self.content_key[num]) categorys = self.retrival.get_category(content_obj, self.ad_c_cache) retrival_ads = [] print 'categorys:' for category in categorys: print category.name retrival_ads += self.ad_cache.get_ads(category) ads = self.ranking.ranking(content_obj, retrival_ads, topk = 2) res_ad = [] for score, ad_key in ads: res_ad.append(self.loader.get_ad_info(ad_key)) return (self.loader.get_content_info(self.content_key[num]), res_ad)