i am new in python and i want to use MrJob package for countind relative frequency of pair words i wrote below code but it doesn't make correct output. can you plz help me with my mistakes? (|) = (, )/()=(, )/∑A' (′ , )
import re
from collections import defaultdict
from mrjob.job import MRJob
WORD_RE = re.compile(r"[\w']+")
class MRRelativeFreq(MRJob):
def mapper(self, _, line):
for word in WORD_RE.findall(line):
for wordpair in WORD_RE.findall(line):
if word != wordpair:
yield (word.lower(), wordpair.lower(), 1)
def reducer(self, key, values):
cnts = defaultdict(int)
total = 0
for (word, count) in values:
cnt=0
total += count
cnts[word] += count
for (k,kp), v in cnts.items():
yield (k,kp), (v, float(v) / total)
def combiner(self, key, values):
yield None, (key, sum(values))
if __name__ == '__main__':
MRRelativeFreq.run()