summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-04 13:09:26 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-04 13:09:26 +0200
commit59d3cd598e0c54464005f7ff19ad9a32ea936117 (patch)
tree376e7c4a419c603dffa91c88181f078a4171fb4e
parentc6b64fa4c9b363379cbdc470cad782412e2db398 (diff)
downloadassignment4-59d3cd598e0c54464005f7ff19ad9a32ea936117.tar.gz
Debugging tweaks, be less verbose unless requested
-rwxr-xr-xspellchecker/run.sh4
-rw-r--r--spellchecker/src/CorpusReader.java2
-rw-r--r--spellchecker/src/SpellCorrector.java28
3 files changed, 24 insertions, 10 deletions
diff --git a/spellchecker/run.sh b/spellchecker/run.sh
index 956ce67..e2df2d4 100755
--- a/spellchecker/run.sh
+++ b/spellchecker/run.sh
@@ -2,6 +2,10 @@
classpath="${CLASSPATH:+$CLASSPATH:}"
classpath+=build/classes
+# Possible env vars:
+#DEBUG_SCORE=1 # Enable debugging of the score
+#NO_PEACH=1 # Print less debug information, use peach I/O formats
+
ant -q -S compile >&2 &&
NO_PEACH=1 \
java -ea -cp "$classpath" SpellChecker
diff --git a/spellchecker/src/CorpusReader.java b/spellchecker/src/CorpusReader.java
index 2e0a855..371c916 100644
--- a/spellchecker/src/CorpusReader.java
+++ b/spellchecker/src/CorpusReader.java
@@ -159,6 +159,8 @@ public class CorpusReader {
p = (a + .001) / (b + 1);
}
+ //System.err.println("P(" + word + "|" + ngram + ") = " + p);
+
return p;
}
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;
}
}