How can label revisions be mapped to spans in both versions?

SequenceMatcher opcodes describe equal, replacement, insertion and deletion spans with half-open indices for each side.

Python example and interpretation

The change from cat to coat includes an insertion span. The alignment favors intuitive matching blocks and does not guarantee minimum edit distance.

from difflib import SequenceMatcher
SequenceMatcher(None,'cat','coat').get_opcodes()

Result [('equal', 0, 1, 0, 1), ('insert', 1, 1, 1, 2), ('equal', 1, 3, 2, 4)]

中文

怎样把两版标注的差异映射回各自的位置?

SequenceMatcher 的 opcodes 描述相等、替换、插入和删除片段,并为两侧提供半开区间下标。

Python 算例与适用条件

cat 变为 coat 时出现一个插入段。该对齐追求直观的匹配片段,不能当作严格的最小编辑距离。

from difflib import SequenceMatcher
SequenceMatcher(None,'cat','coat').get_opcodes()

结果 [('equal', 0, 1, 0, 1), ('insert', 1, 1, 1, 2), ('equal', 1, 3, 2, 4)]

References / 参考来源

Keep reading / 继续阅读