readsight 1.0.1

Multilingual readability library — 86 languages, 17 formulas, TeX-based syllable counting via the Frank M. Liang algorithm.
Documentation
//! Shared statistics helpers used by multiple formulas.

use crate::text::TextStatistics;

/// Helpers over [`TextStatistics`].
pub struct TextStatisticsHelper;

impl TextStatisticsHelper {
    /// Estimate the percentage of "difficult" words (all words that are not
    /// monosyllabic), used by Dale-Chall and Spache.
    pub fn estimate_difficult_percentage(stats: &TextStatistics) -> f64 {
        if stats.word_count == 0 {
            return 0.0;
        }
        let easy = stats.syllable_histogram.get(&1).copied().unwrap_or(0);
        let mut difficult = stats.word_count - easy;
        if difficult < 0 {
            difficult = 0;
        }
        (difficult as f64 / stats.word_count as f64) * 100.0
    }
}