code wiki / (root) / nx_word_sketch.nx

nx_word_sketch.nx

buildroot/runtime/nx_word_sketch.nx

8139 B201 linesdepth 7pulls 8 transitivereach 1 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_word_sketch.nx -- substrate-native word sketch (Sketch Engine displacement, see feedback-corpus-linguistics-s-class-substrate-...). A "word sketch" is the canonical Sketch Engine feature: given a target word, list its statistically most significant collocates. Sketch Engine groups by grammatical relation (subj_of/obj_of/...), which requires a parser; this v1 primitive groups by POSITIONAL WINDOW instead (collocates within +/- W of the target), which is what corpus linguists call a "raw" word sketch. Composes: nx_ngram.nx -- token-stream + hash-table count primitives nx_collocation.nx -- PMI / log-likelihood / T-score / log-Dice Caller flow: 1. tokenise corpus into i64 token stream (one ID per word) 2. compute global per-token totals via nx_ng_count (1-grams) 3. call nx_word_sketch_count to fill a collocate table 4. call nx_word_sketch_score_one for each collocate to get log_dice_q10 5. (optional) sort by log_dice and pick top-K No memory allocation inside the primitive — caller supplies all buffers, keeping the substrate scale-agnostic from MCU to HPC. genealogy_id: rychly_2008_logDice + church_hanks_1990_pmi + kilgarriff_2014_sketch_engine lineage_id: positional_word_sketch_v1

dependencies 4 imports · 1 importers

nx_syscalls.nx nx_tier.nx nx_ngram.nx nx_collocation.nx nx_word_sketch.nx nx_word_sketch_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_ngram.nxnx_collocation.nx

imported by: nx_word_sketch_test.nx

structs

none

consts

46const NX_WS_METRIC_PMI: nx_int = 0
47const NX_WS_METRIC_LOG_LIKELIHOOD: nx_int = 1
48const NX_WS_METRIC_T_SCORE: nx_int = 2
49const NX_WS_METRIC_LOG_DICE: nx_int = 3
50const NX_WS_N_METRICS: nx_int = 4
65const NX_WS_KIND_EMPTY: nx_int = 0 // target absent from stream
66const NX_WS_KIND_SPARSE: nx_int = 1 // <5 occurrences -- low confidence
67const NX_WS_KIND_HEALTHY: nx_int = 2 // >=5 occurrences -- publishable
68const NX_WS_KIND_DENSE: nx_int = 3 // >=100 occurrences -- high confidence
69const NX_WS_N_KINDS: nx_int = 4
91const NX_WS_EMPTY_KEY: nx_int = 0

functions

52func nx_ws_metric_is_valid(m: nx_int) -> nx_int
71func nx_ws_kind_is_valid(k: nx_int) -> nx_int
77func nx_ws_classify(n_target_occurrences: nx_int) -> nx_int
called by 1: main
106func nx_word_sketch_count(stream: *i64, stream_len: nx_int,
called by 1: main
173func nx_word_sketch_score_one(n_target: nx_int, n_collocate: nx_int,
called by 1: main calls 1: nx_col_emit_all
185func nx_word_sketch_metric_q10(n_target: nx_int, n_collocate: nx_int,