Как извлечь индекс строки в MrJob с помощью методов MapReduce? - PullRequest
0 голосов
/ 08 мая 2020

Как вы извлекаете индекс любой данной строки в MrJob?

index_words = ["before", "remove"]

class MRWordInvertedIndex(MRJob):

    # how to make the key(index) the line index of the corresponding value(line) in the input text file?
    def mapper(self, index, line):
        words = WORD_RE.findall(line.lower())

        for word in words:
            # obtain the line index where 'word' occurs
            if word in index_words:         
                yield word.lower(), index    # where index is the line number

Можно ли сделать ключевой (он же index) параметр сопоставителя фактическим индексом строки в соответствующем входном текстовом файле или получить индекс строки каким-либо другим способом?

Например, предположим, что входной текстовый файл:

# copyright laws for your country before downloading or redistributing 
# this or any other Project Gutenberg eBook. BLANK LINE BELOW.

# This header should be the first thing seen when viewing this Project 
# Gutenberg file.  Please do not remove it.

Тогда индекс строки для индексных слов before и remove будет:

"before": 1
"remove": 4

Поскольку before встречается в строке 1, а remove встречается в строке 4.

...