How to change the Levenshtein algorithm, find out if he inserted, deleted or replaced a character?

So, I'm trying to develop a disabling Levenshtein algorithm, where I keep track of what kind of transformations I made in a string (inserted a or replaced a with b).

Example:

Basically, I will say that I calculate the editing distance of "bbd" and "bcd"

The edit distance will be 1, and the conversion will be "substring b for c"

Question: How would I approach this problem, since the implementations that I saw do not care about what kind of operation it is, but only the total cost?

+4
source share
1 answer

- editops, , .

:

Levenshtein.editops("FBBDE", "BCDASD")
[('delete', 0, 0), ('replace', 2, 1), ('insert', 4, 3), ('insert', 4, 4), ('replace', 4, 5)]

:

, .

editops (source_string, destination_string) editops (edit_operations, source_length, destination_length)

(, spos, dpos), equal', replace ', insert', or delete'; SPOS dpos - () () . . , equal', but all the related functions accept both lists with and without equal.

+6

Source: https://habr.com/ru/post/1544366/


All Articles