2014-10-28 6 views
-1

거의 80,000 단어를 포함하는 파일을로드하고 있습니다. 기본 맞춤법 검사 사전으로 사용됩니다. 단어의 순서가 무작위로 지정되었습니다. 확인해야 할 철자가 틀린 단어가있는 다른 파일이 있습니다. 또한 맞춤법이 틀린 단어에 대한 제안을 제공합니다. Collections.binarySearch()의 문서에서사용자 지정 맞춤법 검사 오류 생성

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) 
+0

82 줄은 어느 것입니까? –

+0

ssibleCorrectSpellings = new 문서 (word, dictionary.get (-index + 1), dictionary.get (-index), dictionary.get (-index-1)); – V15720002000

답변

0

:

그렇지 않으면 (-(insertion point) - 1). 삽입 점은 키가 목록에 삽입되는 지점, 즉 키보다 큰 첫 번째 요소의 색인 또는 목록의 모든 요소가 지정된 키보다 작은 경우 list.size()로 정의됩니다. .

즉, 색인의 마지막 요소를 지나치는 색인을 얻는 경우가 있습니다. 이 경우 특수 처리를 추가해야합니다. 이는 어떤 단어가 올바른지 알 수 없음을 의미합니다.