code wiki / (root) / nx_damerau_levenshtein.nx

nx_damerau_levenshtein.nx

buildroot/runtime/nx_damerau_levenshtein.nx

4629 B139 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_damerau_levenshtein.nx -- edit distance with adjacent transposition. Damerau-Levenshtein extends Levenshtein (insert / delete / substitute) with a fourth edit operation: transposition of two ADJACENT characters. Counts "ab" -> "ba" as one edit (Damerau 1964 found 80% of human typos are one Damerau edit). Optimal-string-alignment (restricted-Damerau) variant -- adjacent-only, no two-step transpositions through previously-edited substrings. USE CASES: - typo correction: "the" vs "teh" -> distance 1 (Damerau) vs distance 2 (Levenshtein); much better fit for human errors - identity name lookup: "Diora Baird" vs "Diroa Baird" -> 1 - prompt-token typo: "blonde" vs "blnode" -> 1 Cross-modal: any byte sequence where adjacent-swap is a natural edit (text, DNA where adjacent base swap is a known mutation). Wagner-Fischer DP O(m*n) time + O(m*n) space, with one extra DP rule at each cell: if i >= 2 AND j >= 2 AND s1[i-1] == s2[j-2] AND s1[i-2] == s2[j-1]: dp[i][j] = min(dp[i][j], dp[i-2][j-2] + 1) Idea-provenance: Damerau 1964 "A technique for computer detection and correction of spelling errors" Communications of the ACM + Levenshtein 1965 + Wagner-Fischer 1974. Papers only. genealogy_id: damerau_1964_typo_correction + levenshtein_1965 + wagner_fischer_1974 lineage_id: damerau_levenshtein_q10

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_jaro_winkler.nx nx_damerau_levenshtein.nx nx_damerau_levenshtein_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_jaro_winkler.nx

imported by: nx_damerau_levenshtein_test.nx

structs

none

consts

43const NX_DLV_Q: nx_int = 1024

functions

46func _dlv_min2(a: nx_int, b: nx_int) -> nx_int
51func _dlv_min3(a: nx_int, b: nx_int, c: nx_int) -> nx_int
58func _dlv_min4(a: nx_int, b: nx_int, c: nx_int, d: nx_int) -> nx_int
68func nx_damerau_levenshtein(s1: *u8, n1: nx_int, s2: *u8, n2: nx_int) -> nx_int
121func nx_damerau_levenshtein_similarity_q10(s1: *u8, n1: nx_int,
called by 1: main calls 1: nx_damerau_levenshtein
137func nx_damerau_levenshtein_classify(similarity_q10: nx_int) -> nx_int
called by 1: main calls 1: nx_jaro_winkler_classify