-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvertedIndex.py
More file actions
43 lines (37 loc) · 926 Bytes
/
Copy pathInvertedIndex.py
File metadata and controls
43 lines (37 loc) · 926 Bytes
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
import MapReduce
import sys
"""
Word Count Example in the Simple Python MapReduce Framework
"""
mr = MapReduce.MapReduce()
# =============================
# Do not modify above this line
def mapper(record):
# key: document identifier
# value: document contents
key = record[0]
value = record[1]
words = value.split()
for w in words:
mr.emit_intermediate(w, key)
def reducer(key, list_of_values):
# key: word
# value: list of occurrence counts
#total = 0
first = True
sb = ""
prev = ""
for v in list_of_values:
if(prev != v):
if(first == False):
sb = sb + "," +v
else:
first = False
sb = v
prev = v
mr.emit((key, sb))
# Do not modify below this line
# =============================
if __name__ == '__main__':
inputdata = open(sys.argv[1])
mr.execute(inputdata, mapper, reducer)