pub fn ratio(s1: &str, s2: &str) -> f64Expand description
Calculate how similar two strings are, as a score from 0.0 to 1.0.
A score of 1.0 means the strings are identical, and 0.0 means they
have no character in common. In between, the score is the share of
characters the two strings have in common, known as the indel similarity
ratio:
ratio(s1, s2) = 2 · LCS(s1, s2) / (|s1| + |s2|)where LCS is the length of the longest common subsequence and |s| is
the number of characters in s. Two empty strings score 1.0.
§Examples
assert_eq!(lev::ratio("kitten", "sitting"), 0.6153846153846154);
assert_eq!(lev::ratio("abc", "xyz"), 0.0);
assert_eq!(lev::ratio("", ""), 1.0);
assert_eq!(lev::ratio("résumé", "resume"), 0.6666666666666667);