跳到主要内容
uencoder

计算 edit distance (Levenshtein)

Edit 距离 measures 最小值数字的 insertions, deletions, 和 substitutions 到转换 one 字符串为 另一个. Used 在 spell checking 和 fuzzy matching.

  1. 1

    Levenshtein 距离是 最小值数字的 单个-字符 edits (插入, delete, substitute) 到转换字符串为 字符串 B. "kitten" → "sitting" 有距离 3 (k→s, e→i, +g). 它是 computed 具有动态 programming: 矩阵 where 单元格[i][j] = min(插入, delete, substitute) based 开前一个 cells. Time 和 space: O(m×n).

  2. 2
    文本差异比较器 →

    比较两个 texts to see their differences. While text-diff shows line-level changes, edit distance operates at character level. Use text-diff for documents and edit distance for short strings (words, names)

  3. 3
    字数统计器 →

    为字-级别 edit 距离, tokenize 两者 texts 为字 arrays 和计算距离开 arrays. 此 measures 字-级别 changes (insertion, deletion, substitution 的 words) 而非字符-级别 changes.

常见问题

什么是 差集之间 Levenshtein 和 Damerau-Levenshtein?
Levenshtein allows 插入, delete, substitute. Damerau-Levenshtein also allows transposition 的 adjacent characters (ab → ba 在 one 操作). Damerau 是更多 appropriate 为 typing 错误 (adjacent 键 swaps). 两者是 O(m×n) 时间和 space.
如何是 edit 距离 used 在实践?
Spell checking (查找 dictionary words 具有小 距离到 misspelling), fuzzy 字符串 matching (查找 records 该是 similar 但不 exact), DNA 序列 alignment, 和 deduplication (合并 records 具有小 距离). 为大-规模 fuzzy 搜索, use BK-树或 Levenshtein automaton 为效率.

解决此任务的工作流

相关工具