<s> from __future__ import absolute_import <EOL> from __future__ import division , print_function , unicode_literals <EOL> from operator import attrgetter <EOL> from itertools import chain <EOL> from . . _compat import ffilter <EOL> from . _summarizer import AbstractSummarizer <EOL> class EdmundsonTitleMethod ( AbstractSummarizer ) : <EOL> def __init__ ( self , stemmer , null_words ) : <EOL> super ( EdmundsonTitleMethod , self ) . __init__ ( stemmer ) <EOL> self . _null_words = null_words <EOL> def __call__ ( self , document , sentences_count ) : <EOL> sentences = document . sentences <EOL> significant_words = self . _compute_significant_words ( document ) <EOL> return self . _get_best_sentences ( sentences , sentences_count , <EOL> self . _rate_sentence , significant_words ) <EOL> def _compute_significant_words ( self , document ) : <EOL> heading_words = map ( attrgetter ( "<STR_LIT>" ) , document . headings ) <EOL> significant_words = chain ( * heading_words ) <EOL> significant_words = map ( self . stem_word , significant_words ) <EOL> significant_words = ffilter ( self . _is_null_word , significant_words ) <EOL> return frozenset ( significant_words ) <EOL> def _is_null_word ( self , word ) : <EOL> return word in self . _null_words <EOL> def _rate_sentence ( self , sentence , significant_words ) : <EOL> words = map ( self . stem_word , sentence . words ) <EOL> return sum ( w in significant_words for w in words ) <EOL> def rate_sentences ( self , document ) : <EOL> significant_words = self . _compute_significant_words ( document ) <EOL> rated_sentences = { } <EOL> for sentence in document . sentences : <EOL> rated_sentences [ sentence ] = self . _rate_sentence ( sentence , <EOL> significant_words ) <EOL> return rated_sentences </s>
