def manage(arg): # arg = sys.argv[1] if arg == 'preprocess': Channel().process() elif arg == 'cf': user_cf(2073000) elif arg == 'lfm': lfm() elif arg == 'prank': prank(2073000) else: print('Args must in ["preprocess", "cf", "lfm","prank"].') sys.exit()
def manage(): param = sys.argv[1] #0:文件名 if param == 'preprocess': Channel().process() elif param == 'cf': start = time.time() movies = UserCF().recommend(2, 10) result = getNames(movies) for movie in result: print(movie[1][0], movie[0][1]) print('Cost time:%f' % (time.time() - start)) else: print('Args must in ["preprocess", "cf", "lfm","prank"].') sys.exit()
def manage(): arg = sys.argv[1] if arg == 'preprocess': Channel().process() elif arg == 'cf': user_cf() elif arg == 'lfm': #lfm() print('lfm耗时过长,暂停使用') elif arg == 'prank': prank() else: print('Args must in ["preprocess", "cf", "lfm","prank"].') sys.exit()
def manage(): # arg = sys.argv[1] arg = 'lfm' if arg == 'preprocess': Channel().process() elif arg == 'itemcf': item_cf() elif arg == 'cf': user_cf() elif arg == 'lfm': lfm() elif arg == 'prank': prank() else: print('Args must in ["preprocess", "cf", "lfm","prank"].') sys.exit()
def methods(method_name): if method_name == 'preprocess': Channel().process() elif method_name == 'cf': return cfMed() elif method_name == 'rsif': return rsifMed() elif method_name == 'if': return ifMed() elif method_name == 'lfm': return lfmMed() elif method_name == 'prank': return prankMed() elif method_name == 'tcUser': return tcUserMed() elif method_name == 'tcItems': return tcItemsMed() elif method_name == 'tcPopular': return tcPopularMed() elif method_name == 'setData': return tcSetData() elif method_name == 'getData': return tcGetData() else: abort(404)
def manage(): arg = sys.argv[1] if arg == 'preprocess': Channel().process() elif arg == 'excute': target = int(sys.argv[2]) # 这里用运行参数代表用户id赋值给target result1 = user_cf() result2 = lfm(target) result3 = prank(target) #三个result的输出格式为[[str,浮点数],[str,浮点数]......] result1 = list(result1) result2 = list(result2) result3 = list(result3) result = [] count = 0 for i in result2: for j in result3: for k in result1: i = list(i) j = list(j) k = list(k) if i[0] == delete_substr_method2(j[0], "item_") == k[0]: result.append(i[0]) i[1] = 100 j[1] = 100 k[1] = 100 elif i[0] == delete_substr_method2(j[0], "item_"): result.append(i[0]) i[1] = 100 j[1] = 100 elif k[0] == i[0]: result.append(i[0]) k[1] = 100 i[1] = 100 elif k[0] == delete_substr_method2(j[0], "item_"): result.append(k[0]) k[1] = 100 j[1] = 100 else: for i in result2: for j in result3: for k in result1: if i[1] != 100: result.append(i[0]) if j[1] != 100: result.append( delete_substr_method2( j[0], "item_")) if k[1] != 100: result.append(k[0]) with open("recommand_result_" + sys.argv[2] + ".txt", 'w', encoding='utf-8') as f: for ok in result: if count < 10: print(ok) f.write(str(ok) + "\n") count = count + 1 else: print('Args must in ["preprocess", "excute"].') sys.exit()