diff options
Diffstat (limited to 'InvertedIndex.java')
-rw-r--r-- | InvertedIndex.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/InvertedIndex.java b/InvertedIndex.java index bc75ba6..b2e1fd0 100644 --- a/InvertedIndex.java +++ b/InvertedIndex.java @@ -1,3 +1,4 @@ +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -12,12 +13,15 @@ public class InvertedIndex { inputs.add(new Document(filename, FileParser.parse(filename))); } // TODO: instantiate a MapReduce object with correct input, key, value, and output types + MapReduce<Document, String, String, List<String>> 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 - - throw new UnsupportedOperationException("InvertedIndex.run() not implemented yet."); + return mapReduce.call(); } class Document { @@ -38,7 +42,11 @@ public class InvertedIndex { @Override public Map<String, String> compute() { // TODO: implement the Map function for inverted index - throw new UnsupportedOperationException("InvertedIndex map function not implemented yet."); + Map<String, String> map = new HashMap<>(); + for (String word : input.words) { + map.put(word, input.name); + } + return map; } } @@ -49,7 +57,9 @@ public class InvertedIndex { @Override public List<String> compute() { // TODO: implement the Reduce function for inverted index - throw new UnsupportedOperationException("InvertedIndex reduce function not implemented yet."); + List<String> list = new LinkedList<>(); + list.addAll(valueList); + return list; } } |