summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-02 11:45:04 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-02 11:45:04 +0200
commit7b56b731f525087c25b0e479077edac3674d2274 (patch)
tree2df6d8d6a483a25946c1d00e2e36fcc08f86e06d
parent87b788adb8426d1ca0655ee049a68893bd54ca1b (diff)
downloadassignment4-7b56b731f525087c25b0e479077edac3674d2274.tar.gz
use max instead of sum
-rw-r--r--spellchecker/src/SpellCorrector.java7
1 files changed, 3 insertions, 4 deletions
diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java
index 475e889..e4086aa 100644
--- a/spellchecker/src/SpellCorrector.java
+++ b/spellchecker/src/SpellCorrector.java
@@ -86,11 +86,10 @@ public class SpellCorrector {
// add-one smoothing
p_channel = (correctionCount + 1) / (errorCount + 1);
- // TODO: take the max instead of addition?
- // Sum the probabilities as independent modifications can result in
- // the same word ("acess" -> "access" by "a|ac", "e|ce").
+ // while we could sum here, it does not make sense for the
+ // probability. Use the probability of the most likely change type.
double p = candidates.getOrDefault(word2, 0.0);
- p += p_channel;
+ p = Math.max(p, p_channel);
candidates.put(word2, p);
};