nx_jaro_winkler.nx
buildroot/runtime/nx_jaro_winkler.nx
about
nx_jaro_winkler.nx -- Jaro-Winkler string-similarity primitive.
Operates on byte buffers. For ASCII / UTF-8 byte-by-byte matching;
caller normalizes case / Unicode beforehand if needed.
USE CASES (image-gen prompting + general):
- Prompt deduplication: "blonde girl, beach" vs "blonde girl on
beach" near-IDENTICAL -> reuse cached render.
- Identity-name fuzzy lookup: "Diora-Baird" vs "diora baird".
- Caption-vs-prompt alignment (failure_attribution L2 signal).
- Typo correction: nearest match across a small candidate set.
- Prompt clustering for recommendation (pairwise Q10 grid).
Algorithm:
matching window w = max(|s1|, |s2|) / 2 - 1
m = #chars in s1 found in s2 within +/- w positions (each char used once)
t = #matched-pairs in different order, halved
Jaro = (m/|s1| + m/|s2| + (m - t)/m) / 3
L = common prefix length, clamped at NX_JW_PREFIX_MAX (= 4)
p = 0.1 (Winkler 1990 canonical)
Jaro-Winkler = Jaro + L * p * (1 - Jaro)
All math Q10. Output in [0, Q10]. Idea-provenance: Jaro 1989,
Winkler 1990, Cohen-Ravikumar-Fienberg 2003 secondstring survey
(papers; no code referenced -- patent-clean-absorption discipline).
genealogy_id: jaro_1989_advances + winkler_1990_string_comparator +
cohen_ravikumar_fienberg_2003_secondstring_survey
lineage_id: jaro_winkler_q10
dependencies 2 imports · 3 importers
imports: nx_syscalls.nxnx_tier.nx
imported by: nx_damerau_levenshtein.nxnx_hamming.nxnx_jaro_winkler_test.nx
structs
| none |
consts
| 40 | const NX_JW_Q: nx_int = 1024 |
| 41 | const NX_JW_PREFIX_MAX: nx_int = 4 |
| 43 | const NX_JW_PREFIX_SCALE_Q10: nx_int = 102 |
| 45 | const NX_STRSIM_DISTINCT: nx_int = 0 |
| 46 | const NX_STRSIM_LOOSE_MATCH: nx_int = 1 |
| 47 | const NX_STRSIM_MATCH: nx_int = 2 |
| 48 | const NX_STRSIM_NEAR_DUPLICATE: nx_int = 3 |
| 49 | const NX_STRSIM_IDENTICAL: nx_int = 4 |
| 50 | const NX_STRSIM_N_BANDS: nx_int = 5 |
functions
| 54 | func _jw_common_prefix(s1: *u8, n1: nx_int, s2: *u8, n2: nx_int) -> nx_int called by 1: nx_jaro_winkler |
| 68 | func nx_jaro_winkler(s1: *u8, n1: nx_int, s2: *u8, n2: nx_int) -> nx_int |
| 148 | func nx_jaro_winkler_classify(similarity_q10: nx_int) -> nx_int |
| 156 | func nx_strsim_band_is_valid(band: nx_int) -> nx_int called by 1: main |