-
Notifications
You must be signed in to change notification settings - Fork 1
/
MRFilterComments.py
54 lines (38 loc) · 1.2 KB
/
MRFilterComments.py
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
from mrjob.job import MRJob
from mrjob.step import MRStep
import sys
import csv
import spacy
import re
import numpy as np
#python3 taskx.py csvfile > newcsvfilename
class MRMakeSentences(MRJob):
'''
'''
def mapper_init(self):
self.active_user_list = set() #np.zeros(100000, dtype=object)
active = open('active_final.csv')
active = active.readlines()
for ind, user in enumerate(active):
user = user.strip()
user_edit = re.findall(r'"(.*)"', user)
self.active_user_list.add(user_edit[0])
#print(self.active_user_list)
def mapper(self, _, line):
parsed = line.split(',')
user = re.findall(r'"(.*)',parsed[0])[0]
if user in self.active_user_list:
#print(line)
comment = re.sub("[^(\w\s)]", "", parsed[1])
comment = comment.strip()
yield (user, comment), None
def reducer(self, user, count):
yield user, None
def steps(self):
return [
MRStep(
mapper_init=self.mapper_init,
mapper=self.mapper,
reducer=self.reducer)]
if __name__ == '__main__':
MRMakeSentences.run()