Struct ngrammatic::Corpus
source · [−]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
sourceimpl Corpus
impl Corpus
sourcepub fn add_ngram(&mut self, ngram: Ngram)
pub fn add_ngram(&mut self, ngram: Ngram)
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'.");
}
sourcepub fn add_text(&mut self, text: &str)
pub fn add_text(&mut self, text: &str)
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'.");
}
sourcepub fn key(&self, text: &str) -> Option<String>
pub fn key(&self, text: &str) -> Option<String>
Determines whether an exact match exists for the supplied text
in the
Corpus
index, after processing it with the Corpus
’s key_trans
function.
sourcepub fn search(&self, text: &str, threshold: f32) -> Vec<SearchResult>
pub fn search(&self, text: &str, threshold: f32) -> Vec<SearchResult>
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'.");
}
sourcepub fn search_with_warp(
&self,
text: &str,
warp: f32,
threshold: f32
) -> Vec<SearchResult>
pub fn search_with_warp(
&self,
text: &str,
warp: f32,
threshold: f32
) -> Vec<SearchResult>
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
Auto Trait Implementations
impl !RefUnwindSafe for Corpus
impl Send for Corpus
impl Sync for Corpus
impl Unpin for Corpus
impl !UnwindSafe for Corpus
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more