⍝ Levenshtein distance:

    'Sunday' dist 'Saturday'
3
    'sitting' dist 'kitten'
3
    'Dyalog' dist 'Interpreter'     ⍝ disjoint vectors
11
    mons ← 'January' 'February' 'March' 'April'   'May'      'June'
    mons,← 'July'    'August'   'September'
    mons,← 'October' 'November' 'December'

    ∘.dist⍨ mons                ⍝ distances
0 4 6 7 5 5 4 6 9 7 8 8
4 0 7 7 6 7 6 7 8 7 8 7
6 7 0 4 3 5 5 6 9 7 8 8
7 7 4 0 5 5 5 5 8 7 8 8
5 6 3 5 0 4 3 6 9 7 8 8
5 7 5 5 4 0 2 5 8 6 7 7
4 6 5 5 3 2 0 5 9 7 8 8
6 7 6 5 6 5 5 0 9 7 8 8
9 8 9 8 9 8 9 9 0 5 4 3
7 7 7 7 7 6 7 7 5 0 5 4
8 8 8 8 8 7 8 8 4 5 0 3
8 7 8 8 8 7 8 8 3 4 3 0

    fuzzy←{({⍵⍳⌊/⍵}(lcase ⍺)∘dist∘lcase¨⍵)⊃⍵}   ⍝ fuzzy selection
    fuzzy∘mons¨ 'dcmbr' 'marching' 'febury'     ⍝ fuzzy matches
┌────────┬─────┬────────┐
│December│March│February│
└────────┴─────┴────────┘

Back to: code

Back to: Workspaces