public static List < String > splitSentence2 ( String text , SentenceDetector sd ) { List < String > sentences = new ArrayList < String > ( ) ; try { int sentenceOffsets [ ] = sd . sentPosDetect ( text ) ; int begin = 0 ; int end = 0 ; for ( int i = 0 ; i < sentenceOffsets . length ; i ++ ) { end = begin + ( text . substring ( begin , sentenceOffsets [ i ] ) . trim ( ) ) . length ( ) ; sentences . add ( text . substring ( begin , end ) ) ; begin = sentenceOffsets [ i ] ; } } catch ( Exception e ) { LOG . warn ( "failed to extract sentences from text '" + text + "'" , e ) ; } return sentences ; }
Conv . method to use the SentenceDetector directly ; create it with the method below