pub struct CorpusBuilder { /* private fields */ }
Expand description

Build an Ngram Corpus, one setting at a time.

Implementations

Initialize a new instance of an CorpusBuilder, with a default arity of 2, padding set to Auto, for the given texts. The default key_trans function is a pass-through, leaving the keys unmodified.

let mut corpus = CorpusBuilder::new().finish();
corpus.add_text("tomato");
let results = corpus.search("tomacco", 0.40);
if let Some(result) = results.first() {
    println!("Closest match to 'tomacco' in the corpus was {}", result.text);
} else {
    println!("The corpus contained no words similar to 'tomacco'.");
}

Set the left padding to build into the Corpus.

Set the right padding to build into the Corpus.

Set both the left and right padding to build into the Corpus.

Set arity (the n in ngram) to use for the resulting Corpus.

Provide an iterator that will yield strings to be added to the Corpus.

A key transformation function, supplied as a boxed Fn that takes a &str and returns a String, applied to all strings that will be added to the Corpus. Searches on the Corpus will be similarly transformed.

use ngrammatic::CorpusBuilder;
let mut corpus = CorpusBuilder::new().key_trans(Box::new(|x| x.to_lowercase())).finish();
corpus.add_text("tomato");
let results = corpus.search("ToMaTo", 0.90);
if let Some(result) = results.first() {
    println!("Closest match to 'ToMaTo' in the corpus was {}", result.text);
} else {
    println!("The corpus contained no words similar to 'ToMaTo'.");
}

Convenience function that calls key_trans with a closure that lowercases all keys added to the Corpus.

let mut corpus = CorpusBuilder::new().case_insensitive().finish();
corpus.add_text("tomato");
let results = corpus.search("ToMaTo", 0.90);
if let Some(result) = results.first() {
    println!("Closest match to 'ToMaTo' in the corpus was {}", result.text);
} else {
    println!("The corpus contained no words similar to 'ToMaTo'.");
}

Yield a Corpus instance with all the properties set with this builder.

Trait Implementations

Debug format for a CorpusBuilder. Omits any representation of the key_trans field, as there’s no meaningful representation we could give.

Fowards to CorpusBuilder’s new method.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.