import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import mapreduce.MapReduce; public class InvertedIndex { public Map> run(List filenames) { List inputs = new LinkedList<>(); for (String filename : filenames) { inputs.add(new Document(filename, FileParser.parse(filename))); } // TODO: instantiate a MapReduce object with correct input, key, value, and output types MapReduce> mapReduce = new MapReduce<>(); // TODO: set the mapper and reducer suppliers, and set the inputs mapReduce.setMapperSupplier(Mapper::new); mapReduce.setReducerSupplier(Reducer::new); mapReduce.setInput(inputs); // TODO: execute the MapReduce object and return the result return mapReduce.call(); } class Document { String name; List words; public Document(String name, List words) { this.name = name; this.words = words; } } class Mapper extends mapreduce.Mapper { @Override public Map compute() { // TODO: implement the Map function for inverted index Map map = new HashMap<>(); for (String word : input.words) { map.put(word, input.name); } return map; } } class Reducer extends mapreduce.Reducer> { @Override public List compute() { // TODO: implement the Reduce function for inverted index List list = new LinkedList<>(); list.addAll(valueList); return list; } } }