blob: c8451bf920c117a9fa7a8f4a13cac98cd22293c6 (
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
|
import java.util.HashSet;
public class SpellCorrector {
final private CorpusReader cr;
final private ConfusionMatrixReader cmr;
final char[] ALPHABET = "abcdefghijklmnopqrstuvwxyz'".toCharArray();
public SpellCorrector(CorpusReader cr, ConfusionMatrixReader cmr) {
this.cr = cr;
this.cmr = cmr;
}
public String correctPhrase(String phrase) {
if (phrase == null || phrase.length() == 0) {
throw new IllegalArgumentException("phrase must be non-empty.");
}
String[] words = phrase.split(" ");
String finalSuggestion = "";
/**
* CODE TO BE ADDED *
*/
return finalSuggestion.trim();
}
public double calculateChannelModelProbability(String suggested, String incorrect) {
/**
* CODE TO BE ADDED *
*/
return 0.0;
}
public HashSet<String> getCandidateWords(String word) {
HashSet<String> ListOfWords = new HashSet<String>();
/**
* CODE TO BE ADDED *
*/
return cr.inVocabulary(ListOfWords);
}
}
|