From f24d257cc729199f6513a34f93545569c6f6589c Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 2 Apr 2015 01:41:15 +0200 Subject: Support continuously processing stdin --- spellchecker/run.sh | 4 ++++ spellchecker/src/SpellChecker.java | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 spellchecker/run.sh 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" -- cgit v1.2.1