Skip to main content

"Get the edit operations of two string"

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

edit_operation-1.0.0-cp38-cp38-win_amd64.whl (20.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

edit_operation-1.0.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (157.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

edit_operation-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl (19.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

edit_operation-1.0.0-cp37-cp37m-win_amd64.whl (19.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

edit_operation-1.0.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (149.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

edit_operation-1.0.0-cp36-cp36m-win_amd64.whl (21.6 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

edit_operation-1.0.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page