Expand description
A port of the python-ngram project that provides fuzzy search using N-gram.
ยงโ๏ธ Example
use noodler::NGram;
let ngram = NGram::<&str>::builder()
.arity(2)
.warp(3.0)
.threshold(0.75)
.build()
// Feed with known words
.fill(vec!["pie", "animal", "tomato", "seven", "carbon"]);
// Try an unknown/misspelled word, and find a similar match
let word = "tomacco";
let top = ngram.search_sorted(word).next();
if let Some((text, similarity)) = top {
if similarity > 0.99 {
println!("โ {}", text);
} else {
println!(
"โ{} (did you mean {}? [{:.0}% match])",
word,
text,
similarity * 100.0
);
}
} else {
println!("๐ {}", word);
}ยง๐ญ Inspired by
Please check out these awesome works that helped a lot in the creation of noodler:
- python-ngram: Set that supports searching by ngram similarity.
- ngrammatic: A rust crate providing fuzzy search/string matching using N-grams.
ยง๐ฉ Minimal supported Rust version
All tests passed with rustc v1.41, earlier versions may not compile.