forked from manasRK/word2vec-recommender
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmeta_preprocessing_local.py
More file actions
66 lines (50 loc) · 1.34 KB
/
meta_preprocessing_local.py
File metadata and controls
66 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Akhil Gupta
# @Email: akhilgupta.official@gmail.com
# @Github username: @codeorbit
# @Last Modified by: Manas Ranjan Kar
# @Last Modified time: 2016-06-28
import json
import gzip
import redis
data_obj = redis.Redis("localhost", port=6379, db=9) # 2, 9
def preProcess(row):
#print row
temp = []
productId = row["asin"]
try:
boughtTogether = row["related"]["bought_together"]
for ele in boughtTogether:
temp.append(ele)
except:
pass
try:
alsoBought = row["related"]["also_bought"]
for ele in alsoBought:
temp.append(ele)
except:
pass
try:
alsoViewed = row["related"]["also_viewed"]
for ele in alsoViewed:
temp.append(ele)
except:
pass
if temp ==[]:
pass
else:
data_obj.set(productId, temp)
def parse(path):
g = gzip.open(path, 'rb')
for l in g:
yield (eval(l))
def main():
count = 0
for row in parse("data/metadata/meta_Clothing_Shoes_and_Jewelry.json.gz"):
count+=1
if( (count)%5000 == 0 ):
print "Metas loaded: %s" % ( count )
preProcess(row)
main()
print 'Loaded !'