nx_dr_run.nx source
↩ module page · 65 lines · 2778 B
1// nx_dr_run.nx -- the REAL-TEXT matching / judge stage (DR-0 rung-2).
2// The five DR organs take pre-computed judge inputs (entail scores, flags, votes). This
3// organ closes the loop: it turns REAL document text + REAL groundtruth-insight strings
4// into REAL insight coverage, so a fetched source produces a real number instead of a
5// fixture. It is the sovereign LEXICAL judge tier -- a djb2-hashed bag-of-tokens with
6// token-containment entailment (the same dv_entail the verifier uses); PPMI (recall lane)
7// and the no-float LLM are the escalation tiers on this same socket (honest tiering, the
8// matching is NOT claimed to be neural-grade).
9// Composes nx_dr_verify (dv_entail). All funcs <=6 params (NAS nx_cc mishandles >6-arg
10// stack spill, debt seq239). Imports drift-immune organs + nx_syscalls. No hw writes (Rule 26).
11//
12// module: nishi-core.research.dr_run
13// depends: nx_dr_verify.nx, nx_syscalls.nx
14// genealogy_id: bag_of_words_1975 + drbench_2026_insight_recall
15import "nx_dr_verify.nx"
16import "nx_syscalls.nx"
17const DRR_MAGIC_5381: i64 = 5381
18
19const DRR_MOD: i64 = 1000000007
20
21func drr_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
22
23// djb2 hash of the lowercased byte range [start,end) in buf -> token id in [0, DRR_MOD).
24func drr_hash(buf: *u8, start: i64, end: i64) -> i64 {
25 var h: i64 = DRR_MAGIC_5381
26 var i: i64 = start
27 while i < end {
28 var c: i64 = buf[i] as i64
29 if c >= 65 { if c <= 90 { c = c + 32 } } // A-Z -> a-z
30 h = (h * 33 + c) % DRR_MOD
31 i = i + 1
32 }
33 return h
34}
35
36// tokenize buf[0,len): split on non-alphanumeric, hash each token -> out_ids[0..count).
37// Deterministic + case-insensitive. Returns the token count (capped at maxn).
38func drr_tokenize(buf: *u8, len: i64, out_ids: *i64, maxn: i64) -> i64 {
39 var cnt: i64 = 0
40 var i: i64 = 0
41 var start: i64 = 0 - 1
42 while i < len {
43 let c: i64 = buf[i] as i64
44 var alnum: i64 = 0
45 if c >= 48 { if c <= 57 { alnum = 1 } }
46 if c >= 65 { if c <= 90 { alnum = 1 } }
47 if c >= 97 { if c <= 122 { alnum = 1 } }
48 if alnum == 1 {
49 if start < 0 { start = i }
50 } else {
51 if start >= 0 {
52 if cnt < maxn { out_ids[cnt] = drr_hash(buf, start, i); cnt = cnt + 1 }
53 start = 0 - 1
54 }
55 }
56 i = i + 1
57 }
58 if start >= 0 { if cnt < maxn { out_ids[cnt] = drr_hash(buf, start, len); cnt = cnt + 1 } }
59 return cnt
60}
61
62// is `ins` (token ids) covered by `doc` at `threshold` permille? (containment via dv_entail.)
63func drr_covered(ins: *i64, ni: i64, doc: *i64, nd: i64, threshold: i64) -> i64 {
64 if dv_entail(ins, ni, doc, nd) >= threshold { return 1 } else { return 0 }
65}