summaryrefslogtreecommitdiff
path: root/spellchecker/src/SpellCorrector.java
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-01 02:38:45 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-01 02:38:45 +0200
commit61f7bd4f37dc85f49a1732af58f6bd42e556ad21 (patch)
tree8060faf497555fcf05a1f6ed5254c6002118c4cf /spellchecker/src/SpellCorrector.java
parentee910dfb30e804b1175074aa58d6c43cd9fb4c1c (diff)
downloadassignment4-61f7bd4f37dc85f49a1732af58f6bd42e556ad21.tar.gz
Replace Set by Map for later extension
Diffstat (limited to 'spellchecker/src/SpellCorrector.java')
-rw-r--r--spellchecker/src/SpellCorrector.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java
index 37020fb..6c9225b 100644
--- a/spellchecker/src/SpellCorrector.java
+++ b/spellchecker/src/SpellCorrector.java
@@ -1,5 +1,6 @@
-import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Map;
public class SpellCorrector {
@@ -40,10 +41,10 @@ public class SpellCorrector {
* substitution or transposition.
*
* @param word The (wrong) word to find (corrected) candidates for.
- * @return A set of words with candidate words.
+ * @return Candidate words mapping to the noisy channel model probability.
*/
- public HashSet<String> getCandidateWords(String word) {
- HashSet<String> ListOfWords = new HashSet<>();
+ public Map<String, Double> getCandidateWords(String word) {
+ Map<String, Double> candidates = new HashMap<>();
// tries to add word2 to the list of words. This word2 was generated
// from "word" by changing "error" to "correct".
@@ -52,7 +53,9 @@ public class SpellCorrector {
return;
}
- ListOfWords.add(word2);
+ double p = candidates.getOrDefault(word2, 0.0);
+
+ candidates.put(word2, p);
};
makeWordInsertion(word, push);
@@ -60,7 +63,7 @@ public class SpellCorrector {
makeWordDeletion(word, push);
makeWordTransposition(word, push);
- return ListOfWords;
+ return candidates;
}
private void makeWordInsertion(String word,