1

こんにちは友人私は文の間の意味的類似性のために私の最終年のプロジェクトをやっています。だから私はword-net2.1データベースを使って意味を検索しています。各行は単語を分割する必要はありません。各単語で意味がわかり、配列に格納されます。しかし、それは最初の文の意味しか得ることができません。

 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)**
4

1 に答える 1

0

変数を宣言するときwcount1は、値を代入します: sentences[i].split("\\s+")..。それでも、変数を割り当てると、word1が割り当てられsentences[i].split(" ")ます。

2 つの正規表現を使用しているため、2 番目の分割 (変数に割り当てられているword1) が正しく分割されていない可能性はありますか? したがって、値 ( System.out.println(word1[j]);) にアクセスすると、 がスローされArrayIndexOutOfBoundsExceptionます。の値はwcount1の長さよりも大きい場合があるためですword1

于 2013-02-13T06:44:03.077 に答える