Created
August 6, 2013 08:57
-
-
Save tos-kamiya/6162869 to your computer and use it in GitHub Desktop.
study of mrjob
This file contains 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 characters
import re | |
from mrjob.job import MRJob | |
WORD_RE = re.compile(r"[\w']+") | |
class WordCollocationCount(MRJob): | |
def mapper(self, _, line): | |
t = [word.lower() for word in WORD_RE.findall(line)] | |
for w1, w2 in zip(t, t[1:]): | |
yield (w1, w2), 1 | |
def combiner(self, word_pair, counts): | |
yield word_pair, sum(counts) | |
def reducer(self, word_pair, counts): | |
yield word_pair, sum(counts) | |
if __name__ == '__main__': | |
WordCollocationCount.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment