textstat
:memo: python package to calculate readability statistics of a text object - paragraphs, sentences, articles.
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
Keywords from Contributors
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
Metadata Files
README.md
Textstat
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.
- Fork this repository on GitHub to start making your changes to the master branch (or branch off of it).
- Write a test which shows that the bug was fixed or that the feature works as expected.
- 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/
$ # Make changes
$ python -m pytest test.py # Run tests ```
Owner
- Name: Textstat
- Login: textstat
- Kind: organization
- Website: https://textstat.org
- Repositories: 5
- Profile: https://github.com/textstat
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
Top Committers
| Name | 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... | ||
Committer Domains (Top 20 + Academic)
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
Pull Request Labels
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
- Homepage: https://github.com/textstat/textstat
- Documentation: https://textstat.readthedocs.io/
- License: MIT
-
Latest release: 0.7.10
published 6 months ago
Rankings
Maintainers (2)
conda-forge.org: textstat
- Homepage: https://github.com/textstat/textstat
- License: MIT
-
Latest release: 0.7.2
published over 4 years ago
Rankings
Dependencies
- codespell * develop
- flake8 * develop
- ipython * develop
- pytest * develop
- wheel * develop
- Pyphen *
- repoze.lru *
- releases *
- Pyphen *
- pyphen *