MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / manual_join

Function manual_join

modelzoo/dien/data/script/process_data.py:29–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27
28
29def manual_join():
30 f_rev = open("reviews-info", "r")
31 user_map = {}
32 item_list = []
33 for line in f_rev:
34 line = line.strip()
35 items = line.split("\t")
36 #loctime = time.localtime(float(items[-1]))
37 #items[-1] = time.strftime('%Y-%m-%d', loctime)
38 if items[0] not in user_map:
39 user_map[items[0]] = []
40 user_map[items[0]].append(("\t".join(items), float(items[-1])))
41 item_list.append(items[1])
42 f_meta = open("item-info", "r")
43 meta_map = {}
44 for line in f_meta:
45 arr = line.strip().split("\t")
46 if arr[0] not in meta_map:
47 meta_map[arr[0]] = arr[1]
48 arr = line.strip().split("\t")
49 fo = open("jointed-new", "w")
50 for key in user_map:
51 sorted_user_bh = sorted(user_map[key], key=lambda x: x[1])
52 for line, t in sorted_user_bh:
53 items = line.split("\t")
54 asin = items[1]
55 j = 0
56 while True:
57 asin_neg_index = random.randint(0, len(item_list) - 1)
58 asin_neg = item_list[asin_neg_index]
59 if asin_neg == asin:
60 continue
61 items[1] = asin_neg
62 print("0" + "\t" + "\t".join(items) + "\t" +
63 meta_map[asin_neg],
64 file=fo)
65 j += 1
66 if j == 1: #negative sampling frequency
67 break
68 if asin in meta_map:
69 print("1" + "\t" + line + "\t" + meta_map[asin], file=fo)
70 else:
71 print("1" + "\t" + line + "\t" + "default_cat", file=fo)
72
73
74def split_test():

Callers 1

process_data.pyFile · 0.70

Calls 4

stripMethod · 0.80
splitMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected