summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-02 11:03:43 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-02 11:03:43 +0200
commite87e52faadaded64e687108600055b6bad83f1e4 (patch)
treef6dac0cd691f64d7ed68e9d8a9dc4b95da6cc1e5
parentc2965ed04707ac744058957f7cbd34a9da19a392 (diff)
downloadassignment4-e87e52faadaded64e687108600055b6bad83f1e4.tar.gz
Improved score debugging
-rw-r--r--spellchecker/src/SpellCorrector.java27
1 files changed, 27 insertions, 0 deletions
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) {