From e87e52faadaded64e687108600055b6bad83f1e4 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 2 Apr 2015 11:03:43 +0200 Subject: Improved score debugging --- spellchecker/src/SpellCorrector.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java index 4ba1c7e..65865b9 100644 --- a/spellchecker/src/SpellCorrector.java +++ b/spellchecker/src/SpellCorrector.java @@ -306,6 +306,20 @@ public class SpellCorrector { return best_modification != null; } + private void debugScore(int index, String old_word, double old_score, + double old_evaluation) { + System.err.println(); + System.err.println("Word: " + old_word + " -> " + words[index]); + System.err.println("Word score : " + old_score + + " -> " + word_likelihoods[index]); + System.err.println("Phrase evaluation: " + old_evaluation + + " -> " + evaluateWord(-1)); + for (int i = 0; i < words.length; i++) { + System.err.println(String.format("%28s %s", words[i], word_likelihoods[i])); + } + System.err.println(); + } + /** * Save the best suggestion so far, ensuring that future suggestions * won't overwrite this one. @@ -314,6 +328,15 @@ public class SpellCorrector { int index = best_modification.index; String word = best_modification.word; double score = best_modification.score; + // for debugging + String old_word = words[index]; + double old_score = word_likelihoods[index]; + double old_evaluation = 0; + + if (DEBUG_SCORE) { + // possibly expensive, only calculate it for debug + old_evaluation = evaluateWord(-1); + } if (DEBUG_SCORE) { System.err.println(); @@ -333,6 +356,10 @@ public class SpellCorrector { words[index] = word; word_likelihoods[index] = score; + if (DEBUG_SCORE) { + debugScore(index, old_word, old_score, old_evaluation); + } + // if this was the best word, do not change it now. The context // should also not change. if (index > 0) { -- cgit v1.2.1