Function rustc_span::edit_distance::edit_distance_with_substrings
source · pub fn edit_distance_with_substrings(
a: &str,
b: &str,
limit: usize
) -> Option<usize>
Expand description
Provides a word similarity score between two words that accounts for substrings being more meaningful than a typical edit distance. The lower the score, the closer the match. 0 is an identical match.
Uses the edit distance between the two strings and removes the cost of the length difference.
If this is 0 then it is either a substring match or a full word match, in the substring match
case we detect this and return 1
. To prevent finding meaningless substrings, eg. “in” in
“shrink”, we only perform this subtraction of length difference if one of the words is not
greater than twice the length of the other. For cases where the words are close in size but not
an exact substring then the cost of the length difference is discounted by half.
Returns None
if the distance exceeds the limit.