code wiki / (root) / nx_collocation.nx

nx_collocation.nx

buildroot/runtime/nx_collocation.nx

16207 B421 linesdepth 5pulls 5 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_essentials.nx nx_collocation.nx nx_collocation_test.nx nx_keyness.nx nx_word_sketch.nx nx_word_sketch_test.nx

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

48const NX_MAGIC_20480: i64 = 20480
49const NX_MAGIC_14336: i64 = 14336
51const NX_COL_Q: nx_int = 1024 // Q10 fixed-point base
58const NX_COL_BAND_NONE: nx_int = 0 // no association
59const NX_COL_BAND_WEAK: nx_int = 1
60const NX_COL_BAND_MODERATE: nx_int = 2
61const NX_COL_BAND_STRONG: nx_int = 3
62const NX_COL_BAND_VERY_STRONG: nx_int = 4
63const NX_COL_N_BANDS: nx_int = 5
76const NX_COL_METRIC_PMI: nx_int = 0
77const NX_COL_METRIC_LOG_LIKELIHOOD: nx_int = 1
78const NX_COL_METRIC_T_SCORE: nx_int = 2
79const NX_COL_METRIC_LOG_DICE: nx_int = 3
80const NX_COL_N_METRICS: nx_int = 4
97const NX_LN2_Q10: nx_int = 710 // 0.693147 * 1024
207const NX_COL_PMI_VERY_STRONG_Q10: nx_int = 6144
208const NX_COL_PMI_STRONG_Q10: nx_int = 3072
209const NX_COL_PMI_MODERATE_Q10: nx_int = 1024
210const NX_COL_PMI_WEAK_Q10: nx_int = 0
284const NX_COL_LL_VERY_STRONG_Q10: nx_int = 30720 // ~30
285const NX_COL_LL_STRONG_Q10: nx_int = 15360 // ~15
286const NX_COL_LL_MODERATE_Q10: nx_int = 6144 // ~6
287const NX_COL_LL_WEAK_Q10: nx_int = 3072 // ~3
328const NX_COL_T_VERY_STRONG_Q10: nx_int = 6144
329const NX_COL_T_STRONG_Q10: nx_int = 4096
330const NX_COL_T_MODERATE_Q10: nx_int = 2048
331const NX_COL_T_WEAK_Q10: nx_int = 1024
376const NX_COL_DICE_VERY_STRONG_Q10: nx_int = 10240
377const NX_COL_DICE_STRONG_Q10: nx_int = 7168
378const NX_COL_DICE_MODERATE_Q10: nx_int = 4096
379const NX_COL_DICE_WEAK_Q10: nx_int = 1024
396const NX_COL_OUT_PMI_Q10: nx_int = 0
397const NX_COL_OUT_LL_Q10: nx_int = 1
398const NX_COL_OUT_T_Q10: nx_int = 2
399const NX_COL_OUT_DICE_Q10: nx_int = 3
400const NX_COL_OUT_PMI_BAND: nx_int = 4
401const NX_COL_OUT_LL_BAND: nx_int = 5
402const NX_COL_OUT_T_BAND: nx_int = 6
403const NX_COL_OUT_DICE_BAND: nx_int = 7
404const NX_COL_OUT_FIELDS: nx_int = 8

functions

65func nx_col_band_is_valid(b: nx_int) -> nx_int
called by 2: mainmain
82func nx_col_metric_is_valid(m: nx_int) -> nx_int
called by 1: main
99func _col_ln_q10(x: nx_int) -> nx_int
called by 1: _col_ll_term calls 1: nx_log2_floor
124func _col_log2_q10(x: nx_int) -> nx_int
142func _col_isqrt(n: nx_int) -> nx_int
called by 1: nx_col_t_score_q10
182func nx_col_pmi_floor() -> nx_int { return 0 - NX_MAGIC_20480 }
called by 2: nx_col_pmi_q10main
184func nx_col_pmi_q10(n_a: nx_int, n_b: nx_int,
212func nx_col_pmi_band(pmi_q10: nx_int) -> nx_int
called by 2: nx_col_emit_allmain
240func _col_ll_term(o: nx_int, e: nx_int) -> nx_int
250func nx_col_log_likelihood_q10(n_a: nx_int, n_b: nx_int,
289func nx_col_log_likelihood_band(ll_q10: nx_int) -> nx_int
called by 2: nx_col_emit_allmain
307func nx_col_t_score_q10(n_a: nx_int, n_b: nx_int,
333func nx_col_t_score_band(t_q10: nx_int) -> nx_int
called by 2: nx_col_emit_allmain
354func nx_col_log_dice_q10(n_a: nx_int, n_b: nx_int, n_ab: nx_int) -> nx_int
381func nx_col_log_dice_band(dice_q10: nx_int) -> nx_int
called by 2: nx_col_emit_allmain
406func nx_col_emit_all(n_a: nx_int, n_b: nx_int, n_ab: nx_int, n_total: nx_int,