public class Mapper { public void map(String key, String value) { String words[] = key.split(" "); for (int i = 0; i < words.length; i++) { Wmr.emit(words[i], "1"); } } }
public class Reducer { public void reduce(String key, WmrIterator values) { int sum = 0; for (String value : values) { sum += Integer.parseInt(value); } Wmr.emit(key, Integer.valueOf(sum).toString()); } }