diff options
author | Peter Wu <peter@lekensteyn.nl> | 2015-04-02 01:41:15 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2015-04-02 01:41:15 +0200 |
commit | f24d257cc729199f6513a34f93545569c6f6589c (patch) | |
tree | e7d7bfdfbd103d92f186ee73e6278758cb3ed039 | |
parent | 0df42fd89fb0005c153ec425d1bc6948f1079889 (diff) | |
download | assignment4-f24d257cc729199f6513a34f93545569c6f6589c.tar.gz |
Support continuously processing stdin
-rwxr-xr-x | spellchecker/run.sh | 4 | ||||
-rw-r--r-- | spellchecker/src/SpellChecker.java | 17 |
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" |