Python package to calculate statistics from text, which helps to decide readability, complexity and grade level of a particular corpus.
You can install textstat either via the Python Package Index (PyPI) or from source.
To install using pip:
$ pip install textstat
To install using easy_install:
$ easy_install textstat
Downloading and installing from source
Download the latest version of textstat from http://pypi.python.org/pypi/textstat/
You can install it by doing the following,:
$ tar xfz textstat-*.tar.gz
$ cd textstat-*/
$ python setup.py build
$ python setup.py install # as root
function name - syllable_count(text)
returns - the number of syllables present in the given text.
function name - lexicon_count(text, TRUE/FALSE)
Calculates the number of words present in the text. TRUE/FALSE specifies whether we need to take in account in punctuation symbols while counting lexicons or not. Default value is TRUE, which removes the punctuation before counting lexicons.
function name - sentence_count(text)
returns the number of sentences present in the given text.
function name - flesch_reading_ease(text)
returns the Flesch Reading Ease Score. Following table is helpful to access the ease of readability in a document.
- 90-100 : Very Easy
- 80-89 : Easy
- 70-79 : Fairly Easy
- 60-69 : Standard
- 50-59 : Fairly Difficult
- 30-49 : Difficult
- 0-29 : Very Confusing
function name - flesch_kincaid_grade(text)
returns the grade score using the Flesch-Kincaid Grade Formula. For example a score of 9.3 means that a ninth grader would be able to read the document.
function name - gunning_fog(text) returns the FOG index of the given text.
function name - smog_index(text)
return the SMOG index of the given text.
function name - automated_readability_index(text)
returns the ARI(Automated Readability Index) which outputs a number that approximates the grade level needed to comprehend the text. For example if the ARI is 6.5, then the grade level to comprehend the text is 6th to 7th grade.
function name - coleman_liau_index(text)
returns the grade level of the text using the Coleman-Liau Formula
function name - linsear_write_formula(text)
returns the grade level using the Lisear Write Formula
function name - dale_chall_readability_score(text)
Different from other tests, since it uses a lookup table of most commonly used 3000 english words. Thus it returns the grade level using the New Dale-Chall Formula.
function name - readability_consensus(text) Based upon all the above tests returns the best grade level under which the given text belongs to.
from textstat.textstat import textstat
if __name__ == '__main__':
test_data = """Playing games has always been thought to be important to the development of well-balanced and creative children; however, what part, if any, they should play in the lives of adults has never been researched that deeply. I believe that playing games is every bit as important for adults as for children. Not only is taking time out to play games with our children and other adults valuable to building interpersonal relationships but is also a wonderful way to release built up tension."""
print textstat.flesch_reading_ease(test_data)
print textstat.smog_index(test_data)
print textstat.flesch_kincaid_grade(test_data) print textstat.coleman_liau_index(test_data)
print textstat.automated_readability_index(test_data)
print textstat.dale_chall_readability_score(test_data)
print textstat.difficult_words(test_data)
print textstat.linsear_write_formula(test_data)
print textstat.gunning_fog(test_data)
print textstat.text_standard(test_data)
the arguement (text) for all the functions defined remains same - i.e the text for which statistics needs to be calculated