Crates.io | fuzzy-string-distance |
lib.rs | fuzzy-string-distance |
version | 1.0.0 |
source | src |
created_at | 2024-09-15 18:37:20.074468 |
updated_at | 2024-09-15 18:37:20.074468 |
description | Fuzzy string distance comparisons |
homepage | |
repository | https://github.com/Skeletonxf/fuzzy |
max_upload_size | |
id | 1375633 |
size | 33,323 |
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
Licensed under either of
at your option.
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.