<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> from math import sqrt <EOL> from textacy import data <EOL> def readability_stats ( doc ) : <EOL> """<STR_LIT>""" <EOL> if doc . lang != '<STR_LIT>' : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> n_sents = doc . n_sents <EOL> words = list ( doc . words ( filter_punct = True , filter_stops = False , filter_nums = False ) ) <EOL> n_words = len ( words ) <EOL> n_unique_words = len ( { word . lower for word in words } ) <EOL> n_chars = sum ( len ( word ) for word in words ) <EOL> hyphenator = data . load_hyphenator ( lang = '<STR_LIT>' ) <EOL> syllables_per_word = [ len ( hyphenator . positions ( word . lower_ ) ) + <NUM_LIT:1> for word in words ] <EOL> n_syllables = sum ( syllables_per_word ) <EOL> n_polysyllable_words = sum ( <NUM_LIT:1> for n in syllables_per_word if n >= <NUM_LIT:3> ) <EOL> return { '<STR_LIT>' : n_sents , <EOL> '<STR_LIT>' : n_words , <EOL> '<STR_LIT>' : n_unique_words , <EOL> '<STR_LIT>' : n_chars , <EOL> '<STR_LIT>' : n_syllables , <EOL> '<STR_LIT>' : n_polysyllable_words , <EOL> '<STR_LIT>' : flesch_kincaid_grade_level ( n_syllables , n_words , n_sents ) , <EOL> '<STR_LIT>' : flesch_readability_ease ( n_syllables , n_words , n_sents ) , <EOL> '<STR_LIT>' : smog_index ( n_polysyllable_words , n_sents ) , <EOL> '<STR_LIT>' : gunning_fog_index ( n_words , n_polysyllable_words , n_sents ) , <EOL> '<STR_LIT>' : coleman_liau_index ( n_chars , n_words , n_sents ) , <EOL> '<STR_LIT>' : automated_readability_index ( n_chars , n_words , n_sents ) } <EOL> def flesch_kincaid_grade_level ( n_syllables , n_words , n_sents ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT> * ( n_syllables / n_words ) + <NUM_LIT> * ( n_words / n_sents ) - <NUM_LIT> <EOL> def flesch_readability_ease ( n_syllables , n_words , n_sents ) : <EOL> """<STR_LIT>""" <EOL> return - <NUM_LIT> * ( n_syllables / n_words ) - <NUM_LIT> * ( n_words / n_sents ) + <NUM_LIT> <EOL> def smog_index ( n_polysyllable_words , n_sents , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> if verbose and n_sents < <NUM_LIT:30> : <EOL> print ( '<STR_LIT>' ) <EOL> return <NUM_LIT> * sqrt ( <NUM_LIT:30> * ( n_polysyllable_words / n_sents ) ) + <NUM_LIT> <EOL> def gunning_fog_index ( n_words , n_polysyllable_words , n_sents ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT> * ( ( n_words / n_sents ) + <NUM_LIT:100> * ( n_polysyllable_words / n_words ) ) <EOL> def coleman_liau_index ( n_chars , n_words , n_sents ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT> * ( n_chars / n_words ) - <NUM_LIT> * ( n_sents / n_words ) - <NUM_LIT> <EOL> def automated_readability_index ( n_chars , n_words , n_sents ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT> * ( n_chars / n_words ) + <NUM_LIT:0.5> * ( n_words / n_sents ) - <NUM_LIT> </s>
