nx_collocation.nx
buildroot/runtime/nx_collocation.nx
about
nx_collocation.nx -- statistical association metrics for word pairs.
First brick of the corpus-linguistics S-class substrate per cardinal
feedback-corpus-linguistics-s-class-substrate-sketch-engine-displacement.
Substrate goal: benchmark + exceed Sketch Engine on every measurable
axis, patent-clean, all NishiLang.
=== What this primitive answers ====================================
Given a co-occurrence count table (n_a, n_b, n_ab, n_total) — the
fundamental contingency-table summary of how often word A appears,
how often word B appears, how often they co-occur, and the corpus
size — emit the standard statistical association metrics:
PMI Church & Hanks 1990 log2( p(a,b) / (p(a)*p(b)) )
log-likelihood Dunning 1993 -2 * sum(O * ln(O/E))
T-score Manning & Schütze (O - E) / sqrt(O)
log-Dice Rychly 2008 14 + log2( 2*n_ab / (n_a + n_b) )
All Q10 fixed-point. No f64. All patent-clean (public NLP literature
from 1990-2008).
=== Composition ====================================================
nx_essentials.log2_floor -- integer log2 used everywhere
nx_tier.nx -- nx_int aliases
=== Sealed-enum strength bands ====================================
Per dual-reading cardinal: every primitive emits BOTH a quantitative
Q10 number AND a qualitative sealed-enum band. Downstream tooling
consumes the band without re-deriving thresholds.
genealogy_id: church_hanks_1990_pmi + dunning_1993_log_likelihood +
manning_schutze_1999_t_score + rychly_2008_log_dice +
firth_1957_collocations + halliday_1961_categories
lineage_id: nx_collocation_v1
dependencies 3 imports · 4 importers
imports: nx_syscalls.nxnx_tier.nxnx_essentials.nx
imported by: nx_collocation_test.nxnx_keyness.nxnx_word_sketch.nxnx_word_sketch_test.nx
structs
| none |
consts
| 48 | const NX_MAGIC_20480: i64 = 20480 |
| 49 | const NX_MAGIC_14336: i64 = 14336 |
| 51 | const NX_COL_Q: nx_int = 1024 // Q10 fixed-point base |
| 58 | const NX_COL_BAND_NONE: nx_int = 0 // no association |
| 59 | const NX_COL_BAND_WEAK: nx_int = 1 |
| 60 | const NX_COL_BAND_MODERATE: nx_int = 2 |
| 61 | const NX_COL_BAND_STRONG: nx_int = 3 |
| 62 | const NX_COL_BAND_VERY_STRONG: nx_int = 4 |
| 63 | const NX_COL_N_BANDS: nx_int = 5 |
| 76 | const NX_COL_METRIC_PMI: nx_int = 0 |
| 77 | const NX_COL_METRIC_LOG_LIKELIHOOD: nx_int = 1 |
| 78 | const NX_COL_METRIC_T_SCORE: nx_int = 2 |
| 79 | const NX_COL_METRIC_LOG_DICE: nx_int = 3 |
| 80 | const NX_COL_N_METRICS: nx_int = 4 |
| 97 | const NX_LN2_Q10: nx_int = 710 // 0.693147 * 1024 |
| 207 | const NX_COL_PMI_VERY_STRONG_Q10: nx_int = 6144 |
| 208 | const NX_COL_PMI_STRONG_Q10: nx_int = 3072 |
| 209 | const NX_COL_PMI_MODERATE_Q10: nx_int = 1024 |
| 210 | const NX_COL_PMI_WEAK_Q10: nx_int = 0 |
| 284 | const NX_COL_LL_VERY_STRONG_Q10: nx_int = 30720 // ~30 |
| 285 | const NX_COL_LL_STRONG_Q10: nx_int = 15360 // ~15 |
| 286 | const NX_COL_LL_MODERATE_Q10: nx_int = 6144 // ~6 |
| 287 | const NX_COL_LL_WEAK_Q10: nx_int = 3072 // ~3 |
| 328 | const NX_COL_T_VERY_STRONG_Q10: nx_int = 6144 |
| 329 | const NX_COL_T_STRONG_Q10: nx_int = 4096 |
| 330 | const NX_COL_T_MODERATE_Q10: nx_int = 2048 |
| 331 | const NX_COL_T_WEAK_Q10: nx_int = 1024 |
| 376 | const NX_COL_DICE_VERY_STRONG_Q10: nx_int = 10240 |
| 377 | const NX_COL_DICE_STRONG_Q10: nx_int = 7168 |
| 378 | const NX_COL_DICE_MODERATE_Q10: nx_int = 4096 |
| 379 | const NX_COL_DICE_WEAK_Q10: nx_int = 1024 |
| 396 | const NX_COL_OUT_PMI_Q10: nx_int = 0 |
| 397 | const NX_COL_OUT_LL_Q10: nx_int = 1 |
| 398 | const NX_COL_OUT_T_Q10: nx_int = 2 |
| 399 | const NX_COL_OUT_DICE_Q10: nx_int = 3 |
| 400 | const NX_COL_OUT_PMI_BAND: nx_int = 4 |
| 401 | const NX_COL_OUT_LL_BAND: nx_int = 5 |
| 402 | const NX_COL_OUT_T_BAND: nx_int = 6 |
| 403 | const NX_COL_OUT_DICE_BAND: nx_int = 7 |
| 404 | const NX_COL_OUT_FIELDS: nx_int = 8 |
functions
| 65 | func nx_col_band_is_valid(b: nx_int) -> nx_int |
| 82 | func nx_col_metric_is_valid(m: nx_int) -> nx_int called by 1: main |
| 99 | func _col_ln_q10(x: nx_int) -> nx_int |
| 124 | func _col_log2_q10(x: nx_int) -> nx_int |
| 142 | func _col_isqrt(n: nx_int) -> nx_int called by 1: nx_col_t_score_q10 |
| 182 | func nx_col_pmi_floor() -> nx_int { return 0 - NX_MAGIC_20480 } |
| 184 | func nx_col_pmi_q10(n_a: nx_int, n_b: nx_int, |
| 212 | func nx_col_pmi_band(pmi_q10: nx_int) -> nx_int |
| 240 | func _col_ll_term(o: nx_int, e: nx_int) -> nx_int |
| 250 | func nx_col_log_likelihood_q10(n_a: nx_int, n_b: nx_int, |
| 289 | func nx_col_log_likelihood_band(ll_q10: nx_int) -> nx_int |
| 307 | func nx_col_t_score_q10(n_a: nx_int, n_b: nx_int, |
| 333 | func nx_col_t_score_band(t_q10: nx_int) -> nx_int |
| 354 | func nx_col_log_dice_q10(n_a: nx_int, n_b: nx_int, n_ab: nx_int) -> nx_int |
| 381 | func nx_col_log_dice_band(dice_q10: nx_int) -> nx_int |
| 406 | func nx_col_emit_all(n_a: nx_int, n_b: nx_int, n_ab: nx_int, n_total: nx_int, |