Jaro–Winkler distance
In computer science and statistics, the Jaro–Winkler similarity is a string metric measuring an edit distance between two sequences. It is a variant of the Jaro distance metric proposed in 1990 by William E. Winkler.
The Jaro–Winkler distance uses a prefix scale which gives more favourable ratings to strings that match from the beginning for a set prefix length.
The higher the Jaro–Winkler distance for two strings is, the less similar the strings are. The score is normalized such that 0 means an exact match and 1 means there is no similarity. The original paper actually defined the metric in terms of similarity, so the distance is defined as the inversion of that value.
Although often referred to as a distance metric, the Jaro–Winkler distance is not a metric in the mathematical sense of that term because it does not obey the triangle inequality.
Definition
Jaro similarity
The Jaro similarity of two given strings and isWhere:
- is the length of the string ;
- is the number of matching characters ;
- is the number of transpositions.
If non-zero matching characters are found, the next step is to find the number of transpositions. Transposition is the number of matching characters that are not in the right order divided by two. In the above example between FAREMVIEL and FARMVILLE, 'E' and 'L' are the matching characters that are not in the right order. So the number of transposition is one.
Finally, plugging in the number of matching characters and number of transpositions the Jaro similarity of FAREMVIEL and FARMVILLE can be calculated,
Jaro–Winkler similarity
Jaro–Winkler similarity uses a prefix scale which gives more favorable ratings to strings that match from the beginning for a set prefix length. Given two strings and, their Jaro–Winkler similarity is:where:
- is the Jaro similarity for strings and
- is the length of common prefix at the start of the string up to a maximum of 4 characters
- is a constant scaling factor for how much the score is adjusted upwards for having common prefixes. should not exceed 0.25, otherwise the similarity could become larger than 1. The standard value for this constant in Winkler's work is
Although often referred to as a distance metric, the Jaro–Winkler distance is not a metric in the mathematical sense of that term because it does not obey the triangle inequality. The Jaro–Winkler distance also does not satisfy the identity axiom.
Relationship with other edit distance metrics
There are other popular measures of edit distance, which are calculated using a different set of allowable edit operations. For instance,- the Levenshtein distance allows deletion, insertion and substitution;
- the Damerau–Levenshtein distance allows insertion, deletion, substitution, and the transposition of two adjacent characters;
- the longest common subsequence distance allows only insertion and deletion, not substitution;
- the Hamming distance allows only substitution, hence, it only applies to strings of the same length.