summaryrefslogtreecommitdiff
path: root/spellchecker/src/SpellCorrector.java
diff options
context:
space:
mode:
Diffstat (limited to 'spellchecker/src/SpellCorrector.java')
-rw-r--r--spellchecker/src/SpellCorrector.java28
1 files changed, 18 insertions, 10 deletions
diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java
index fbbfbef..a015ac2 100644
--- a/spellchecker/src/SpellCorrector.java
+++ b/spellchecker/src/SpellCorrector.java
@@ -33,6 +33,13 @@ public class SpellCorrector {
this.cmr = cmr;
}
+ private void debugPrint(String str) {
+ // print debugging information if NO_PEACH is set.
+ if (System.getenv("NO_PEACH") != null) {
+ System.err.println(str);
+ }
+ }
+
/**
* Converts a set of word indices which were modified to an array of length
* {@code n} of which elements are set to true when those should not be
@@ -70,6 +77,7 @@ public class SpellCorrector {
// try to find a better suggestion for this word.
Map<String, Double> candidates = getCandidateWords(old_word);
+ debugPrint("\n\n LOOKING AT " + i + " " + old_word);
candidates.forEach((word, channel_probability) -> {
rater.tryWord(word_index, word, channel_probability);
});
@@ -88,19 +96,19 @@ public class SpellCorrector {
if (subResult != null) {
// Yes it did. Is this the best one so far?
if (subResult.getBestScore() > rater.getBestScore()) {
- System.err.println("Subresult is better!");
+ debugPrint("Subresult is better!");
bestResult = subResult;
} else {
- System.err.println("Subresult is not better!");
+ debugPrint("Subresult is not better!");
}
} else {
- System.err.println("no subresult found");
+ debugPrint("no subresult found");
}
}
// make the context to be editable again
modifiedIndices.remove(i);
} else {
- System.err.println("No suggestion found for " + old_word + ".");
+ debugPrint("No suggestion found for " + old_word + ".");
}
}
return bestResult;
@@ -272,7 +280,9 @@ public class SpellCorrector {
LM_PROBABILITY_UNMODIFIED);
}
sentence_probability = combineProbabilities(word_likelihoods);
- debugScore();
+ if (DEBUG_SCORE) {
+ debugScore();
+ }
}
/**
@@ -306,10 +316,7 @@ public class SpellCorrector {
assert channel_probability > 0.0;
String debug_word = null;
- if (DEBUG_SCORE
- && (word.equals("he")
- || word.equals("hme")
- || word.equals("home"))) {
+ if (DEBUG_SCORE) {
debug_word = "";
}
@@ -351,7 +358,7 @@ public class SpellCorrector {
p = prior * channel_probability;
if (debug_word != null) {
- System.err.println("# " + word + " p=" + p
+ debugPrint("# " + word + " p=" + p
+ " chan=" + channel_probability
+ " prior=" + prior + debug_word);
}
@@ -413,6 +420,7 @@ public class SpellCorrector {
// better than the original sentence.
if ((best_modification != null && effect.probability > best_modification.probability)
|| (best_modification == null && effect.probability > sentence_probability)) {
+ debugPrint("Found better word! " + word + " p=" + effect.probability);
best_modification = effect;
}
}