def map(self, key, value): """ map a name to the name before and after it @param key: the first character of a name @param value: all the names start with the key """ namelist = value.strip().split() namelist.insert(0, '') namelist.append('') n = len(namelist) for i in range(1, n - 1): self.outputcollector.collect(namelist[i], \ tuple2str((namelist[i-1] ,namelist[i+1])))
def reduce(self, key, values): """ aggregate the values having the same key. """ values_str = tuple2str(tuple(values)) self.outputcollector.collect(key, values_str)