summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-04-02 01:41:15 +0200
committerPeter Wu <peter@lekensteyn.nl>2015-04-02 01:41:15 +0200
commitf24d257cc729199f6513a34f93545569c6f6589c (patch)
treee7d7bfdfbd103d92f186ee73e6278758cb3ed039
parent0df42fd89fb0005c153ec425d1bc6948f1079889 (diff)
downloadassignment4-f24d257cc729199f6513a34f93545569c6f6589c.tar.gz
Support continuously processing stdin
-rwxr-xr-xspellchecker/run.sh4
-rw-r--r--spellchecker/src/SpellChecker.java17
2 files changed, 20 insertions, 1 deletions
diff --git a/spellchecker/run.sh b/spellchecker/run.sh
new file mode 100755
index 0000000..14c7057
--- /dev/null
+++ b/spellchecker/run.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+ant -q -S compile &&
+NO_PEACH=1 \
+java -ea -cp build/classes SpellChecker
diff --git a/spellchecker/src/SpellChecker.java b/spellchecker/src/SpellChecker.java
index 6550678..055326e 100644
--- a/spellchecker/src/SpellChecker.java
+++ b/spellchecker/src/SpellChecker.java
@@ -9,6 +9,9 @@ public class SpellChecker {
*/
public static void main(String[] args) {
boolean inPeach = true; // set this to true if you submit to peach!!!
+ if (System.getenv("NO_PEACH") != null) {
+ inPeach = false;
+ }
try {
CorpusReader cr = new CorpusReader();
@@ -17,7 +20,8 @@ public class SpellChecker {
if (inPeach) {
peachTest(sc);
} else {
- nonPeachTest(sc);
+ continuousTest(sc);
+ //nonPeachTest(sc);
}
} catch (Exception ex) {
System.out.println(ex);
@@ -25,6 +29,17 @@ public class SpellChecker {
}
}
+ static void continuousTest(SpellCorrector sc) {
+ Scanner input = new Scanner(System.in);
+ while (input.hasNextLine()) {
+ String s0 = input.nextLine();
+ System.out.println("Input : " + s0);
+ String result = sc.correctPhrase(s0);
+ System.out.println("Answer: " + result);
+ System.out.println();
+ }
+ }
+
static void nonPeachTest(SpellCorrector sc) throws IOException {
String[] sentences = {
"at the hme locations there were traces of water"