code wiki / _hdl_build / nx_research_extract_sovereign_test.nx
nx_research_extract_sovereign_test.nx source
↩ module page · 77 lines · 3433 B
1// nx_research_extract_sovereign_test.nx -- the SOVEREIGN half of the
2// B3 research loop, now fed by the TEAM's OWN fetch (no Playwright).
3//
4// Reads the sovereign-fetched raw HTTP response
5// knowledge/fetched/wiki_web_dev_sovereign.raw (from nx_research_fetch_wiki)
6// strips the HTTP headers (\r\n\r\n boundary), renders HTML->text with the
7// team's nx_html_to_text, saves the rendered text to
8// knowledge/fetched/wiki_web_dev_sovereign.txt
9// (apples-to-apples with the Playwright benchmark's wiki_web_dev.txt),
10// then drives the team's deterministic ce_extract over it.
11//
12// Division (unchanged): FETCH = sovereign (was the Playwright benchmark);
13// RENDER + EXTRACT = sovereign Nishi; only the qualitative prose->feature
14// semantic residual is the LLM/Nishi-AI seat.
15//
16// Lives in _hdl_build/ so the import search reaches BOTH nx_claim_extract
17// (here) and nx_html_to_text (../).
18//
19// expect_exit: 0
20// license_tier: ORIGINAL
21
22import "nx_syscalls.nx"
23import "nx_claim_extract.nx"
24import "nx_html_to_text.nx"
25
26func rr_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
27func rr_putn(v: i64) -> i64 {
28 let bb: *u8=sys_mmap(28); var m: i64=v
29 if m<0{m=0-m;sys_write(1,"-" as *u8,1)}
30 let t: *u8=sys_mmap(28); var k: i64=0
31 if m==0{t[0]=48 as u8;k=1}
32 while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}
33 var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0
34}
35
36func main() -> i64 {
37 let raw: *u8 = sys_mmap(2097152)
38 let rn: i64 = ce_read_file("knowledge/fetched/wiki_web_dev_sovereign.raw" as *u8, raw, 2097151)
39 if rn <= 0 { rr_puts("SOV-EXTRACT: raw fetch file not found/empty\n" as *u8); sys_exit(1); return 1 }
40
41 // ---- Find the HTTP header/body boundary (\r\n\r\n) ----
42 var bo: i64 = 0
43 var p: i64 = 0
44 while p + 3 < rn {
45 if raw[p]==(13 as u8) { if raw[p+1]==(10 as u8) { if raw[p+2]==(13 as u8) { if raw[p+3]==(10 as u8) {
46 bo = p + 4
47 p = rn
48 } } } }
49 p = p + 1
50 }
51 if bo == 0 { rr_puts("SOV-EXTRACT: no header/body boundary found\n" as *u8); sys_exit(2); return 2 }
52 let body_len: i64 = rn - bo
53
54 // ---- Sovereign HTML -> text render ----
55 let txt: *u8 = sys_mmap(2097152)
56 let tn: i64 = nx_html_to_text((raw as i64 + bo) as *u8, body_len, txt, 2097151)
57 if tn <= 0 { rr_puts("SOV-EXTRACT: html_to_text produced no text\n" as *u8); sys_exit(3); return 3 }
58
59 // ---- Persist rendered text (apples-to-apples vs Playwright file) ----
60 let ofd: i64 = sys_openat_wr("knowledge/fetched/wiki_web_dev_sovereign.txt\x00" as *u8, 0x1A4)
61 if ofd > 0 { sys_write(ofd, txt, tn); sys_close(ofd) }
62
63 // ---- Team's deterministic extract over the SOVEREIGN text ----
64 let out: *i64 = sys_mmap(64) as *i64
65 let facts: i64 = ce_extract(txt, tn, out)
66
67 rr_puts("SOVEREIGN RESEARCH EXTRACT (no Playwright; team fetch+render+extract):\n raw_bytes=" as *u8); rr_putn(rn)
68 rr_puts("\n header_bytes=" as *u8); rr_putn(bo)
69 rr_puts("\n html_body_bytes=" as *u8); rr_putn(body_len)
70 rr_puts("\n rendered_text_bytes=" as *u8); rr_putn(tn)
71 rr_puts("\n sentences=" as *u8); rr_putn(out[0])
72 rr_puts("\n fact_claims(number+unit)=" as *u8); rr_putn(out[1])
73 rr_puts("\n first_claim_value=" as *u8); rr_putn(out[2])
74 rr_puts("\n (FETCH now sovereign; Playwright = benchmark only)\n" as *u8)
75 sys_exit(0)
76 return 0
77}