1

Is there a python package which supports the Damerau-Levenshtein-Distance with

  • support for any type of array, especially integers
  • weights for transposition, insertion, deletion and substitution, such that f.ex. 1 insertion counts as much as 3 deletions?

Some common libraries

1

This is not a library (a cython one would be even more preferable), but the code at http://mwh.geek.nz/2009/04/26/python-damerau-levenshtein-distance/ can be converted to variable costs pretty easily, by replacing the + 1 with the weights:

delcost = oneago[y] + weight_deletion
addcost = thisrow[y - 1] + weight_addition
subcost = oneago[y - 1] + ((seq1[x] != seq2[y]) * weight_substition)
thisrow[y] = min(delcost, addcost, subcost)
# This block deals with transpositions
if (x > 0 and y > 0 and seq1[x] == seq2[y - 1]
    and seq1[x-1] == seq2[y] and seq1[x] != seq2[y]):
    thisrow[y] = min(thisrow[y], (twoago[y - 2] + 1 * weight_transposition))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.