VOOZH about

URL: https://pypi.org/project/textstat/

⇱ textstat Β· PyPI


Skip to main content

textstat 0.7.13

pip install textstat

Latest release

Released:

Calculate statistical features from text

Navigation

Unverified details

These details have not been verified by PyPI
Project links
Meta

Project description

Textstat

πŸ‘ PyPI
πŸ‘ Build Status
πŸ‘ Downloads

Textstat is an easy to use library to calculate statistics from text. It helps determine readability, complexity, and grade level.

πŸ‘ Image

Photo by Patrick Tomasso on Unsplash

Usage

>>> importtextstat

>>> 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."
)

>>> textstat.flesch_reading_ease(test_data)
>>> textstat.flesch_kincaid_grade(test_data)
>>> textstat.smog_index(test_data)
>>> textstat.coleman_liau_index(test_data)
>>> textstat.automated_readability_index(test_data)
>>> textstat.dale_chall_readability_score(test_data)
>>> textstat.difficult_words(test_data)
>>> textstat.linsear_write_formula(test_data)
>>> textstat.gunning_fog(test_data)
>>> textstat.text_standard(test_data)
>>> textstat.fernandez_huerta(test_data)
>>> textstat.szigriszt_pazos(test_data)
>>> textstat.gutierrez_polini(test_data)
>>> textstat.crawford(test_data)
>>> textstat.gulpease_index(test_data)
>>> textstat.osman(test_data)

The argument (text) for all the defined functions remains the same - i.e the text for which statistics need to be calculated.

Install

You can install textstat either via the Python Package Index (PyPI) or from source.

Install using pip

pipinstalltextstat

Install using easy_install

easy_installtextstat

Install latest version from GitHub

gitclonehttps://github.com/textstat/textstat.git
cdtextstat
pipinstall.

Install from PyPI

Download the latest version of textstat from http://pypi.python.org/pypi/textstat/

You can install it by doing the following:

tarxfztextstat-*.tar.gz
cdtextstat-*/
pythonsetup.pybuild
pythonsetup.pyinstall# as root

Language support

By default functions implement algorithms for english language. To change language, use:

textstat.set_lang(lang)

The language will be used for syllable calculation and to choose variant of the formula.

Language variants

All functions implement en_US language. Some of them has also variants for other languages listed below.

Function en de es fr it nl pl ru
flesch_reading_ease βœ” βœ” βœ” βœ” βœ” βœ” βœ”
gunning_fog βœ” βœ”

Spanish-specific tests

The following functions are specifically designed for spanish language. They can be used on non-spanish texts, even though that use case is not recommended.

>>> textstat.fernandez_huerta(test_data)
>>> textstat.szigriszt_pazos(test_data)
>>> textstat.gutierrez_polini(test_data)
>>> textstat.crawford(test_data)

Additional information on the formula they implement can be found in their respective docstrings.

List of Functions

Formulas

The Flesch Reading Ease formula

textstat.flesch_reading_ease(text)

Returns the Flesch Reading Ease Score.

The following table can be helpful to assess the ease of readability in a document.

The table is an example of values. While the maximum score is 121.22, there is no limit on how low the score can be. A negative score is valid.

Score Difficulty
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

Further reading on Wikipedia

The Flesch-Kincaid Grade Level

textstat.flesch_kincaid_grade(text)

Returns the Flesch-Kincaid Grade of the given text. This is a grade formula in that a score of 9.3 means that a ninth grader would be able to read the document.

Further reading on Wikipedia

The Fog Scale (Gunning FOG Formula)

textstat.gunning_fog(text)

Returns the FOG index of the given text. This is a grade formula in that a score of 9.3 means that a ninth grader would be able to read the document.

Further reading on Wikipedia

The SMOG Index

textstat.smog_index(text)

Returns the SMOG index of the given text. This is a grade formula in that a score of 9.3 means that a ninth grader would be able to read the document.

Texts of fewer than 30 sentences are statistically invalid, because the SMOG formula was normed on 30-sentence samples. textstat requires at least 3 sentences for a result.

Further reading on Wikipedia

Automated Readability Index

textstat.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.

Further reading on Wikipedia

The Coleman-Liau Index

textstat.coleman_liau_index(text)

Returns the grade level of the text using the Coleman-Liau Formula. This is a grade formula in that a score of 9.3 means that a ninth grader would be able to read the document.

Further reading on Wikipedia

Linsear Write Formula

textstat.linsear_write_formula(text)

Returns the grade level using the Linsear Write Formula. This is a grade formula in that a score of 9.3 means that a ninth grader would be able to read the document.

Further reading on Wikipedia

Dale-Chall Readability Score

textstat.dale_chall_readability_score(text)

Different from other tests, since it uses a lookup table of the most commonly used 3000 English words. Thus it returns the grade level using the New Dale-Chall Formula.

Score Understood by
4.9 or lower average 4th-grade student or lower
5.0–5.9 average 5th or 6th-grade student
6.0–6.9 average 7th or 8th-grade student
7.0–7.9 average 9th or 10th-grade student
8.0–8.9 average 11th or 12th-grade student
9.0–9.9 average 13th to 15th-grade (college) student

Further reading on Wikipedia

Readability Consensus based upon all the above tests

textstat.text_standard(text, float_output=False)

Based upon all the above tests, returns the estimated school grade level required to understand the text.

Optional float_output allows the score to be returned as a float. Defaults to False.

Spache Readability Formula

textstat.spache_readability(text)

Returns grade level of english text.

Intended for text written for children up to grade four.

Further reading on Wikipedia

McAlpine EFLAW Readability Score

textstat.mcalpine_eflaw(text)

Returns a score for the readability of an english text for a foreign learner or English, focusing on the number of miniwords and length of sentences.

