From 7b56b731f525087c25b0e479077edac3674d2274 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 2 Apr 2015 11:45:04 +0200 Subject: use max instead of sum --- spellchecker/src/SpellCorrector.java | 7 +++---- 1 file 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); }; -- cgit v1.2.1