indexoutofboundsexception - Troubling shooting java.lang.ArrayIndexOutOfBoundsException -
hi friends i'm doing final year project semantic similarity between sentences. i'm using word-net 2.1 database retrieve meaning. each line have split no of words. in each word i'm meaning , storing array. can meaning of first sentences.
string[] sentences = result.split("[\\.\\!\\?]"); (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(" "); (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(); (synset synset : synsets) { word[] words = synset.getwords(); (word word : words) { synonyms.add(word.getlemma()); } } system.out.println(synonyms);
output: sentences[o]
(first sentence word's shoe meaning ...all other words not looping...) show error..
**java.lang.arrayindexoutofboundsexception: 0 @ first_jwnl.main(first_jwnl.java:102)**
when declare variable wcount1
, assign in value: sentences[i].split("\\s+")..
. , yet, when assign variable word1
, assigned sentences[i].split(" ")
.
is possible, because using 2 regular expressions, sec split (which beingness assigned word1
variable) not splitting correctly? , hence when access value (system.out.println(word1[j]);
), throwing arrayindexoutofboundsexception
. since value of wcount1
may bigger length of word1
.
java indexoutofboundsexception
No comments:
Post a Comment