code wiki / (root) / nx_survey_sentiment.nx

nx_survey_sentiment.nx

buildroot/runtime/nx_survey_sentiment.nx

12111 B194 linesdepth 11pulls 12 transitivereach 4 importersview sourcekind librarytopic survey
docsdependenciesstructsconstsfunctions

about

nx_survey_sentiment.nx -- sovereign open-text SENTIMENT for survey free-text answers. A faithful INTEGER reimplementation of lexicon-based sentiment (VADER-style): a valence lexicon + negation flip + intensifier boost + the VADER compound normalization compound = S / sqrt(S^2 + alpha). EVIDENCE (banked 2024-26, knowledge/library/swc_svy_sent.txt): "VADER", "lexicon-based", "polarity", "Opinion Mining" -- the method is grounded; this adds emotional VALENCE beside the frequency themes so the admin sees not just WHICH words recur but whether the written feedback is warming or cooling. Admin-only: like the theme extractor it reads the free text that is WALLED from every public page (never leaks). All arithmetic is integer fixed-point: valences carry MILLIS (AFINN -4..+4 scale x1000), compound is PERMILLE (-1000..+1000). Deterministic + KAT-exact (gate nx_survey_sentiment_gate). No float, no LLM. Imports quality (which brings stats+engine+seg_store) so the serve layer gets the whole survey lib through one import; st_isqrt (stats) is used for the compound normalization.

dependencies 1 imports · 2 importers

nx_survey_quality.nx nx_survey_sentiment.nx nx_survey_sentiment_gate.nx nx_survey_serve.nx

imports: nx_survey_quality.nx

imported by: nx_survey_sentiment_gate.nxnx_survey_serve.nx

structs

none

consts

14const SN_MAGIC_4096: i64 = 4096
17const SN_BINCR: i64 = 293 // booster/intensifier increment 0.293, applied sign-preserving to |v|
18const SN_NSCALAR: i64 = 0 - 740 // negation scalar -0.74 (flips + dampens a valence in a negation window)
19const SN_NWIN: i64 = 3 // negation look-back window (words) -- VADER's tri-gram
20const SN_ALPHA: i64 = 15000000 // normalization alpha = 15 in millis^2 (15 * 1000 * 1000)
21const SN_POS_TH: i64 = 50 // compound >= +0.05 (+50 permille) => positive (VADER standard)
22const SN_NEG_TH: i64 = 0 - 50 // compound <= -0.05 (-50 permille) => negative
23const SN_MAXLEX: i64 = 400 // lexicon entry bound
29const SN_LEX: *u8 = "love w 3000\nwonderful w 3000\nexcellent w 3000\nfantastic w 3000\namazing w 3000\nperfect w 3000\nawesome w 3000\ngrateful w 2000\nthankful w 2000\nthank w 2000\nthanks w 2000\nappreciate w 2000\nappreciated w 2000\nhappy w 2000\nglad w 2000\npleased w 2000\ngood w 1900\ngreat w 3000\nhelpful w 2000\nhelped w 1900\nhelp w 1000\nsupport w 1900\nsupported w 2000\nsupportive w 2000\ncaring w 2000\nkind w 2000\nkindness w 2000\ngenerous w 2000\nwelcoming w 1900\nfriendly w 1900\nsafe w 1700\nsecure w 1500\ncomfortable w 1500\nhopeful w 1700\nhope w 1400\nblessed w 2200\nrelief w 1900\nrelieved w 2000\nbetter w 1700\nimproved w 1900\nimproving w 1700\nimprovement w 1500\nsatisfied w 1900\nenjoy w 1900\nenjoyed w 1900\nnice w 1500\ngreatly w 1400\neasy w 1200\ncomforting w 1900\nencouraged w 1800\nencouraging w 1800\nwarm w 1200\npositive w 1400\nbad w 0 - 2100\nterrible w 0 - 3000\nawful w 0 - 3000\nhorrible w 0 - 3000\nworst w 0 - 3000\nhate w 0 - 2700\ndifficult w 0 - 1800\nhard w 0 - 1400\nstruggle w 0 - 2000\nstruggling w 0 - 2000\nstruggles w 0 - 2000\nworried w 0 - 2000\nworry w 0 - 1800\nworrying w 0 - 1800\nstress w 0 - 1800\nstressed w 0 - 2000\nstressful w 0 - 1800\nanxious w 0 - 2000\nafraid w 0 - 1900\nscared w 0 - 2000\nangry w 0 - 2300\nupset w 0 - 1800\nfrustrated w 0 - 2100\nfrustrating w 0 - 2100\ndisappointed w 0 - 2000\ndisappointing w 0 - 2000\nsad w 0 - 1800\nlonely w 0 - 1900\nalone w 0 - 1300\npoor w 0 - 1400\nsick w 0 - 1600\nill w 0 - 1500\npain w 0 - 1900\npainful w 0 - 1900\nhungry w 0 - 2000\ntired w 0 - 1200\nexhausted w 0 - 2000\noverwhelmed w 0 - 2100\nconfused w 0 - 1200\nconfusing w 0 - 1300\nlost w 0 - 1200\nbehind w 0 - 1200\nexpensive w 0 - 1200\nunaffordable w 0 - 2200\nbroken w 0 - 1800\nfail w 0 - 2000\nfailed w 0 - 2000\nfailing w 0 - 2000\nproblem w 0 - 1200\nproblems w 0 - 1300\nconcern w 0 - 1000\nconcerned w 0 - 1200\nconcerns w 0 - 1100\nhurt w 0 - 1900\nsuffering w 0 - 2800\ndesperate w 0 - 2900\ncrisis w 0 - 2700\nhomeless w 0 - 2600\neviction w 0 - 2600\nevicted w 0 - 2700\ndebt w 0 - 1600\nunemployed w 0 - 1800\ndepressed w 0 - 2500\ndepressing w 0 - 2200\nhopeless w 0 - 2600\nnegative w 0 - 1400\nnot n 0\nno n 0\nnever n 0\nnone n 0\nnothing n 0\nneither n 0\nnobody n 0\ncannot n 0\ncant n 0\ndont n 0\ndoesnt n 0\ndidnt n 0\nisnt n 0\nwasnt n 0\narent n 0\nwont n 0\nwouldnt n 0\ncouldnt n 0\nshouldnt n 0\nwithout n 0\nhardly n 0\nbarely n 0\nvery i 293\nreally i 293\nextremely i 293\nso i 293\ntoo i 293\nabsolutely i 293\ncompletely i 293\ntotally i 293\nincredibly i 293\nespecially i 293\nslightly i 0 - 293\nsomewhat i 0 - 293\nkinda i 0 - 293\n" as *u8

functions

32func sn_pval(s: *u8) -> i64
called by 1: sn_load
49func sn_load(lex: *u8, words: *i64, kinds: *i64, vals: *i64, cap: i64) -> i64
92func sn_find(words: *i64, n: i64, tok: *u8) -> i64
called by 2: sn_scoremain
101func sn_score(words: *i64, kinds: *i64, vals: *i64, nlex: i64, text: *u8, tlen: i64) -> i64
147func sn_class(compound: i64) -> i64
159func sn_aggregate_over(bv: *i64, bl: *i64, nb: i64, qid: *u8, words: *i64, kinds: *i64, vals: *i64, nlex: i64, out: *i64) -> i64
188func sn_aggregate(prefix: *u8, id: *u8, qid: *u8, words: *i64, kinds: *i64, vals: *i64, nlex: i64, out: *i64) -> i64
called by 1: main calls 2: se_ballotssn_aggregate_over