I am loading a file that holds nearly 80,000 words. It will be used as the primary spell checking dictionary. The sequence of the words has been randomized. There is another file which i am loading that has the misspelled words i have to check. Also it provides suggestions to misspelled words.
public void spellCheckDocument(ArrayList<String> dictionary){
long startCheck = System.currentTimeMillis();
for(String words: collectionOfParagraphs)
for(String word: words.split("[^a-zA-Z_0-9']+")){
int index = Collections.binarySearch(dictionary, word.toLowerCase());
if(index<0 && word.length()>0){
//collectionOfMisspelledWord.add(word+" Possible correct word: "+dictionary.get(-index+1)+" "+dictionary.get(-index)+" "+dictionary.get(-index-1));
//System.out.printf("%s Misspelled, possible correct words: %s, %s, %s\n", word, dictionary.get(-index+1),dictionary.get(-index),dictionary.get(-index-1));
possibleCorrectSpellings = new Document(word, dictionary.get(-index+1),dictionary.get(-index), dictionary.get(-index-1));
collectionOfMisspelledWord.add(possibleCorrectSpellings);
}
}
--------error----------
java.lang.IndexOutOfBoundsException: Index: 380, Size: 379
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at file.Document.spellCheckDocument(Document.java:82)