Crate syllarust

Source
Expand description

Syllarust - A Rust library for estimating syllables and other text metrics. This is still a work in progress, but the goal is to provide a simple library for estimating syllables in English words, as well as other text metrics counting words, sentences, and tokens.

The example below uses the rayon crate for parallel processing, but this is not necessary for the library to work. The library is designed to take advantage of Rust’s fearless concucrrency features, but use it how you’d like!

use syllarust::estimate_syllables;
use rayon::prelude::*;

fn main() {
    let test_strs: Vec<&str> = vec![
        "Apple",
        "Tart",
        "plate",
        "Pontificate",
        "Hello"
    ];
    
    let start = Instant::now();
    let results: Vec<usize> = test_strs.par_iter()
        .map(|s| estimate_syllables(s))
        .collect();

    let stop = Instant::now();
    println!("{:?}", stop - start);
    println!("{:?}", results);
}

Additionally, the library provides functions for counting words, sentences, and tokens in a text. These functions are count_words, count_sentences, and count_tokens, respectively.

use syllarust::{count_words, count_sentences, count_tokens};

fn main() {
    let test_str: &str = "Hello, world! This is a test.";
    println!("Words: {}", count_words(test_str));
    println!("Sentences: {}", count_sentences(test_str));
    println!("Tokens: {}", count_tokens(test_str));
}

For additional information, please see the documentation for the individual functions themselves.

Functions§

count_sentences
count_tokens
count_words
estimate_syllables
sentence_vec
tokens_vec