code wiki / _hdl_build / nx_library_extract.nx

nx_library_extract.nx source

↩ module page · 75 lines · 3398 B

1// nx_library_extract.nx -- SOVEREIGN render+extract half of the digital-library 2// best-practices research rung (L-R1a). Reads the six raw HTTP responses fetched 3// by nx_library_fetch, strips HTTP headers, renders HTML->text with the team's 4// nx_html_to_text, saves the rendered text, and runs the team's deterministic 5// ce_extract (number+unit fact claims) over each. Lives in _hdl_build/ so the 6// import path reaches both nx_claim_extract (here) and nx_html_to_text (../). 7// 8// Division: FETCH + RENDER + EXTRACT all sovereign Nishi; the qualitative 9// "which sentence states which best practice" reading is the model seat 10// (cited verbatim in the sourced research doc). 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" 18const K_MAGIC_4194304: i64 = 4194304 19const K_MAGIC_4194303: i64 = 4194303 20 21func le_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 22func le_putn(v: i64) -> i64 { 23 let bb: *u8 = sys_mmap(28); var m: i64 = v 24 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 25 let t: *u8 = sys_mmap(28); var k: i64 = 0 26 if m == 0 { t[0] = 48 as u8; k = 1 } 27 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 28 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 29} 30 31func render_one(raw_path: *u8, txt_path: *u8) -> i64 { 32 let raw: *u8 = sys_mmap(K_MAGIC_4194304) 33 let rn: i64 = ce_read_file(raw_path, raw, K_MAGIC_4194303) 34 if rn <= 0 { le_puts(" MISS raw "); le_puts(raw_path); le_puts("\n"); return 0 - 1 } 35 36 var bo: i64 = 0 37 var p: i64 = 0 38 while p + 3 < rn { 39 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) { 40 bo = p + 4 41 p = rn 42 } } } } 43 p = p + 1 44 } 45 if bo == 0 { le_puts(" no header boundary\n"); return 0 - 2 } 46 let body_len: i64 = rn - bo 47 48 let txt: *u8 = sys_mmap(K_MAGIC_4194304) 49 let tn: i64 = nx_html_to_text((raw as i64 + bo) as *u8, body_len, txt, K_MAGIC_4194303) 50 if tn <= 0 { le_puts(" html_to_text empty\n"); return 0 - 3 } 51 52 let ofd: i64 = sys_openat_wr(txt_path, 0x1A4) 53 if ofd > 0 { sys_write(ofd, txt, tn); sys_close(ofd) } 54 55 let out: *i64 = sys_mmap(64) as *i64 56 ce_extract(txt, tn, out) 57 le_puts(" "); le_puts(txt_path) 58 le_puts(" text="); le_putn(tn) 59 le_puts(" sentences="); le_putn(out[0]) 60 le_puts(" facts="); le_putn(out[1]); le_puts("\n") 61 return out[1] 62} 63 64func main() -> i64 { 65 le_puts("SOVEREIGN DIGITAL-LIBRARY EXTRACT (team fetch+render+extract):\n") 66 render_one("knowledge/fetched/lib_opds.raw\x00" as *u8, "knowledge/fetched/lib_opds.txt\x00" as *u8) 67 render_one("knowledge/fetched/lib_diglib.raw\x00" as *u8, "knowledge/fetched/lib_diglib.txt\x00" as *u8) 68 render_one("knowledge/fetched/lib_dublin.raw\x00" as *u8, "knowledge/fetched/lib_dublin.txt\x00" as *u8) 69 render_one("knowledge/fetched/lib_epub.raw\x00" as *u8, "knowledge/fetched/lib_epub.txt\x00" as *u8) 70 render_one("knowledge/fetched/lib_bm25.raw\x00" as *u8, "knowledge/fetched/lib_bm25.txt\x00" as *u8) 71 render_one("knowledge/fetched/lib_facet.raw\x00" as *u8, "knowledge/fetched/lib_facet.txt\x00" as *u8) 72 le_puts("LIB-EXTRACT-DONE\n") 73 sys_exit(0) 74 return 0 75}