edit-operation

"Get the edit operations of two string"


License
MIT
Install
pip install edit-operation==1.0.0

Documentation

edit_operation

There are already several Python packages that implement levenshtein distance, which are writtend by C or C++ to improve the efficiency. In certain occasions, besides the edit distance, the edit operations are also needed. python-Levenshtein has the editops function but doesn't support transpose operations. So here comes the project, editdistpy supports the function of edit operations under Damerau–Levenshtein distance.

Install

    pip install -U edit_operation

Usage

The package supports distance and edit_operations two functions. They have the same parameters

  • string a
  • string b
  • max_distance: Only return right result under max_distance.
  • is_damerau: Whether support transpose operation or not.

distance

from edit_operation import levenshtein

a = 'absolute'
b = 'absiluti'

dis = levenshtein.distance(a, b)

return -1 if the actual distance is beyond max_distance, by default max_distance is -1, which means no max_distance limit.

edit_operations

from edit_operation import levenshtein

a = 'absolute'
b = 'bsiluti'
operations = levenshtein.edit_operations(a, b, is_damerau=True)

"""
[{'operation': 'replace', 'location': 7, 'char_x': 'e', 'char_y': 'i'}, 
 {'operation': 'delete', 'location': 0, 'char_x': '@', 'char_y': 'a'}]
"""

@ character means the beginning of the input string. Return empty list if the actual distance is beyond max_distance.