textstat

:memo: python package to calculate readability statistics of a text object - paragraphs, sentences, articles.

https://github.com/textstat/textstat

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 49 committers (4.1%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.9%) to scientific vocabulary

Keywords

flesch-kincaid-grade flesch-reading-ease python readability smog textstat

Keywords from Contributors

transformer cryptocurrency medical-images cryptography audio agents pretrained-models jax vector-database large-language-models
Last synced: 6 months ago · JSON representation

Repository

:memo: python package to calculate readability statistics of a text object - paragraphs, sentences, articles.

Basic Info
  • Host: GitHub
  • Owner: textstat
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage: https://textstat.org
  • Size: 1.38 MB
Statistics
  • Stars: 1,312
  • Watchers: 18
  • Forks: 177
  • Open Issues: 20
  • Releases: 21
Topics
flesch-kincaid-grade flesch-reading-ease python readability smog textstat
Created over 11 years ago · Last pushed 6 months ago
Metadata Files
Readme License

README.md

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.

Photo by Patrick Tomasso on Unsplash

Usage

```python

import textstat

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.fleschreadingease(testdata) textstat.fleschkincaidgrade(testdata) textstat.smogindex(testdata) textstat.colemanliauindex(testdata) textstat.automatedreadabilityindex(testdata) textstat.dalechallreadabilityscore(testdata) textstat.difficultwords(testdata) textstat.linsearwriteformula(testdata) textstat.gunningfog(testdata) textstat.textstandard(testdata) textstat.fernandezhuerta(testdata) textstat.szigrisztpazos(testdata) textstat.gutierrezpolini(testdata) textstat.crawford(testdata) textstat.gulpeaseindex(testdata) 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

shell pip install textstat

Install using easy_install

shell easy_install textstat

Install latest version from GitHub

shell git clone https://github.com/textstat/textstat.git cd textstat pip install .

Install from PyPI

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

You can install it by doing the following:

shell tar xfz textstat-*.tar.gz cd textstat-*/ python setup.py build python setup.py install # as root

Language support

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

python 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 | |-----------------------------|----|----|----|----|----|----|----|----| | fleschreadingease | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | | ✔ | | 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.

```python

textstat.fernandezhuerta(testdata) textstat.szigrisztpazos(testdata) textstat.gutierrezpolini(testdata) 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

python 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

python 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)

python 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

python 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

python 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

python 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

python 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

python 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

python 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

python 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

python 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

python 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)

python 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)

python 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)

python 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)

python 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)

python 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)

python 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)

python 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

python 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

python 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

python textstat.sentence_count(text)

Returns the number of sentences present in the given text.

Character Count

python textstat.char_count(text, ignore_spaces=True)

Returns the number of characters present in the given text.

Letter Count

python textstat.letter_count(text, ignore_spaces=True)

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

Polysyllable Count

python textstat.polysyllabcount(text)

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

Monosyllable Count

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

```bash $ git clone https://github.com//textstat.git # Clone the repo from your fork $ cd textstat $ pip install -r requirements.txt # Install all dependencies

$ # Make changes

$ python -m pytest test.py # Run tests ```

Owner

  • Name: Textstat
  • Login: textstat
  • Kind: organization

GitHub Events

Total
  • Create event: 2
  • Release event: 3
  • Issues event: 12
  • Watch event: 174
  • Delete event: 1
  • Issue comment event: 44
  • Push event: 21
  • Pull request review event: 3
  • Pull request review comment event: 1
  • Pull request event: 9
  • Fork event: 7
Last Year
  • Create event: 2
  • Release event: 3
  • Issues event: 12
  • Watch event: 174
  • Delete event: 1
  • Issue comment event: 44
  • Push event: 21
  • Pull request review event: 3
  • Pull request review comment event: 1
  • Pull request event: 9
  • Fork event: 7

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 367
  • Total Committers: 49
  • Avg Commits per committer: 7.49
  • Development Distribution Score (DDS): 0.684
Past Year
  • Commits: 62
  • Committers: 4
  • Avg Commits per committer: 15.5
  • Development Distribution Score (DDS): 0.145
