blob: 55f8f6b456bfa9291e42f11527823910b60f81e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import java.io.IOException;
import java.util.Scanner;
public class SpellChecker {
/**
* @param args the command line arguments
*/
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();
ConfusionMatrixReader cmr = new ConfusionMatrixReader();
SpellCorrector sc = new SpellCorrector(cr, cmr);
if (inPeach) {
peachTest(sc);
} else {
continuousTest(sc);
//nonPeachTest(sc);
}
} catch (Exception ex) {
System.out.println(ex);
ex.printStackTrace();
}
}
static void continuousTest(SpellCorrector sc) {
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
String s0 = input.nextLine();
String result = sc.correctPhrase(s0);
if (System.getenv("ANSWER_ONLY") == null) {
System.out.println("Input : " + s0);
System.out.println("Answer: " + result);
System.out.println();
} else {
System.out.println(s0);
}
}
}
static void nonPeachTest(SpellCorrector sc) throws IOException {
String[] sentences = {
"at the hme locations there were traces of water"
};
for (String s0 : sentences) {
System.out.println("Input : " + s0);
String result = sc.correctPhrase(s0);
System.out.println("Answer: " + result);
System.out.println();
}
}
static void peachTest(SpellCorrector sc) throws IOException {
Scanner input = new Scanner(System.in);
String sentence = input.nextLine();
System.out.println("Answer: " + sc.correctPhrase(sentence));
}
}
|