nx_word_sketch.nx
buildroot/runtime/nx_word_sketch.nx
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
imports: nx_syscalls.nxnx_tier.nxnx_ngram.nxnx_collocation.nx
imported by: nx_word_sketch_test.nx
structs
| none |
consts
| 46 | const NX_WS_METRIC_PMI: nx_int = 0 |
| 47 | const NX_WS_METRIC_LOG_LIKELIHOOD: nx_int = 1 |
| 48 | const NX_WS_METRIC_T_SCORE: nx_int = 2 |
| 49 | const NX_WS_METRIC_LOG_DICE: nx_int = 3 |
| 50 | const NX_WS_N_METRICS: nx_int = 4 |
| 65 | const NX_WS_KIND_EMPTY: nx_int = 0 // target absent from stream |
| 66 | const NX_WS_KIND_SPARSE: nx_int = 1 // <5 occurrences -- low confidence |
| 67 | const NX_WS_KIND_HEALTHY: nx_int = 2 // >=5 occurrences -- publishable |
| 68 | const NX_WS_KIND_DENSE: nx_int = 3 // >=100 occurrences -- high confidence |
| 69 | const NX_WS_N_KINDS: nx_int = 4 |
| 91 | const NX_WS_EMPTY_KEY: nx_int = 0 |
functions
| 52 | func nx_ws_metric_is_valid(m: nx_int) -> nx_int |
| 71 | func nx_ws_kind_is_valid(k: nx_int) -> nx_int |
| 77 | func nx_ws_classify(n_target_occurrences: nx_int) -> nx_int called by 1: main |
| 106 | func nx_word_sketch_count(stream: *i64, stream_len: nx_int, called by 1: main |
| 173 | func nx_word_sketch_score_one(n_target: nx_int, n_collocate: nx_int, |
| 185 | func nx_word_sketch_metric_q10(n_target: nx_int, n_collocate: nx_int, called by 1: main calls 4: nx_col_pmi_q10nx_col_log_likelihood_q10nx_col_t_score_q10nx_col_log_dice_q10 |