Top Committers
Name Email Commits
Alex Ward a****d@g****m 116
Sean Hastings s****7@g****m 53
LKirst l****h@m****g 42
Shivam Bansal s****2@g****m 23
Lukas Schöbel 5****l 12
alonsomartinez a****9@g****m 10
Christian Clauss c****s@m****m 9
Guillem García Subies 3****s 9
Shivam Bansal s****l@i****m 6
markopy (****) 5
Brandon Pokorny p****3@i****u 5
hugovk h****k 5
akarsh3007 a****h@k****m 4
Caleb Foong c****s 4
Andrew McNutt m****w@g****m 4
Rinaldo Rex r****4@g****m 4
Takeshi KISHIYAMA k****t@g****m 4
Chaitanya Aggarwal c****s@g****m 4
miczi m****l@g****m 4
Lane Clark l****k@g****a 3
Lane Clark 5****o 3
matyas m****v@g****m 3
Aether a****u@g****m 2
Christoph Haarburger c****r@l****e 2
lm l****s@g****m 2
richiehowelll r****l@g****m 2
mbarkhau m****u@g****m 2
krosan m****3@g****m 2
Clickedbigfoot c****t@g****m 2
guillem.garcia g****a@i****s 2
and 19 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 67
  • Total pull requests: 53
  • Average time to close issues: 6 months
  • Average time to close pull requests: 19 days
  • Total issue authors: 34
  • Total pull request authors: 22
  • Average comments per issue: 1.97
  • Average comments per pull request: 1.43
  • Merged pull requests: 45
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 7
  • Pull requests: 9
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 1 month
  • Issue authors: 7
  • Pull request authors: 4
  • Average comments per issue: 0.71
  • Average comments per pull request: 2.22
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • alxwrd (14)
  • DonaldTsang (14)
  • LKirst (6)
  • GuillemGSubies (2)
  • dogweather (2)
  • Rexfarell (1)
  • slavakurilyak (1)
  • harupy (1)
  • rgoubet (1)
  • wangxuan123123 (1)
  • stribor14 (1)
  • Eeman1113 (1)
  • aaroncarlfernandez (1)
  • nikchha (1)
  • klinehan1 (1)
Pull Request Authors
  • alxwrd (9)
  • LKirst (7)
  • Sean-Hastings (4)
  • lukaschoebel (4)
  • Clickedbigfoot (4)
  • lclarko (3)
  • GuillemGSubies (3)
  • LuckyLu04 (2)
  • matyasosvath (2)
  • dogweather (2)
  • mbarkhau (2)
  • vcBinary (2)
  • alonsoC1s (2)
  • pls78 (1)
  • halidziya (1)
Top Labels
Issue Labels
bug (17) enhancement (17) priority: low (15) good first issue (9) priority: high (8) lang support (7) priority: medium (6) question (4) docs (3) announcement (2) chore (2) pr welcome (1)
Pull Request Labels
hacktoberfest-accepted (5)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 1,919,305 last-month
  • Total docker downloads: 1,686
  • Total dependent packages: 27
    (may contain duplicates)
  • Total dependent repositories: 677
    (may contain duplicates)
  • Total versions: 40
  • Total maintainers: 2
pypi.org: textstat

Calculate statistical features from text

  • Versions: 34
  • Dependent Packages: 27
  • Dependent Repositories: 676
  • Downloads: 1,919,305 Last month
  • Docker Downloads: 1,686
Rankings
Dependent repos count: 0.5%
Dependent packages count: 0.6%
Downloads: 1.0%
Average: 1.7%
Docker downloads count: 1.9%
Stargazers count: 2.0%
Forks count: 4.0%
Maintainers (2)
Last synced: 6 months ago
conda-forge.org: textstat
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Stargazers count: 13.2%
Forks count: 14.9%
Dependent repos count: 24.3%
Average: 26.0%
Dependent packages count: 51.6%
Last synced: 6 months ago

Dependencies

Pipfile pypi
  • codespell * develop
  • flake8 * develop
  • ipython * develop
  • pytest * develop
  • wheel * develop
  • Pyphen *
  • repoze.lru *
docs/requirements.txt pypi
  • releases *
requirements.txt pypi
  • Pyphen *
setup.py pypi
  • pyphen *