summaryrefslogtreecommitdiff
path: root/spellchecker
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-04 14:51:37 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-04 14:51:37 +0200
commitbf3521be529d87331652547bcd207f3abd59cd0e (patch)
treea6b37039e7e4166d909c56345cd5fbb961aa82d6 /spellchecker
parent5d632ace5d41f83cc268420ee8779d9fb4eb8e17 (diff)
downloadassignment4-bf3521be529d87331652547bcd207f3abd59cd0e.tar.gz
Fix bugs when looking for more than one typo
I thought that arraycopy had memcpy semantics, but oh gawd I was wrong. The other bug is that the best result could be overwritten by a worse one since the wrong result was checked.
Diffstat (limited to 'spellchecker')
-rw-r--r--spellchecker/src/SpellCorrector.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java
index 4bc3fe8..f3e504d 100644
--- a/spellchecker/src/SpellCorrector.java
+++ b/spellchecker/src/SpellCorrector.java
@@ -117,7 +117,11 @@ public class SpellCorrector {
// if a better word was found, use the change
if (rater.hasBetterSuggestion()) {
rater.saveSuggestion();
- bestResult = rater;
+ if (bestResult == null || rater.getBestScore() > bestResult.getBestScore()) {
+ // apparently this is not just the best result of this
+ // round, but the overall result! Save it.
+ bestResult = rater;
+ }
// If some other errors are still possible, hunt for those!
modifiedIndices.add(i);
@@ -127,7 +131,7 @@ public class SpellCorrector {
// Did it find a corrected word?
if (subResult != null) {
// Yes it did. Is this the best one so far?
- if (subResult.getBestScore() > rater.getBestScore()) {
+ if (subResult.getBestScore() > bestResult.getBestScore()) {
debugPrint("Subresult is better!");
bestResult = subResult;
} else {
@@ -522,7 +526,7 @@ public class SpellCorrector {
// save the word and the affected scores
words[index] = word;
- System.arraycopy(word_likelihoods, 0, scores, 0, words.length);
+ System.arraycopy(scores, 0, word_likelihoods, 0, words.length);
sentence_probability = best_modification.probability;
if (DEBUG_SCORE) {