A Small Edit Distance Example

Edit distance measures the fewest allowed editing operations to transform one text into another under specified costs.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a single deletion
  2. Use it as evidence
  3. Follow one character change in each direction
  4. Check the matching model before tuning spelling suggestions

Trace a single deletion

Under unit-cost insertion, deletion, and substitution, cat and cart differ by one insertion of r. Swapping two adjacent characters may count as two operations under this model. String positions identify the edits.

Use it as evidence

Closeness can suggest a correction, but two similar terms can both be valid. Keep exact matches visible and define how suggestions affect title ranking.[1]

Follow one character change in each direction

The words map and maps differ by one insertion. Map and mat differ by one substitution. Map and amp require two changes under ordinary Levenshtein distance because a transposition is not an elementary operation there. See substring and subsequence relations.

map → maps: insert s
map → mat: substitute t for p
map → amp: two substitutions or another two-operation path under Levenshtein rules

Check the matching model before tuning spelling suggestions

Some distances allow a neighboring transposition as one operation. Case and accent rules can also change the compared sequences. Test short ambiguous words so unrelated terms are not broadened without a reason.

References

  1. Christopher D. Manning, Prabhakar Raghavan and Hinrich Schütze, Introduction to Information Retrieval ↩