pub struct TextStatistics { /* private fields */ }Expand description
Text statistics calculator for readability metrics and text complexity analysis.
Implementations§
Source§impl TextStatistics
impl TextStatistics
Sourcepub fn with_tokenizers(
wordtokenizer: WordTokenizer,
sentencetokenizer: SentenceTokenizer,
) -> Self
pub fn with_tokenizers( wordtokenizer: WordTokenizer, sentencetokenizer: SentenceTokenizer, ) -> Self
Create a TextStatistics analyzer with custom tokenizers
Sourcepub fn word_count(&self, text: &str) -> Result<usize>
pub fn word_count(&self, text: &str) -> Result<usize>
Count the number of words in text
Sourcepub fn sentence_count(&self, text: &str) -> Result<usize>
pub fn sentence_count(&self, text: &str) -> Result<usize>
Count the number of sentences in text
Sourcepub fn syllable_count(&self, text: &str) -> Result<usize>
pub fn syllable_count(&self, text: &str) -> Result<usize>
Count total syllables in text
Sourcepub fn complex_word_count(&self, text: &str) -> Result<usize>
pub fn complex_word_count(&self, text: &str) -> Result<usize>
Count the number of complex words (words with 3+ syllables)
Sourcepub fn avg_sentence_length(&self, text: &str) -> Result<f64>
pub fn avg_sentence_length(&self, text: &str) -> Result<f64>
Calculate average sentence length in words
Sourcepub fn avg_word_length(&self, text: &str) -> Result<f64>
pub fn avg_word_length(&self, text: &str) -> Result<f64>
Calculate average word length in characters
Sourcepub fn avg_syllables_per_word(&self, text: &str) -> Result<f64>
pub fn avg_syllables_per_word(&self, text: &str) -> Result<f64>
Calculate average syllables per word
Sourcepub fn flesch_reading_ease(&self, text: &str) -> Result<f64>
pub fn flesch_reading_ease(&self, text: &str) -> Result<f64>
Calculate Flesch Reading Ease score
Score interpretation:
- 90-100: Very easy to read. 5th grade level.
- 80-89: Easy to read. 6th grade level.
- 70-79: Fairly easy to read. 7th grade level.
- 60-69: Standard. 8th-9th grade level.
- 50-59: Fairly difficult. 10th-12th grade level.
- 30-49: Difficult. College level.
- 0-29: Very difficult. College graduate level.
Sourcepub fn flesch_kincaid_grade_level(&self, text: &str) -> Result<f64>
pub fn flesch_kincaid_grade_level(&self, text: &str) -> Result<f64>
Calculate Flesch-Kincaid Grade Level
Returns the U.S. school grade level needed to understand the text
Sourcepub fn gunning_fog(&self, text: &str) -> Result<f64>
pub fn gunning_fog(&self, text: &str) -> Result<f64>
Calculate Gunning Fog Index
The Gunning Fog Index estimates the years of formal education a person needs to understand the text on first reading
Sourcepub fn smog_index(&self, text: &str) -> Result<f64>
pub fn smog_index(&self, text: &str) -> Result<f64>
Calculate SMOG Index (Simple Measure of Gobbledygook)
SMOG estimates the years of education needed to understand a piece of writing. Typically used for health messages.
Sourcepub fn automated_readability_index(&self, text: &str) -> Result<f64>
pub fn automated_readability_index(&self, text: &str) -> Result<f64>
Calculate Automated Readability Index (ARI)
Returns the U.S. grade level needed to comprehend the text
Sourcepub fn coleman_liau_index(&self, text: &str) -> Result<f64>
pub fn coleman_liau_index(&self, text: &str) -> Result<f64>
Calculate Coleman-Liau Index
Returns the U.S. grade level needed to comprehend the text
Sourcepub fn dale_chall_readability(&self, text: &str) -> Result<f64>
pub fn dale_chall_readability(&self, text: &str) -> Result<f64>
Calculate Dale-Chall Readability Score
This is a more accurate readability formula, but requires a list of common words, which we approximate here
Sourcepub fn lexical_diversity(&self, text: &str) -> Result<f64>
pub fn lexical_diversity(&self, text: &str) -> Result<f64>
Calculate lexical diversity (unique words / total words)
Sourcepub fn type_token_ratio(&self, text: &str) -> Result<f64>
pub fn type_token_ratio(&self, text: &str) -> Result<f64>
Calculate type-token ratio (synonym for lexical diversity)
Sourcepub fn get_all_metrics(&self, text: &str) -> Result<ReadabilityMetrics>
pub fn get_all_metrics(&self, text: &str) -> Result<ReadabilityMetrics>
Get all readability metrics in a single call
Trait Implementations§
Source§impl Clone for TextStatistics
impl Clone for TextStatistics
Source§fn clone(&self) -> TextStatistics
fn clone(&self) -> TextStatistics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextStatistics
impl Debug for TextStatistics
Auto Trait Implementations§
impl Freeze for TextStatistics
impl RefUnwindSafe for TextStatistics
impl Send for TextStatistics
impl Sync for TextStatistics
impl Unpin for TextStatistics
impl UnwindSafe for TextStatistics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.