use readsight::ReadSight;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let plain = "We made an app that reads your text. It tells you how easy it is to read. \
You get a score in one second.";
let legal = "The parties acknowledge that any unauthorized disclosure of confidential \
information may cause irreparable harm. In such an event, the affected party \
shall be entitled to seek injunctive relief.";
let rs = ReadSight::new("en-us")?;
println!("== ReadSight (Rust) dashboard ==");
println!("Language: {} ({})", rs.language().name, rs.language().code);
println!();
println!(
"{:<28} | {:<24} | {:<26}",
"READABILITY FORMULA", "Plain text", "Legalese"
);
println!("{}", "-".repeat(28 + 24 + 26 + 6));
for name in rs.supported_formulas() {
let p = rs.score(&name, plain)?;
let l = rs.score(&name, legal)?;
println!(
"{:<28} | {:<24} | {:<26}",
p.formula_name,
cell(&p),
cell(&l)
);
}
println!();
println!("Syllables:");
for word in ["hyphenation", "banana", "beautiful", "communication"] {
println!(
" {:<16} count={} split_syllables={:?} split_word={:?}",
word,
rs.syllable_count(word),
rs.split_syllables(word),
rs.split_word(word)
);
}
println!();
let stats = rs.analyze(plain)?;
println!("Statistics (plain text):");
println!(" letters={}", stats.letter_count);
println!(" words={}", stats.word_count);
println!(" sentences={}", stats.sentence_count);
println!(" syllables={}", stats.syllable_count);
println!(" polysyllables={}", stats.polysyllable_count);
println!(" histogram={:?}", stats.syllable_histogram);
Ok(())
}
fn cell(r: &readsight::FormulaResult) -> String {
match r.grade_level {
Some(g) => format!("{} g{:.1} {}", r.score, g, r.interpretation),
None => format!("{} {}", r.score, r.interpretation),
}
}