## Jaro–Winkler Similarity – How to correctly count the number of transpositions

Jaro–Winkler Similarity is a widely used similarity measure for checking the similarity between two strings. Being a similarity measure (not a distance measure), a higher value means more similar strings.

You can read on basics and how it works on Wikipedia. It’s available in many places and I’m not going into that. However, none of these sites talks about how to correctly count the number of transpositions in complex situations.

Transposition is defined as “matches which are not in the same position”. For a simple example like `‘c`

vs ‘**ar**t’`c`

’ it is obvious with 4 matches and 2 transpositions (‘r’ and ‘a’ are in not in the same position). But for **ra**tec`'x`

vs **abcd**xxxxxx' `'y`

in the first look, all letters seem to be out of position but there are **a**y**b**y**c**y**d**yyyyyy'**no transpositions** (4 matches). For very similar `'x`

vs**abcd**xxxxxx'` 'y`

, there are **d**y**a**y**b**y**c**yyyyyy'**4 transpositions **(4 matches). With these examples, it might not be trivial to count the number of transpositions.