Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucacappelletti94/ngrammatic-old
Reference old version of ngrammatic
https://github.com/lucacappelletti94/ngrammatic-old
Last synced: 9 days ago
JSON representation
Reference old version of ngrammatic
- Host: GitHub
- URL: https://github.com/lucacappelletti94/ngrammatic-old
- Owner: LucaCappelletti94
- License: mit
- Created: 2024-04-08T07:14:12.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-07-26T14:51:00.000Z (3 months ago)
- Last Synced: 2024-10-13T13:52:24.737Z (23 days ago)
- Language: Rust
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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.
### Documentation
https://docs.rs/ngrammatic/latest/ngrammatic/
### Installation
This crate is published on [crates.io](https://crates.io/crates/).
To use it, add this to your Cargo.toml:
```toml
[dependencies]
ngrammatic = "0.3.4"
```### Usage
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.add_text("pie");
corpus.add_text("animal");
corpus.add_text("tomato");
corpus.add_text("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(top_result) = corpus.search(word, 0.25).first() {
if top_result.similarity > 0.99 {
println!("✔ {}", top_result.text);
} else {
println!("❓{} (did you mean {}? [{:.0}% match])",
word,
top_result.text,
top_result.similarity * 100.0);
}
} else {
println!("🗙 {}", word);
}
```