private String [ ] segment ( final String builtText ) { // these are fine because they do not affect offsets String line = builtText . trim ( ) ; line = RuleBasedTokenizer . doubleSpaces . matcher ( line ) . replaceAll ( " " ) ; if ( this . isHardParagraph ) { // convert every (spurious) paragraph in newlines and keep them line = paragraph . matcher ( line ) . replaceAll ( "\n$1" ) ; } else { // end of sentence markers, paragraph mark and beginning of link line = endPunctLinkPara . matcher ( line ) . replaceAll ( "$1\n$2$3" ) ; line = conventionalPara . matcher ( line ) . replaceAll ( "$1\n$2$3" ) ; line = endInsideQuotesPara . matcher ( line ) . replaceAll ( "$1\n$3$4" ) ; line = multiDotsParaStarters . matcher ( line ) . replaceAll ( "$1\n$2$3" ) ; // remove spurious paragraphs line = alphaNumParaLowerNum . matcher ( line ) . replaceAll ( "$1 $3" ) ; line = spuriousParagraph . matcher ( line ) . replaceAll ( " $2" ) ; } // non-period end of sentence markers (?!) followed by sentence starters. line = noPeriodSpaceEnd . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // multi-dots followed by sentence starters line = multiDotsSpaceStarters . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // end of sentence inside quotes or brackets line = endInsideQuotesSpace . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // end of sentence marker, sentence starter punctuation and upper case. line = punctSpaceUpper . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // end of sentence markers, maybe space or paragraph mark and beginning of // link line = endPunctLinkSpace . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // special case of multi-punctuation line = punctSpaceMultiPunct . matcher ( line ) . replaceAll ( "$1\n$2" ) ; // non breaker segments everything else with some exceptions final String [ ] lines = line . split ( "\n" ) ; final String [ ] sentences = this . nonBreaker . segmenterExceptions ( lines ) ; return sentences ; }
Segments sentences and calls the NonPeriodBreaker for exceptions .