Expand description
§textstat — readability metrics for English text
Compute the classic readability scores — Flesch Reading Ease, Flesch-Kincaid
Grade, Gunning Fog, SMOG, Automated Readability Index, Coleman-Liau — plus the
word / sentence / syllable counts they are built on. Inspired by Python’s
textstat.
let text = "The cat sat on the mat. The dog ran fast.";
assert_eq!(textstat::lexicon_count(text), 10);
assert_eq!(textstat::sentence_count(text), 2);
// Simple text scores very high on reading ease (0–100+, higher = easier).
assert!(textstat::flesch_reading_ease(text) > 90.0);Pure logic, zero dependencies, #![no_std].
§Note on accuracy
Syllables are counted with a fast English heuristic (vowel groups with a
silent-e rule), not a pronunciation dictionary, so scores are close to —
but not bit-identical with — dictionary-based tools. The metric formulas
themselves are the standard published ones.
Functions§
- automated_
readability_ index - Automated Readability Index (U.S. school grade).
- char_
count - Count non-whitespace characters (includes punctuation).
- coleman_
liau_ index - Coleman-Liau index (U.S. school grade).
- flesch_
kincaid_ grade - Flesch-Kincaid Grade Level (U.S. school grade).
- flesch_
reading_ ease - Flesch Reading Ease: higher is easier (typically 0–100; can exceed both ends).
- gunning_
fog - Gunning Fog index (U.S. school grade).
- letter_
count - Count alphabetic characters only.
- lexicon_
count - Count words: whitespace-separated tokens containing at least one alphanumeric character (so stray punctuation tokens are not counted).
- polysyllabic_
count - Count polysyllabic words (three or more syllables) — used by Gunning Fog and SMOG.
- reading_
time - Estimated reading time in seconds at
words_per_minute. - sentence_
count - Count sentences by runs of terminal punctuation (
.,!,?). Non-empty text with no terminator counts as one sentence. - smog_
index - SMOG index (U.S. school grade), based on polysyllabic word density.
- syllable_
count - Total syllables across all words in
text. - syllables
- Estimate the number of syllables in a single English word using a vowel-group
heuristic with a silent-
erule. Always returns at least 1 for a word with letters, and 0 for a word with none.