I'm playing around with Levenshteins Edit Distance algorithm, and I want to extend this to count transpositions -- that is, exchanges of adjacent letters -- as 1 edit. The unmodified algorithm counts insertions, deletes or substitutions needed to reach a certain string from another. For instance, the edit distance from "KITTEN" to "SITTING" is 3. Here's the explanation from Wikipedia:
- kitten → sitten (substitution of 'k' with 's')
- sitten → sittin (substitution of 'e' with 'i')
- sittin → sitting (insert 'g' at the end).
Following the same method, the edit distance from "CHIAR" to "CHAIR" is 2:
- CHIAR → CHAR (delete 'I')
- CHAR → CHAIR (insert 'I')
I would like to count this as "1 edit", since I only exchange two adjacent letters. How would I go about to do this?