def product_profile(): importer = pre_analyzed_importer.PreImporter(db_name='pre_analyze') users = [u[2] for u in importer.import_user()] products = [p[2] for p in importer.import_product()] user = random.sample(users, 1)[0] product = random.sample(products, 1)[0] recom = PPRecommendation(db_name='pre_analyze', top_tag_number=7, top_related_products=5, user=user, product=product) recom_prods = recom.recom_from_tags() with open('product.json', 'w') as f1, open('user.json', 'w') as f2, open('recom_prods.json', 'w') as f3: json.dump({'tags': product['tags'], 'id': product['id']}, f1, indent=4) json.dump({'tags': user['tags'], 'id': user['id']}, f2, indent=4) json.dump([{ 'tags': i['tags'], 'id': i['id'] } for i in recom_prods if isinstance(i, dict)], f3, indent=4)
def __init__(self, *args, **kwargs): db_name = kwargs['db_name'] self.importer = pre_analyzed_importer.PreImporter(db_name=db_name) self.product = kwargs['product'] self.user = kwargs['user'] self.top_tag_number = kwargs['top_tag_number'] self.top_related_products = kwargs['top_related_products']
def __init__(self, *args, **kwargs): pre_analyzed_db_name = kwargs['pre_analyzed_db_name'] self.time_format = kwargs['time_format'] self.recent_date_number = kwargs['recent_date_number'] self.similar_product_number = kwargs['similar_product_number'] self.importer = pre_analyzed_importer.PreImporter( db_name=pre_analyzed_db_name)
def __init__(self, *args, **kwargs): db_name = kwargs['db_name'] self.wordnet = self.load_wordnet() self.importer = pre_analyzed_importer.PreImporter(db_name=db_name) self.all_products = self.load_products() # Number of products to be suggested for events. self.product_number = kwargs['product_number']
def __init__(self, *args, **kwargs): self.top_n = kwargs['novel_number'] self.days = kwargs['novel_days'] pre_analyzed_db_name = kwargs['pre_analyzed_db_name'] pre_importer = pre_analyzed_importer.PreImporter( db_name=pre_analyzed_db_name) self.all_products = pre_importer.import_products()
def __init__(self, *args, **kwargs): db_name = kwargs['db_name'] self.importer = pre_analyzed_importer.PreImporter(db_name=db_name) self.user = kwargs['user'] self.user_profile = { 'product_similarity': {}, 'user_similarity': { 'level_1': {}, 'level_2': {} } }
def __init__(self, *args, **kwargs): super(User, self).__init__(*args, **kwargs) pre_importer = pre_analyzed_importer.PreImporter(db_name=self.pre_analyzed_db_name) self.max_rate = kwargs['max_rate'] self.download_factor = kwargs['download_factor'] self.view_factor = kwargs['view_factor'] self.rate_power_factor = kwargs['rate_power_factor'] try: self.users = self.get_users() except: # exception must be handled raise else: try: self.products = pre_importer.import_product() except: raise else: self.products = [i[2] for i in self.products] self.users = [i[2] for i in self.users] self.add_product_affinity_user_tags()
def user_profile(): importer = pre_analyzed_importer.PreImporter(db_name='pre_analyze') users = [u[2] for u in importer.import_user()] # products = [p[2] for p in importer.import_product()] for user in users: print("processing {}".format(user['id'])) recom = Recommendation(user=user, db_name='pre_analyze') recom.product_similarity() recom.user_similarity() new_products = [user['id']] + list(user['tags'].items()) user_profile = recom.user_profile product_similarity = user_profile['product_similarity'] top_ps = dict( sorted(product_similarity.items(), key=itemgetter(1))[-3:]) user_similarity = user_profile['user_similarity'] us_l1 = user_similarity['level_1'] top_l1 = dict(sorted(us_l1.items(), key=itemgetter(1))[-3:]) us_l2 = user_similarity['level_2'] top_l2 = dict(sorted(us_l2.items(), key=itemgetter(1))[-3:]) with open('result.json', 'a+') as f: json.dump(new_products, f, indent=4) json.dump(['---' * 10], f, indent=4) json.dump(top_ps, f, indent=4) json.dump(['---' * 10], f, indent=4) json.dump(top_l1, f, indent=4) json.dump(['---' * 10], f, indent=4) json.dump(top_l2, f, indent=4) json.dump(['####' * 10], f, indent=4) products = [p[2] for p in importer.import_product()] with open('product.json', 'w') as f1: json.dump([{ 'tags': p['tags'], 'id': p['id'] } for p in products], f1, indent=4)
def __init__(self, *args, **kwargs): self.pre_analyzed_db_name = ['kwargs'] self.pre_importer = pre_analyzed_importer.PreImporter( db_name=self.pre_analyzed_db_name)