summaryrefslogtreecommitdiff
path: root/spellchecker/src/SpellChecker.java
blob: 6550678302e0e617a7c6ab8aa603695d1955ed89 (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

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!!!

        try {
            CorpusReader cr = new CorpusReader();
            ConfusionMatrixReader cmr = new ConfusionMatrixReader();
            SpellCorrector sc = new SpellCorrector(cr, cmr);
            if (inPeach) {
                peachTest(sc);
            } else {
                nonPeachTest(sc);
            }
        } catch (Exception ex) {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }

    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));
    }
}