美文网首页
Inverted index(Map Reduce)

Inverted index(Map Reduce)

作者: Zihowe | 来源:发表于2017-09-04 16:44 被阅读15次
image.png

Python Solution:

class WordCount:
    def mapper(self, key, line):
        # key我们可以当做是index,或者URL
        for word in line.split():
            yield word, key

    # @param key is from mapper
    # @param values is a set of value with the same key
    def reducer(self, key, values):
        # values 是一组index 或者 URL
        indexes = []
        for v in values:
            indexes.append(v)
        yield key, indexes

相关文章

网友评论

      本文标题:Inverted index(Map Reduce)

      本文链接:https://www.haomeiwen.com/subject/qcmejxtx.html