1. Christos Kannas
  2. DocIRHadoop


DocIRHadoop / InvertedIndex / mapperReadIndex.py

#!/usr/bin/env python

import os
import sys
from itertools import groupby
from operator import itemgetter

def read_input(file, separator='\t'):
    for line in file:
        # read a line and split it to key and values
        yield line.rstrip().split(separator, 1)
def main(separator='\t'):
    test_terms = ["sherlock", "greece", "queen"]
    # input comes from STDIN (standard input)
    data = read_input(sys.stdin, separator=separator)
    for current_word, group in groupby(data, itemgetter(0)):
        if current_word in test_terms:
            for current_word, file_list in group:
                print "%s%s%s" % (current_word, separator, file_list)

if __name__ == "__main__":