fuzzy-string-distance

Fuzzy string distance comparisons

1 stable release

1.0.0 Sep 15, 2024

#457 in Text processing

Download history 153/week @ 2024-09-13 25/week @ 2024-09-20 7/week @ 2024-09-27 1/week @ 2024-10-04

186 downloads per month

MIT/Apache

22KB
158 lines

Fuzzy

Fuzzy string comparisons using Levenshtein distance

Whereas simple string comparison is very sensitive to typos, Levenshtein Distance gives the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. This gives us a sliding scale between 0 (strings are identical) and the length of the longer string (strings are unrelated), which can be used for fuzzy comparisons that can be resilient to typos, minor mistakes, and inconsistent spelling.

use fuzzy_string_distance::levenshtein_distance;
assert_eq!(1, levenshtein_distance(&"rust", &"rusty")); // insert y
assert_eq!(3, levenshtein_distance(&"bug", &"")); // delete all characters
assert_eq!(2, levenshtein_distance(&"typography", &"typpgrapy")); // fix both typos

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps