aboutsummaryrefslogtreecommitdiff
path: root/InvertedIndex.java
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-12-10 14:46:20 -0500
committersotech117 <michael_foiani@brown.edu>2023-12-10 14:46:20 -0500
commite1f0edd5c3fb32ce1fd5436b9653a7ebdcc14edf (patch)
treedfa869e0edc65bad73c842ee0e264053d39b266d /InvertedIndex.java
parentcb491e82b5ce3dcb7e3c41973a46cb7dcbaa9008 (diff)
1st iteration
Diffstat (limited to 'InvertedIndex.java')
-rw-r--r--InvertedIndex.java18
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;
}
}