I'm trying to make a MapReduce WordCount that get a large article and counts proper nouns. Here's requirements:
- Starts with a capital letter and has never been found in the text with a small letter
- Has length between 2 and 7 letters
- Sort in descending order
Looks like a typical WordCount mapreduce, but I couldn't do this. How to get rid of all the punctuation marks? What's the right way to construct mapper and reducer?
import sys
import re
for line in sys.stdin:
article_id, text = line.strip().split('\t', 1)
text = re.sub('\W', ' ', text).split(' ')
for word in text:
if len(word) >= 2 and len(word) < 7:
key = "".join(sorted(word.lower()))
print("{}\t{}\t{}".format(key, word.lower(), 1))