#NEWLINE# def demo( text , tok_cls = PunktSentenceTokenizer , train_cls = PunktTrainer ) : #NEWLINE# #INDENT# 'Builds a punkt model and applies it to the same text' #NEWLINE# cleanup = ( lambda s : re . compile ( '(?:\\r|^\\s+)' , re . MULTILINE ) . sub ( '' , s ) . replace ( '\n' , ' ' ) ) #NEWLINE# trainer = train_cls ( ) #NEWLINE# trainer . INCLUDE_ALL_COLLOCS = True #NEWLINE# trainer . train ( text ) #NEWLINE# sbd = tok_cls ( trainer . get_params ( ) ) #NEWLINE# for l in sbd . sentences_from_text ( trainer ) : #NEWLINE# #INDENT# print ( cleanup ( l ) )