File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import MapReduce
2
+ import sys
3
+
4
+ """
5
+ Word Count Example in the Simple Python MapReduce Framework
6
+ """
7
+
8
+ mr = MapReduce .MapReduce ()
9
+
10
+ # =============================
11
+ # Do not modify above this line
12
+
13
+ def mapper (record ):
14
+ # key: document identifier
15
+ # value: document contents
16
+ key = record [0 ]
17
+ value = record [1 ]
18
+ words = value .split ()
19
+ for w in words :
20
+ mr .emit_intermediate (w , 1 )
21
+
22
+ def reducer (key , list_of_values ):
23
+ # key: word
24
+ # value: list of occurrence counts
25
+ total = 0
26
+ for v in list_of_values :
27
+ total += v
28
+ mr .emit ((key , total ))
29
+
30
+ # Do not modify below this line
31
+ # =============================
32
+ if __name__ == '__main__' :
33
+ inputdata = open (sys .argv [1 ])
34
+ mr .execute (inputdata , mapper , reducer )
You can’t perform that action at this time.
0 commit comments