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

Holds a corpus of words and their ngrams, allowing fuzzy matches of candidate strings against known strings in the corpus.

Implementations

Add the supplied ngram to the Corpus.

let mut corpus = CorpusBuilder::new().finish();
corpus.add_ngram(NgramBuilder::new("tomato").finish());
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'.");
}

Generate an Ngram for the supplied text, and add it to the Corpus.

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'.");
}

If the corpus is empty.

Determines whether an exact match exists for the supplied text in the Corpus index, after processing it with the Corpus’s key_trans function.

Perform a fuzzy search of the Corpus for Ngrams above some threshold of similarity to the supplied text. Returns up to 10 results, sorted by highest similarity to lowest.

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'.");
}

Perform a fuzzy search of the Corpus for Ngrams with a custom warp for results above some threshold of similarity to the supplied text. Returns up to 10 results, sorted by highest similarity to lowest.

let mut corpus = CorpusBuilder::new().finish();
corpus.add_text("tomato");
let results = corpus.search_with_warp("tomacco", 2.0, 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'.");
}

Trait Implementations

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

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.