Skip to main content

Crate textstat

Crate textstat 

Source
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-e rule. Always returns at least 1 for a word with letters, and 0 for a word with none.