code wiki / (root) / nx_keyness.nx

nx_keyness.nx

buildroot/runtime/nx_keyness.nx

8889 B222 linesdepth 6pulls 6 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_keyness.nx -- substrate-native keyword extraction. "Keyness" answers the canonical corpus-linguistics question: what words are distinctively COMMON in target corpus vs reference? Standard metric is Dunning's log-likelihood applied to a 2x2 contingency table comparing token frequencies between corpora. This is identical in shape to the collocation log-likelihood -- the difference is the meaning of the cells: Collocation: word_a vs word_b in same corpus, n_ab co-occurrences Keyness: same word in target vs reference corpus Composes: nx_collocation.nx -- log-likelihood already there; we reuse it Sealed verdict bands (Sketch Engine convention, see Kilgarriff 2009): POSITIVE_KEYWORD_STRONG -- strongly over-represented in target POSITIVE_KEYWORD_WEAK -- modestly over-represented NEUTRAL -- about the same in both NEGATIVE_KEYWORD -- under-represented in target genealogy_id: dunning_1993_log_likelihood + scott_1997_wordsmith_keywords + kilgarriff_2009_simple_maths lineage_id: keyness_extraction_v1

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_collocation.nx nx_keyness.nx nx_keyness_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_collocation.nx

imported by: nx_keyness_test.nx

structs

none

consts

36const NX_MAGIC_1024: i64 = 1024
37const NX_MAGIC_2048: i64 = 2048
45const NX_KEY_NEGATIVE_STRONG: nx_int = 0 // strongly under in target
46const NX_KEY_NEGATIVE_WEAK: nx_int = 1
47const NX_KEY_NEUTRAL: nx_int = 2 // ratio close to 1
48const NX_KEY_POSITIVE_WEAK: nx_int = 3
49const NX_KEY_POSITIVE_STRONG: nx_int = 4 // strongly over in target
50const NX_KEY_N_KINDS: nx_int = 5
119const NX_KEY_THRESH_WEAK_Q10: nx_int = 3932 // 3.84 * 1024
120const NX_KEY_THRESH_STRONG_Q10: nx_int = 15493 // 15.13 * 1024
203const NX_KEY_OUT_G2_Q10: nx_int = 0
204const NX_KEY_OUT_LOG_RATIO_Q10: nx_int = 1
205const NX_KEY_OUT_BAND: nx_int = 2
206const NX_KEY_OUT_OVER: nx_int = 3 // 1 = target over-represented
207const NX_KEY_OUT_FIELDS: nx_int = 4

functions

52func nx_key_kind_is_valid(k: nx_int) -> nx_int
called by 1: main
65func nx_key_target_overrepresented(observed_target: nx_int, total_target: nx_int,
94func nx_keyness_g2_q10(observed_target: nx_int, total_target: nx_int,
122func nx_keyness_band(g2_q10: nx_int) -> nx_int
157func _key_log2_ratio_q10(num: nx_int, den: nx_int) -> nx_int
190func nx_keyness_log_ratio_q10(observed_target: nx_int, total_target: nx_int,
209func nx_keyness_emit_all(observed_target: nx_int, total_target: nx_int,