nx_search_emerge_gate.nx source
↩ module page · 41 lines · 2827 B
1// nx_search_emerge_gate.nx -- deterministic gate for the emergence scorer (NO network): locks year-month
2// extraction, lexical max (= newest), recent-month share, and volume parsing on canned data. Imports the
3// scorer (main stripped) + drives its pure fns.
4import "nx_search_emerge.nx"
5import "nx_syscalls.nx"
6
7func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func gnum(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 }
9func glen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
10func chk(name: *u8, got: i64, want: i64, pass: *i64, fail: *i64) -> i64 {
11 if got==want { pass[0]=pass[0]+1; gp(" ok " as *u8) } else { fail[0]=fail[0]+1; gp(" FAIL " as *u8) }
12 gp(name); gp(" got=" as *u8); gnum(got); gp(" want=" as *u8); gnum(want); gp("\n" as *u8)
13 return 0
14}
15
16func main() -> i64 {
17 gp("=== nx_search_emerge_gate ===\n" as *u8)
18 let pass: *i64=sys_mmap(16) as *i64; let fail: *i64=sys_mmap(16) as *i64; pass[0]=0; fail[0]=0
19
20 // canned arXiv-ish: 3 <published> dates -> 2 in 2026-07 (newest), 1 in 2025-01, + a totalResults
21 let doc: *u8="<opensearch:totalResults>557280</opensearch:totalResults><published>2026-07-22T17:00:00Z</published><published>2026-07-20T09:00:00Z</published><published>2025-01-03T00:00:00Z</published>" as *u8
22 let dl: i64=glen(doc)
23 let flat: *u8=sys_mmap(12*8)
24 let nd: i64=em_collect_yms(doc, dl, "<published>" as *u8, flat, 12)
25 chk("T1 collected 3 year-months" as *u8, nd, 3, pass, fail)
26 let newest: *u8=sys_mmap(8); em_maxym(flat, nd, newest)
27 // newest should be "2026-07" -> assert via em_ymcmp against a literal
28 chk("T2 newest==2026-07" as *u8, em_ymcmp(newest, "2026-07" as *u8), 0, pass, fail)
29 chk("T3 recent-month count==2" as *u8, em_count_eq(flat, nd, "2026-07" as *u8), 2, pass, fail)
30 chk("T4 ymcmp older<newer" as *u8, em_ymcmp("2025-01" as *u8, "2026-07" as *u8), 0-1, pass, fail)
31 chk("T5 total volume==557280" as *u8, em_int_after(doc, dl, "opensearch:totalResults>" as *u8), 557280, pass, fail)
32 // share = 2/3 = 666 permille
33 var share: i64=0; if nd>0 { share=em_count_eq(flat,nd,newest)*1000/nd }
34 chk("T6 recent share==666permille" as *u8, share, 666, pass, fail)
35 // label banding
36 chk("T7 hot label for 666>=EM_HOT" as *u8, share>=EM_HOT, 1, pass, fail)
37
38 gp("\n-- RESULT pass=" as *u8); gnum(pass[0]); gp(" fail=" as *u8); gnum(fail[0]); gp("\n" as *u8)
39 if fail[0]==0 { gp("GATE verdict=GREEN\n" as *u8); sys_exit(0) } else { gp("GATE verdict=RED\n" as *u8); sys_exit(1) }
40 return 0
41}