def load_pickle(api): files = ['que_' + api] load_files = Mypickle.load(path, files) return load_files[0]
elif d == "old": d_flag = False break while (1): print("input queryID") queryID = input('>>> ') break print("queryID is {0}\n".format(queryID)) c_flag = database.select("SELECT * from query where queryID = \'" + queryID + "\'") if len(c_flag) > len(seeds_list): from mymodule import Mypickle seeds_score = Mypickle.load(path, "seeds_score_" + queryID) _, next_pattern = recommend.passcheck_continue("0", seeds_score) seeds_list = [i for i in seeds_score.keys()] else: seed_score = {p: [start_score, 0, 0, 0] for p in path_pattern} #[precision, good, bad] seeds_score = {i: seed_score for i in seeds_list} import random next_pattern = random.choice(path_pattern) for seed in seeds: database.insert("query", (0, seed, queryID, "None")) while (len(seeds_list) < get_num + start_num): next_pattern, seeds_list, seeds_score = recommend.recommendation(
def get_match(pattern, seeds): print("now : pattern{0}".format(pattern)) from mymodule import Myyaml path_pattern = Myyaml.load("path")["path_com"]["39"] needs = Myyaml.load("path")["basic_path_com"][pattern] print("needs:{0}".format(needs)) target_list = [] target_seeds = {} for seed in seeds: print("graph {0}".format(seed)) f = True for need in needs: if os.path.isfile(DIR + seed + '_' + need + '.pickle') == False: f = False break if f: print("all pickle") match_list = [] for need in needs: su = Mypickle.load(DIR, seed + '_' +need) match_list = list(set(match_list) | set(su)) else: print("else") if pattern == path_pattern[0]:#friend match_list = basic_pass1(seed) elif pattern == path_pattern[1]:#follower match_list = basic_pass2(seed) elif pattern == path_pattern[2]:#com_friend match_list = basic_pass3(seed) elif pattern == path_pattern[3]:#com_follower match_list = basic_pass4(seed) elif pattern == path_pattern[4]:#friend_friend match_list = basic_pass5(seed) elif pattern == path_pattern[5]:#follower_follower match_list = basic_pass6(seed) elif pattern == path_pattern[6]:#mutual match_list = basic_pass7(seed) elif pattern == path_pattern[7]:#8 match_list = basic_pass8(seed) elif pattern == path_pattern[8]:#9 match_list = basic_pass9(seed) elif pattern == path_pattern[9]:#10 match_list = basic_pass10(seed) elif pattern == path_pattern[10]:#11 match_list = basic_pass11(seed) elif pattern == path_pattern[11]:#12 match_list = basic_pass12(seed) elif pattern == path_pattern[12]:#13 match_list = basic_pass13(seed) elif pattern == path_pattern[13]:#14 match_list = basic_pass14(seed) elif pattern == path_pattern[14]:#15 match_list = basic_pass15(seed) elif pattern == path_pattern[15]:#16 match_list = basic_pass16(seed) elif pattern == path_pattern[16]:#17 match_list = basic_pass17(seed) elif pattern == path_pattern[17]:#18 match_list = basic_pass18(seed) elif pattern == path_pattern[18]:#19 match_list = basic_pass19(seed) elif pattern == path_pattern[19]:#20 match_list = basic_pass20(seed) elif pattern == path_pattern[20]:#21 match_list = basic_pass21(seed) elif pattern == path_pattern[21]:#22 match_list = basic_pass22(seed) elif pattern == path_pattern[22]:#23 match_list = basic_pass23(seed) elif pattern == path_pattern[23]:#24 match_list = basic_pass24(seed) elif pattern == path_pattern[24]:#25 match_list = basic_pass25(seed) elif pattern == path_pattern[25]:#26 match_list = basic_pass26(seed) elif pattern == path_pattern[26]:#27 match_list = basic_pass27(seed) elif pattern == path_pattern[27]:#28 match_list = basic_pass28(seed) elif pattern == path_pattern[28]:#29 match_list = basic_pass29(seed) elif pattern == path_pattern[29]:#30 match_list = basic_pass30(seed) elif pattern == path_pattern[30]:#31 match_list = basic_pass31(seed) elif pattern == path_pattern[31]:#32 match_list = basic_pass32(seed) elif pattern == path_pattern[32]:#33 match_list = basic_pass33(seed) elif pattern == path_pattern[33]:#34 match_list = basic_pass34(seed) elif pattern == path_pattern[34]:#35 match_list = basic_pass35(seed) match_seeds = join_dic([match_seeds]) elif pattern == path_pattern[35]:#36 match_list = basic_pass36(seed) elif pattern == path_pattern[36]:#37 match_list = basic_pass37(seed) elif pattern == path_pattern[37]:#38 match_list = basic_pass38(seed) elif pattern == path_pattern[38]:#39 match_list = basic_pass39(seed) else: print("key error : {0}".format(pattern)) print("match_list : {0}".format(len(match_list))) target_list = list((set(target_list) | set(match_list))) target_seeds = match(seed, match_list, target_seeds) return target_list, target_seeds
SQL_match = database.select( "SELECT userID from query where queryID LIKE \'%" + queryID + "%\'" + "and result = \'2\'") seeds = [s[0] for s in SQL_seeds] match = list(set([s[0] for s in SQL_match])) node2node = { } #{userID:{friend:...,follower:...,friend2friend:...,friend2follower:...,follower2friend:...,follower2follower:...,}} nodeofflags = {} path = "../query/analysis/" pickle_path = "../pickle/positive/" doc_name = queryID + "_node2node" if os.path.exists(path + doc_name + ".pickle"): node2node = Mypickle.load(path, doc_name) print(len(node2node)) print("seeds : {0}".format(seeds)) print("match : {0}".format(match)) for user in seeds + match: if user in node2node.keys(): continue node2node[user] = {} if user not in nodeofflags: nodeofflags[user] = [True, True] print("\nuser : {0} start".format(user)) if nodeofflags[user][0] and nodeofflags[user][1]:
def update(goal, userID, seed): friends = [] followers = [] flag = database.check(userID) if userID == seed: if goal == 'all': if os.path.isfile(DIR + seed + '_1' + '.pickle'): friends = Mypickle.load(DIR, seed + '_1') else: friends = up('friends_only', userID) if os.path.isfile(DIR + seed + '_2' + '.pickle'): followers = Mypickle.load(DIR, seed + '_2') else: followers = up('followers_only', userID) return friends, followers elif goal == 'friends_only': if os.path.isfile(DIR + seed + '_1' + '.pickle'): return Mypickle.load(DIR, seed + '_1') else: if os.path.isfile(DIR + seed + '_2' + '.pickle'): return Mypickle.load(DIR, seed + '_2') if goal == 'all': if flag == '***': friends = use_API(userID, 'friends') if friends is not None: database.select('UPDATE checked_list SET state = \'friends_only\' WHERE userID = \'{0}\''.format(userID)) followers = use_API(userID, 'followers') if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID)) elif flag == 'followers_only': friends = use_API(userID, 'friends') followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID)) followers = tuple2list(followers) if friends is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID)) elif flag == 'friends_only': followers == use_API(userID, 'followers') friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID)) friends = tuple2list(friends) if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID)) elif flag == "all": friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID)) friends = tuple2list(friends) followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID)) followers = tuple2list(followers) if friends is None or followers is None: return [], [] return friends, followers elif goal == 'friends_only': if flag == 'followers_only': friends = use_API(userID, 'friends') if friends is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID)) elif flag == '***': friends = use_API(userID, 'friends') if friends is not None: database.select('UPDATE checked_list SET state = \'friends_only\' WHERE userID = \'{0}\''.format(userID)) elif flag == 'friends_only' or flag == 'all': friends = use_API(userID, 'friends') friends = database.select('SELECT followerID FROM follow_graph WHERE userID = \'{0}\''.format(userID)) friends = tuple2list(friends) if friends is None: return [] return friends elif goal == 'followers_only': if flag == 'friends_only': followers = use_API(userID, 'followers') if followers is not None: database.select('UPDATE checked_list SET state = \'all\' WHERE userID = \'{0}\''.format(userID)) elif flag == '***': followers = use_API(userID, 'followers') if followers is not None: database.select('UPDATE checked_list SET state = \'followers_only\' WHERE userID = \'{0}\''.format(userID)) elif flag == 'followers_only' or flag == 'all': followers = database.select('SELECT userID FROM follow_graph WHERE followerID = \'{0}\''.format(userID)) followers = tuple2list(followers) if followers is None: return [] return followers