It is recommended to aim for a score equal to or lower than 25.

Further reading on This blog post

Reading Time

textstat.reading_time(text, ms_per_char=14.69)

Returns the reading time of the given text.

Assumes 14.69ms per character.

Further reading in This academic paper

Language Specific Formulas

Índice de lecturabilidad Fernandez-Huerta (Spanish)

textstat.fernandez_huerta(text)

Reformulation of the Flesch Reading Ease Formula specifically for spanish. The results can be interpreted similarly

Further reading on This blog post

Índice de perspicuidad de Szigriszt-Pazos (Spanish)

textstat.szigriszt_pazos(text)

Adaptation of Flesch Reading Ease formula for spanish-based texts.

Attempts to quantify how understandable a text is.

Further reading on This blog post

FΓ³rmula de comprensibilidad de GutiΓ©rrez de Polini (Spanish)

textstat.gutierrez_polini(text)

Returns the GutiΓ©rrez de Polini understandability index.

Specifically designed for the texts in spanish, not an adaptation. Conceived for grade-school level texts.

Scores for more complex text are not reliable.

Further reading on This blog post

FΓ³rmula de Crawford (Spanish)

textstat.crawford(text)

Returns the Crawford score for the text.

Returns an estimate of the years of schooling required to understand the text.

The text is only valid for elementary school level texts.

Further reading on This blog post

Osman (Arabic)

textstat.osman(text)

Returns OSMAN score for text.

Designed for Arabic, an adaption of Flesch and Fog Formula. Introduces a new factor called "Faseeh".

Further reading in This academic paper

Gulpease Index (Italian)

textstat.gulpease_index(text)

Returns the Gulpease index of Italian text, which translates to level of education completed.

Lower scores require higher level of education to read with ease.

Further reading on Wikipedia

Wiener Sachtextformel (German)

textstat.wiener_sachtextformel(text, variant)

Returns a grade level score for the given text.

A value of 4 means very easy text, whereas 15 means very difficult text.

Further reading on Wikipedia

Aggregates and Averages

Syllable Count

textstat.syllable_count(text)

Returns the number of syllables present in the given text.

Uses the Python module Pyphen for syllable calculation in most languages, but defaults to nltk.corpus.cmudict for en_US.

Lexicon Count

textstat.lexicon_count(text, removepunct=True)

Calculates the number of words present in the text. Optional removepunct specifies whether we need to take punctuation symbols into account while counting lexicons. Default value is True, which removes the punctuation before counting lexicon items.

Sentence Count

textstat.sentence_count(text)

Returns the number of sentences present in the given text.

Character Count

textstat.char_count(text, ignore_spaces=True)

Returns the number of characters present in the given text.

Letter Count

textstat.letter_count(text, ignore_spaces=True)

Returns the number of characters present in the given text without punctuation.

Polysyllable Count

textstat.polysyllabcount(text)

Returns the number of words with a syllable count greater than or equal to 3.

Monosyllable Count

textstat.monosyllabcount(text)

Returns the number of words with a syllable count equal to one.

Contributing

If you find any problems, you should open an issue.

If you can fix an issue you've found, or another issue, you should open a pull request.

  1. Fork this repository on GitHub to start making your changes to the master branch (or branch off of it).
  2. Write a test which shows that the bug was fixed or that the feature works as expected.
  3. Send a pull request!

Development setup

It is recommended you use a virtual environment, or Pipenv to keep your development work isolated from your systems Python installation.

$gitclonehttps://github.com/<yourname>/textstat.git# Clone the repo from your fork
$cdtextstat
$pipinstall-rrequirements.txt# Install all dependencies

$# Make changes

$python-mpytesttest.py# Run tests

Project details

Unverified details

These details have not been verified by PyPI
Project links
Meta

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textstat-0.7.13.tar.gz (138.9 kB view details)

Uploaded Source

Built Distribution

Filter files by name, interpreter, ABI, and platform.

If you're not sure about the file name format, learn more about wheel file names.

Copy a direct link to the current filters

textstat-0.7.13-py3-none-any.whl (177.1 kB view details)

Uploaded Python 3

File details

Details for the file textstat-0.7.13.tar.gz.

File metadata

  • Download URL: textstat-0.7.13.tar.gz
  • Upload date:
  • Size: 138.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for textstat-0.7.13.tar.gz
Algorithm Hash digest
SHA256 a88d1da76287cd27ca4ce7bcba1ebaf2890544a5f0bb6a5758fa84cef3bceccb
MD5 48865ced55cdb8181bd2a5f63ebd167d
BLAKE2b-256 8c0fb673fcec5ad6e976b2e8368ef3651fe0fea3348a1191bacfcd41a17ddec6

See more details on using hashes here.

File details

Details for the file textstat-0.7.13-py3-none-any.whl.

File metadata

  • Download URL: textstat-0.7.13-py3-none-any.whl
  • Upload date:
  • Size: 177.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for textstat-0.7.13-py3-none-any.whl
Algorithm Hash digest
SHA256 04b1ec995d1e8b2e628759497e6b23204a9ec91dcd652447d8cbba9478f25471
MD5 17588c769af69d1121f62f4598aecae9
BLAKE2b-256 ca310eb4cc5bb021b4ceaaa602c59ba16ce99256b9dd30981bef3f3a53d8555f

See more details on using hashes here.

Supported by

πŸ‘ Image
AWS Cloud computing and Security Sponsor πŸ‘ Image
Datadog Monitoring πŸ‘ Image
Depot Continuous Integration πŸ‘ Image
Fastly CDN πŸ‘ Image
Google Download Analytics πŸ‘ Image
Pingdom Monitoring πŸ‘ Image
Sentry Error logging πŸ‘ Image
StatusPage Status page