This repository contains an implementation of the string edit distance algorithm to compute the minimum sequence of cost edit operations between two strings.
- Python >= 3.10
# Create virtual environment
python3.10 -m venv venv
source venv/bin/activate
# Install the Python package
python3 -m pip install -e .from sed.string_edit_distance import StringEditDistance
string1 = 'ABABBB'
string2 = 'BABAAA'
sed = StringEditDistance(string1, string2)
D = sed.init_cost_matrix()
P = sed.init_pointer_matrix()
sed.calc_sed(D, P)
print('Cost Matrix D: ')
print(D)
print('\nPointer Matrix P: ')
for row in P:
print(" ".join(row))According to the cost matrix
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| 1 | 2 | 1 | 2 | 3 | 4 | 5 |
| 2 | 1 | 2 | 1 | 2 | 3 | 4 |
| 3 | 2 | 1 | 2 | 1 | 2 | 3 |
| 4 | 3 | 2 | 1 | 2 | 3 | 4 |
| 5 | 4 | 3 | 2 | 3 | 4 | 5 |
| 6 | 5 | 4 | 3 | 4 | 5 | 6 |
According to the pointer matrix
| ← | ← | ← | ← | ← | ← | |
| ↑ | ↖ | ↖ | ← | ↖ | ↖ | ↖ |
| ↑ | ↖ | ↑ | ↖ | ← | ← | ← |
| ↑ | ↑ | ↖ | ↑ | ↖ | ↖ | ↖ |
| ↑ | ↖ | ↑ | ↖ | ↑ | ↖ | ↖ |
| ↑ | ↖ | ↑ | ↖ | ↖ | ↖ | ↖ |
| ↑ | ↖ | ↑ | ↖ | ↖ | ↖ | ↖ |
The current implementation is restricted to lowercase and uppercase Roman letters, represented by the set