def recommend(self, i, id, location, num): print(id + "\t" + num + "\t" + i + '\t' + urllib.unquote(location).decode('utf-8')) location = urllib.unquote(location).decode('utf-8') conf = Config('../config/UserKNN.conf') if num is None or num < 3: num = 3 if int(i) == 1: sysRec = RecQ(conf) sysRec.execute() model_f = open(conf['model.file']) lr = [] for line in model_f: l = line.split(' ') if str(l[0]) == str(id): lr.append(line) print("l:{}".format(l)) l = [] for r in lr: rs = str(r).split(' ') if len(l) < int(num): l.append(rs[1]) print("r :{}".format(rs[1])) s = [] lt = [] with open(conf['stock.file']) as f: for ind, line in enumerate(f): if line.strip() <> '': li = line.split("\t") x = li[0] e = li[1] loc = li[2] if len(l) == 0: s.append(str(x)) else: b_append = False for k in l: if e == k: lt.append(str(x)) elif location == loc.decode('utf-8'): b_append = True if b_append: s.append(str(x)) le = len(s) print(le) if le > (int(num) - len(l)): ret = random.sample(s, int(num) - len(l)) for r in ret: lt.append(r) else: for r in s: lt.append(r) return {"list": [lt], "code": 200}
conf = Config('../config/ItemMean.conf') elif order == 'b3': conf = Config('../config/MostPopular.conf') elif order == 'b4': conf = Config('../config/rand.conf') elif order == 'd1': conf = Config('../config/APR.conf') elif order == 'd2': conf = Config('../config/CDAE.conf') elif order == 'd3': conf = Config('../config/DMF.conf') elif order == 'd4': conf = Config('../config/NeuMF.conf') elif order == 'd5': conf = Config('../config/CFGAN.conf') else: print 'Error num!' exit(-1) recSys = RecQ(conf) recSys.execute() e = time.time() print "Run time: %f s" % (e - s)
elif order == 9: conf = Config('../config/PMF.conf') elif order == 10: conf = Config('../config/TrustMF.conf') elif order == 11: conf = Config('../config/SocialMF.conf') elif order == 12: conf = Config('../config/SoRec.conf') elif order == 13: conf = Config('../config/SoReg.conf') elif order == 14: conf = Config('../config/SVD++.conf') elif order == 15: conf = Config('../config/EE.conf') else: print 'Error num!' exit(-1) RecQ = RecQ(conf) RecQ.execute() e = time.clock() print "Run time: %f s" % (e - s)