Skip to main content

Crate text_statistics

Crate text_statistics 

Source
Expand description

§text-statistics

Comprehensive text statistics: word, sentence, and character counts, average word length, average sentence length, estimated reading time, and a lexile-like difficulty estimate. Pure Rust, zero dependencies, deterministic.

These are the same measurements the BeLikeNative AI writing assistant surfaces while you write — turned into a small, embeddable library.

§Quick example

use text_statistics::stats;

let s = stats("The cat sat on the mat. It was a good day for a nap.");
assert_eq!(s.words, 14);
assert_eq!(s.sentences, 2);
assert!(s.avg_word_length > 2.5);
assert!(s.estimated_reading_seconds < 60.0);
assert!(s.difficulty_band() == text_statistics::Difficulty::Easy);

Structs§

TextStats
The full bundle of computed statistics for a piece of text.

Enums§

Difficulty
A coarse difficulty band derived from the lexile-like estimate.

Constants§

EASY_AVG_WORD_LENGTH
Lexile-like difficulty reference: characters per word at grade-5 level. Below this average word length the text is considered “easy”.
HARD_AVG_SENTENCE_LENGTH
Above this average sentence length (in words) the text is considered “difficult” to follow.
HARD_AVG_WORD_LENGTH
Above this average word length the text is considered “difficult” (roughly grade-11+ vocabulary density).
WORDS_PER_MINUTE
Average adult reading speed, in words per minute. 200 wpm is the widely-cited average for silent reading of English prose.

Functions§

stats
Compute the full TextStats bundle for text.