This crate provides fuzzy search/string matching using N-grams.
This implementation is character-based, rather than word based, matching solely based on string similarity.
Licensed under the MIT license.
Not published yet.
This crate is published on crates.io.
To use it, add this to your Cargo.toml:
toml
[dependencies]
ngrammatic = "0.2.0"
To do fuzzy matching, build up your corpus of valid symbols like this:
```rust use ngrammatic::{CorpusBuilder, Pad};
let mut corpus = CorpusBuilder::new() .arity(2) .pad_full(Pad::Auto) .finish();
// Build up the list of known words corpus.addtext("pie"); corpus.addtext("animal"); corpus.addtext("tomato"); corpus.addtext("seven"); corpus.add_text("carbon");
// Now we can try an unknown/misspelled word, and find a similar match // in the corpus let word = String::from("tomacco"); if let Some(topresult) = corpus.search(word, 0.25).first() { if topresult.similarity > 0.99 { println!("✔ {}", topresult.text); } else { println!("❓{} (did you mean {}? [{:.0}% match])", word, topresult.text, top_result.similarity * 100.0); } } else { println!("🗙 {}", word); } ```