#NEWLINE# def summarize( text , sentence_count = 5 , language = 'english' ) : #NEWLINE# #INDENT# processor = LanguageProcessor ( language ) #NEWLINE# sentence_list = processor . split_sentences ( text ) #NEWLINE# wordset_list = map ( processor . extract_significant_words , sentence_list ) #NEWLINE# stemsets = [ { processor . stem ( word ) for word in wordset } for wordset in wordset_list ] #NEWLINE# graph = Graph ( ) #NEWLINE# pairs = combinations ( enumerate ( stemsets ) , 2 ) #NEWLINE# for ( ( index_a , stems_a ) , ( index_b , stems_b ) ) in pairs : #NEWLINE# #INDENT# if ( stems_a and stems_b ) : #NEWLINE# #INDENT# similarity = ( 1 - jaccard ( stems_a , stems_b ) ) #NEWLINE# if ( similarity > 0 ) : #NEWLINE# #INDENT# graph . add_edge ( index_a , index_b , weight = similarity ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ranked_sentence_indexes = list ( pagerank ( graph ) . items ( ) ) #NEWLINE# if ranked_sentence_indexes : #NEWLINE# #INDENT# sentences_by_rank = sorted ( ranked_sentence_indexes , key = itemgetter ( 1 ) , reverse = True ) #NEWLINE# best_sentences = map ( itemgetter ( 0 ) , index_a [ : sentence_count ] ) #NEWLINE# best_sentences_in_order = sorted ( best_sentences ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# best_sentences_in_order = range ( min ( sentence_count , len ( sentence_list ) ) ) #NEWLINE# #UNINDENT# return ' ' . join ( ( sentence_list [ index ] for index in best_sentences_in_order ) )