code wiki / _hdl_build / nx_night_extract_test.nx

nx_night_extract_test.nx source

↩ module page · 70 lines · 2946 B

1// nx_night_extract_test.nx -- SOVEREIGN render+extract half of the 2// night-reading research rung (W-NIGHT-1). Reads the three raw HTTP 3// responses fetched by nx_night_fetch_test, strips HTTP headers, renders 4// HTML->text with the team's nx_html_to_text, saves the rendered text, and 5// runs the team's deterministic ce_extract (number+unit fact claims) over 6// each. Lives in _hdl_build/ so the import path reaches both nx_claim_extract 7// (here) and nx_html_to_text (../). 8// 9// Division: FETCH + RENDER + EXTRACT all sovereign Nishi; the qualitative 10// "which number means what" reading is the model seat (cited in the rung). 11// 12// expect_exit: 0 13// license_tier: ORIGINAL 14 15import "nx_syscalls.nx" 16import "nx_claim_extract.nx" 17import "nx_html_to_text.nx" 18 19func ne_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 20func ne_putn(v: i64) -> i64 { 21 let bb: *u8 = sys_mmap(28); var m: i64 = v 22 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 23 let t: *u8 = sys_mmap(28); var k: i64 = 0 24 if m == 0 { t[0] = 48 as u8; k = 1 } 25 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 26 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 27} 28 29func render_one(raw_path: *u8, txt_path: *u8) -> i64 { 30 let raw: *u8 = sys_mmap(2097152) 31 let rn: i64 = ce_read_file(raw_path, raw, 2097151) 32 if rn <= 0 { ne_puts(" MISS raw "); ne_puts(raw_path); ne_puts("\n"); return 0 - 1 } 33 34 var bo: i64 = 0 35 var p: i64 = 0 36 while p + 3 < rn { 37 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) { 38 bo = p + 4 39 p = rn 40 } } } } 41 p = p + 1 42 } 43 if bo == 0 { ne_puts(" no header boundary\n"); return 0 - 2 } 44 let body_len: i64 = rn - bo 45 46 let txt: *u8 = sys_mmap(2097152) 47 let tn: i64 = nx_html_to_text((raw as i64 + bo) as *u8, body_len, txt, 2097151) 48 if tn <= 0 { ne_puts(" html_to_text empty\n"); return 0 - 3 } 49 50 let ofd: i64 = sys_openat_wr(txt_path, 0x1A4) 51 if ofd > 0 { sys_write(ofd, txt, tn); sys_close(ofd) } 52 53 let out: *i64 = sys_mmap(64) as *i64 54 ce_extract(txt, tn, out) 55 ne_puts(" "); ne_puts(txt_path) 56 ne_puts(" text="); ne_putn(tn) 57 ne_puts(" sentences="); ne_putn(out[0]) 58 ne_puts(" facts="); ne_putn(out[1]); ne_puts("\n") 59 return out[1] 60} 61 62func main() -> i64 { 63 ne_puts("SOVEREIGN NIGHT-READING EXTRACT (team fetch+render+extract):\n") 64 render_one("knowledge/fetched/night_wcag.raw\x00" as *u8, "knowledge/fetched/night_wcag.txt\x00" as *u8) 65 render_one("knowledge/fetched/night_colortemp.raw\x00" as *u8, "knowledge/fetched/night_colortemp.txt\x00" as *u8) 66 render_one("knowledge/fetched/night_melanopsin.raw\x00" as *u8, "knowledge/fetched/night_melanopsin.txt\x00" as *u8) 67 ne_puts("NIGHT-EXTRACT-DONE\n") 68 sys_exit(0) 69 return 0 70}