From e1f0edd5c3fb32ce1fd5436b9653a7ebdcc14edf Mon Sep 17 00:00:00 2001 From: sotech117 Date: Sun, 10 Dec 2023 14:46:20 -0500 Subject: 1st iteration --- InvertedIndex.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'InvertedIndex.java') 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> 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 compute() { // TODO: implement the Map function for inverted index - throw new UnsupportedOperationException("InvertedIndex map function not implemented yet."); + Map 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 compute() { // TODO: implement the Reduce function for inverted index - throw new UnsupportedOperationException("InvertedIndex reduce function not implemented yet."); + List list = new LinkedList<>(); + list.addAll(valueList); + return list; } } -- cgit v1.2.3-70-g09d2