S Gaber S Gaber - 1 year ago 80
Java Question

How can I split a text into sentences using the Stanford parser?

How can I split a text or paragraph into sentences using Stanford parser?

Is there any method that can extract sentences, such as

as it's provided for Ruby?

Answer Source

You can check the DocumentPreprocessor class. Below is a short snippet. I think there may be other ways to do what you want.

String paragraph = "My 1st sentence. “Does it work for questions?” My third sentence.";
Reader reader = new StringReader(paragraph);
DocumentPreprocessor dp = new DocumentPreprocessor(reader);
List<String> sentenceList = new ArrayList<String>();

for (List<HasWord> sentence : dp) {
   String sentenceString = Sentence.listToString(sentence);

for (String sentence : sentenceList) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download