难以拍摄java.lang.ArrayIndexOutOfBoundsException
嗨,朋友们,我正在做句子间语义相似性的最后一年项目。 所以我使用word NET2.1数据库来检索其含义。每一行我都要分词。在每一个单词中,我都得到了意义并存储到数组中。但它只能得到第一句话的意思难以拍摄java.lang.ArrayIndexOutOfBoundsException,java,indexoutofboundsexception,Java,Indexoutofboundsexception,嗨,朋友们,我正在做句子间语义相似性的最后一年项目。 所以我使用word NET2.1数据库来检索其含义。每一行我都要分词。在每一个单词中,我都得到了意义并存储到数组中。但它只能得到第一句话的意思 String[] sentences = result.split("[\\.\\!\\?]"); for (int i=0;i<sentences.length;i++) { System.out.println(i);
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);
声明变量
wcount1
时,在值中赋值:语句[i]。拆分(\\s+)..
。然而,当您分配变量word1
时,它会被分配语句[i].split(“”
)
由于您使用的是两个正则表达式,第二次拆分(分配给
word1
变量)是否可能无法正确拆分?因此,当您访问值(System.out.println(word1[j]);
)时,它会抛出ArrayIndexOutOfBoundsException
。由于wcount1
的值可能大于word1
的长度,因此您的问题似乎不完整。你能修改一下吗?还有,你在哪一行得到错误?
**java.lang.ArrayIndexOutOfBoundsException: 0
at first_JWNL.main(first_JWNL.java:102)**