From a6fbffe08e9217c16ef2afa0d69e8a7c527d5f8d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 4 Apr 2015 11:05:12 +0200 Subject: Changes must always be better than the latest modification --- spellchecker/src/SpellCorrector.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java index 2e03f26..e3f2955 100644 --- a/spellchecker/src/SpellCorrector.java +++ b/spellchecker/src/SpellCorrector.java @@ -388,9 +388,11 @@ public class SpellCorrector { // group the effects of this modifications for tracking. WordModification effect = new WordModification(index, word, scores); - if ((best_modification != null - && effect.probability > best_modification.probability) - || effect.probability > sentence_probability) { + // if there was a previous best modification, the proposed + // modification must be better than that. Otherwise, it must be + // better than the original sentence. + if ((best_modification != null && effect.probability > best_modification.probability) + || (best_modification == null && effect.probability > sentence_probability)) { best_modification = effect; } } -- cgit v1.2.1