<filename>Assignment3/inverted_index.py
import MapReduce
import sys

"""
Inverted Index in the Simple Python MapReduce Framework
"""

mr = MapReduce.MapReduce()

# =============================
# Do not modify above this line

def mapper(record):
    # key: document identifier
    # value: document contents
    key = record[0]
    value = record[1]
    words = value.split()
    for w in words:
      mr.emit_intermediate(w, key) #output file name

def reducer(key, list_of_values):
    # key: word
    # value: list of occurring file names
    unique_list = list(set(list_of_values))
    mr.emit((key, unique_list))

# Do not modify below this line
# =============================
if __name__ == '__main__':
  inputdata = open(sys.argv[1])
  mr.execute(inputdata, mapper, reducer)

<filename>Assignment3/inverted_index.py
import MapReduce
import sys

"""
Inverted Index in the Simple Python MapReduce Framework
"""

mr = MapReduce.MapReduce()

# =============================
# Do not modify above this line

def mapper(record):
    # key: document identifier
    # value: document contents
    key = record[0]
    value = record[1]
    words = value.split()
    for w in words:
      mr.emit_intermediate(w, key) #output file name

def reducer(key, list_of_values):
    # key: word
    # value: list of occurring file names
    unique_list = list(set(list_of_values))
    mr.emit((key, unique_list))

# Do not modify below this line
# =============================
if __name__ == '__main__':
  inputdata = open(sys.argv[1])
  mr.execute(inputdata, mapper, reducer)

Inverted Index in the Simple Python MapReduce Framework # ============================= # Do not modify above this line # key: document identifier # value: document contents #output file name # key: word # value: list of occurring file names # Do not modify below this line # =============================