Implements the Damerau–Levenshtein diff algorithm
Project description
- Version:
- 0.1.2
- Date:
- 2023-01-05
Overview
The dam_lev
package implements the
Damerau–Levenshtein diff algorithm. That is,
it will take two sequences and determine the minimum number of transpositions, substitutions, insertions, and
deletions needed to transform the first sequence into the second.
Usage
The package exposes a single function, dam_lev.get_changes
. It takes two sequences (i.e., they must
implement the __len__
and __getitem__
methods) and returns a list of dam_lev.Mutation
objects. There are four subclasses of dam_lev.Mutation
corresponding to the four types of
transformations. For example,
diffs = dam_lev.get_changes('abcdef', 'bcedxy')
print(diffs) # [Deletion(at=0), Transposition(at=3), Substitution(at=5, at2=4), Insertion(at=6, at2=5)]
We see that the sequence of transformations is:
Delete the item at index 0 (
'a'
)Transpose the item at index 3 (
'd'
) with its successorSubstitute the item at index 5 (
'f'
) with the item from the second sequence at index 4 ('x'
)Insert at index 6 the item from the second sequence at index 5 (
'y'
)
Note the index for the transposition. Even though, after the deletion, the 'd'
is at index 2, it’s at
index 3 in the original version of the sequence. Likewise for the successive mutations.
Key function
You can also pass a callable as the key
keyword argument to dam_lev.get_changes
. Similar to
list.sort
, this callable will be used to compare the elements of the sequences. For example,
diffs = dam_lev.get_changes('aBc', 'AbC', key=str.upper)
print(diffs) # []
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dam_lev-0.1.2.tar.gz
.
File metadata
- Download URL: dam_lev-0.1.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ab0e04751c51ca118a6a0ae31b923db3a78f355e3dc3cf6e33a93711ae17fd |
|
MD5 | 853544fb572180bbbe697c4c18f913c4 |
|
BLAKE2b-256 | e245ad5e9475b5ff7c38cc3c44b3b0c5fda2618e5ee8b01a4dccf30c52e25ec0 |
File details
Details for the file dam_lev-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: dam_lev-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e0b5e3d5d6f948b0718b848183d44b70af073bddb260c1810826eaec29486eb |
|
MD5 | 3d029f7412d2b16b141e6ca6682ec9d3 |
|
BLAKE2b-256 | a4d7599555989638860f3b309d3798d03a94dbf3c1d75a80ab45a78a5b4cf66e |