Crate fuzzy_string_distance

Source
Expand description

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

Functionsยง

levenshtein_distance
Returns the minimum number of single character insertions, deletions or substitutions required to convert the source string to the target string, known as the Levenshtein distance.
levenshtein_distance_ignore_ascii_case
Returns the minimum number of single character insertions, deletions or substitutions required to convert the source string to the target string, known as the Levenshtein distance, ignoring ASCII case differences.
local_levenshtein_distance
A modified Levenshtein distance that matches from the source string to an arbitrary substring of the target string, returning the minimum number of single character insertions, deletions or substitutions required to convert the source string to match any substring in the target.
local_levenshtein_distance_ignore_ascii_case
A modified Levenshtein distance that matches from the source string to an arbitrary substring of the target string, returning the minimum number of single character insertions, deletions or substitutions required to convert the source string to match any substring in the target, ignoring ASCII case differences