2013-02-13 6 views
1

안녕하세요, 저는 문장 사이의 의미 상 유사성에 대한 마지막 해의 프로젝트를하고 있습니다. 그래서 나는 의미를 검색하기 위해 word-net 2.1 데이터베이스를 사용하고 있습니다. 각 줄마다 단어를 나눌 필요가 없습니다. 각 단어에서 나는 의미를 얻고 배열에 저장합니다. 그러나 그것은 첫 번째 문장의 의미만을 얻을 수 있습니다.처리 문제 해결 java.lang.ArrayIndexOutOfBoundsException

String[] sentences = result.split("[\\.\\!\\?]"); 
for (int i=0;i<sentences.length;i++) 
      { 
       System.out.println(i); 
       System.out.println(sentences[i]); 
       int wcount1 = sentences[i].split("\\s+").length; 
       System.out.println(wcount1);int wcount1=wordCount(w2); 
      System.out.println(wcount1); 
     String[] word1 = sentences[i].split(" "); 
     for (int j=0;j<wcount1;j++){ 
      System.out.println(j); 

     System.out.println(word1[j]); 
    } 
      } 

     IndexWordSet set = wordnet.lookupAllIndexWords(word1[j]); 
     System.out.println(set); 
     IndexWord[] ws = set.getIndexWordArray(); 

     **POS p = ws[0].getPOS();///line no 103** 

     Set<String> synonyms = new HashSet<String>(); 
     IndexWord indexWord = wordnet.lookupIndexWord(p, word1[j]); 
     Synset[] synSets = indexWord.getSenses(); 
     for (Synset synset : synSets) 
     { 
      Word[] words = synset.getWords(); 

      for (Word word : words) 
      { 
       synonyms.add(word.getLemma()); 
      } 
     } 
     System.out.println(synonyms); 

출력 : 에만 sentences[o] (첫 문장의 단어 유일의 신발 의미 ... 다른 모든 단어가 반복되지 않습니다 ...) 는이 오류를 보여 ..

**java.lang.ArrayIndexOutOfBoundsException: 0 
at first_JWNL.main(first_JWNL.java:102)** 
+1

질문이 불완전한 것 같습니다. 너는 개정 할 수 있니? 또한, 어떤 라인에서 오류가 발생합니까? – kufudo

답변

0

변수 wcount1을 선언하면 sentences[i].split("\\s+").. 값을 할당합니다. 그리고 변수 word1을 할당하면 sentences[i].split(" ")이 할당됩니다.

두 개의 정규 표현식을 사용하고 있기 때문에 두 번째 분할 (word1 변수에 할당 됨)이 올바르게 분할되지 않을 수 있습니까? 따라서 값 (System.out.println(word1[j]);)에 액세스하면 ArrayIndexOutOfBoundsException가 발생합니다. wcount1의 값은 word1보다 클 수 있습니다.