我是 python 新手,正在尝试处理大数据代码,但无法理解表达式re.compile(r"[\w']+") 的含义。有人对此有任何想法吗?
这是我使用的代码。
from mrjob.job import MRJob
import re
WORD_REGEXP = re.compile(r"[\w']+")
class MRWordFrequencyCount(MRJob):
def mapper(self, _, line):
words = WORD_REGEXP.findall(line)
for word in words:
yield word.lower(), 1
def reducer(self, key, values):
yield key, sum(values)
if __name__ == '__main__':
MRWordFrequencyCount.run()
Run Code Online (Sandbox Code Playgroud)