Skip to main content

Crate ngram_rs

Crate ngram_rs 

Source
Expand description

§Short example illustrating the library usage

use std::borrow::Cow;
use ngram_rs::generate_ngrams;

let words = vec!["the".to_string(), "quick".to_string(), "brown".to_string()];
let ngrams = generate_ngrams(&words, &[1, 2], None);

assert_eq!(ngrams, vec![
    Cow::Borrowed("the"),
    Cow::Borrowed("quick"),
    Cow::Borrowed("brown"),
    Cow::Owned("the quick".to_string()),
    Cow::Owned("quick brown".to_string()),
]);

Structs§

NGramIterator
An iterator that generates n-grams lazily for memory-efficient processing.

Functions§

generate_ngrams
Generates n-grams from a sequence of words with configurable n-gram sizes and delimiter.
generate_ngrams_owned
Generates n-grams and returns owned strings, useful for integration with Polars.
ngrams_as_iterator
Creates an iterator that generates n-grams lazily.