Storing each sentence in an array from a document in java? -


i want split every sentence document , store each sentence in different arrays. each array element word of sentences. cant far this.

int count =0,len=0; string sentence[]; string words[][]; sentence = name.split("\\."); count = sentence.length;  system.out.print("total sentence: " ); system.out.println(count); int h;   words = new string[count][];   (h = 0; h < count; h++) {      string tmp[] = sentence[h].split(" ");      words[h] = tmp;      len = len + words[h].length;      system.out.println("total words: " );      system.out.print(len);        temp = sentence[h].split(delimiter);         for(int = 0; < temp.length; i++) {         system.out.print(len);         system.out.println(temp[i]);         len++;      }   } 

i can't understand code, here's how achieve stated intention 3 lines:

string document; // read somewhere  list<list<string>> words = new arraylist<>(); (string sentence : document.split("[.?!]\\s*"))     words.add(arrays.aslist(sentence.split("[ ,;:]+"))); 

if want convert lists arrays, use list.asarray(), wouldn't recommend it. lists far easier deal arrays. one, expand automatically (one reason why above code dense).

addendum: (most) characters don't need escaping inside character class.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -