Created
March 10, 2013 22:50
-
-
Save masayang/5130862 to your computer and use it in GitHub Desktop.
Revisions
-
masayang created this gist
Mar 10, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ W, A, B, C X, A, B, C, D, Z Y, A, B, E Z, A, B, D, E This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ from mrjob.job import MRJob class Recommendation(MRJob): def mapper(self, key, line): input = line.split(',') user, friends = input[0], input[1:] for i in range(len(friends)): f1 = friends[i].strip() for j in range(i+1, len(friends)): f2 = friends[j].strip() if f1 < f2: yield(f1, f2), 1 else: yield(f2, f1), 1 def reducer(self, key, values): f1, f2 = key mutual_friends_count = 0 for value in values: mutual_friends_count += value yield (f1, f2), mutual_friends_count if __name__ == '__main__': Recommendation.run()