code wiki / (root) / nx_uxf_extract.nx

nx_uxf_extract.nx source

↩ module page · 152 lines · 7405 B

1// nx_uxf_extract.nx -- UXF arc R1b-3: the DATA-DRIVEN multi-source EXTRACT + CORROBORATION 2// pass (Rule 11 data-driven, Rule 15 DRY -- one extractor for every source, no per-source 3// clones). Reads a manifest knowledge/staging/uxf/raws.tsv (lines: <label>\t<raw-path>), 4// and for EACH source runs the proven pipeline: 5// sys_read_file -> split header/body at CRLFCRLF -> nx_http_dechunk (fallback to body 6// as-is) -> nx_html_to_text_x -> pattern-count a broadened decoupling term set. 7// Then reports CROSS-SOURCE corroboration (a concept present in >=2 sources = corroborated, 8// the researcher's admission rule). Mechanical (terminology-literal) -- NOT semantic NLP. 9// No hardware/persistent writes (Rule 26). expect_exit: 0 license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_http_dechunk.nx" 12import "nx_html_to_text.nx" 13const K_MAGIC_4194304: i64 = 4194304 14 15func ux_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 16func ux_putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 } 17func ux_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 18 19func ux_count(text: *u8, n: i64, term: *u8) -> i64 { 20 let m: i64 = ux_slen(term) 21 if m == 0 { return 0 } 22 var c: i64 = 0 23 var i: i64 = 0 24 while (i + m) <= n { 25 var j: i64 = 0 26 var ok: i64 = 1 27 while j < m { if text[i + j] != term[j] { ok = 0; j = m } else { j = j + 1 } } 28 if ok == 1 { c = c + 1; i = i + m } else { i = i + 1 } 29 } 30 return c 31} 32 33func ux_find_byte(buf: *u8, start: i64, end: i64, b: i64) -> i64 { 34 var i: i64 = start 35 while i < end { if (buf[i] as i64) == b { return i } i = i + 1 } 36 return end 37} 38 39func ux_copyz(src: *u8, a: i64, b: i64, dst: *u8, dstcap: i64) -> i64 { 40 let len: i64 = b - a 41 if (len + 1) > dstcap { return 0 - 1 } 42 var i: i64 = 0 43 while i < len { dst[i] = src[a + i]; i = i + 1 } 44 dst[len] = 0 as u8 45 return len 46} 47 48func ux_body_off(raw: *u8, n: i64) -> i64 { 49 var i: i64 = 0 50 while (i + 4) <= n { 51 if raw[i] == (0x0D as u8) { if raw[i+1] == (0x0A as u8) { if raw[i+2] == (0x0D as u8) { if raw[i+3] == (0x0A as u8) { return i + 4 } } } } 52 i = i + 1 53 } 54 return 0 - 1 55} 56 57// process one raw file: pipeline + 8 concept counts; write 1/0 hit-flags into hits[0..8). 58func ux_process(rawpath: *u8, label: *u8, hits: *i64) -> i64 { 59 let lenp: *i64 = sys_mmap(8) as *i64 60 let raw: *u8 = sys_read_file(rawpath, lenp) 61 if (raw as i64) == 0 { ux_puts(" [" as *u8); ux_puts(label); ux_puts("] raw not found\n" as *u8); return 0 - 1 } 62 let rawlen: i64 = lenp[0] 63 if rawlen <= 0 { ux_puts(" [" as *u8); ux_puts(label); ux_puts("] raw empty\n" as *u8); return 0 - 1 } 64 let boff: i64 = ux_body_off(raw, rawlen) 65 if boff < 0 { ux_puts(" [" as *u8); ux_puts(label); ux_puts("] no header/body split\n" as *u8); return 0 - 1 } 66 let body: *u8 = ((raw as i64) + boff) as *u8 67 let bodylen: i64 = rawlen - boff 68 let html: *u8 = sys_mmap(K_MAGIC_4194304) 69 var srcptr: *u8 = html 70 var srclen: i64 = nx_http_dechunk(body, bodylen, html, K_MAGIC_4194304) 71 if srclen < 0 { srcptr = body; srclen = bodylen } 72 let text: *u8 = sys_mmap(K_MAGIC_4194304) 73 let textlen: i64 = nx_html_to_text_x(srcptr, srclen, text, K_MAGIC_4194304, 0) 74 if textlen <= 0 { ux_puts(" [" as *u8); ux_puts(label); ux_puts("] no text rendered\n" as *u8); return 0 - 1 } 75 76 let c0: i64 = ux_count(text, textlen, "schema" as *u8) 77 let c1: i64 = ux_count(text, textlen, "reader" as *u8) 78 let c2: i64 = ux_count(text, textlen, "writer" as *u8) 79 let c3: i64 = ux_count(text, textlen, "evolution" as *u8) 80 let c4: i64 = ux_count(text, textlen, "compatib" as *u8) 81 let c5: i64 = ux_count(text, textlen, "reserved" as *u8) 82 let c6: i64 = ux_count(text, textlen, "backward" as *u8) 83 let c7: i64 = ux_count(text, textlen, "without knowing the schema" as *u8) 84 85 hits[0] = 0; if c0 > 0 { hits[0] = 1 } 86 hits[1] = 0; if c1 > 0 { hits[1] = 1 } 87 hits[2] = 0; if c2 > 0 { hits[2] = 1 } 88 hits[3] = 0; if c3 > 0 { hits[3] = 1 } 89 hits[4] = 0; if c4 > 0 { hits[4] = 1 } 90 hits[5] = 0; if c5 > 0 { hits[5] = 1 } 91 hits[6] = 0; if c6 > 0 { hits[6] = 1 } 92 hits[7] = 0; if c7 > 0 { hits[7] = 1 } 93 94 ux_puts(" [" as *u8); ux_puts(label); ux_puts("] text=" as *u8); ux_putn(textlen) 95 ux_puts(" schema=" as *u8); ux_putn(c0) 96 ux_puts(" reader=" as *u8); ux_putn(c1) 97 ux_puts(" writer=" as *u8); ux_putn(c2) 98 ux_puts(" evolution=" as *u8); ux_putn(c3) 99 ux_puts(" compatib=" as *u8); ux_putn(c4) 100 ux_puts(" reserved=" as *u8); ux_putn(c5) 101 ux_puts(" backward=" as *u8); ux_putn(c6) 102 ux_puts(" self-desc-phrase=" as *u8); ux_putn(c7) 103 ux_puts("\n" as *u8) 104 return 0 105} 106 107func main() -> i64 { 108 let lenp: *i64 = sys_mmap(8) as *i64 109 let man: *u8 = sys_read_file("knowledge/staging/uxf/raws.tsv\x00", lenp) 110 if (man as i64) == 0 { ux_puts("R1b-3: manifest knowledge/staging/uxf/raws.tsv not found\n" as *u8); sys_exit(1); return 1 } 111 let mn: i64 = lenp[0] 112 ux_puts("R1b-3 MULTI-SOURCE EXTRACT (data-driven over raws.tsv)\n" as *u8) 113 114 let labelbuf: *u8 = sys_mmap(256) 115 let pathbuf: *u8 = sys_mmap(512) 116 let hits: *i64 = sys_mmap(64) as *i64 117 let acc: *i64 = sys_mmap(64) as *i64 118 var z: i64 = 0 119 while z < 8 { acc[z] = 0; z = z + 1 } 120 var nsrc: i64 = 0 121 122 var i: i64 = 0 123 while i < mn { 124 let nl: i64 = ux_find_byte(man, i, mn, 0x0A) 125 var lineend: i64 = nl 126 if lineend > i { if man[lineend - 1] == (0x0D as u8) { lineend = lineend - 1 } } 127 if lineend > i { 128 let tab: i64 = ux_find_byte(man, i, lineend, 0x09) 129 if tab < lineend { 130 ux_copyz(man, i, tab, labelbuf, 256) 131 ux_copyz(man, tab + 1, lineend, pathbuf, 512) 132 if ux_process(pathbuf, labelbuf, hits) == 0 { 133 var k: i64 = 0 134 while k < 8 { acc[k] = acc[k] + hits[k]; k = k + 1 } 135 nsrc = nsrc + 1 136 } 137 } 138 } 139 i = nl + 1 140 } 141 142 ux_puts("CORROBORATION across " as *u8); ux_putn(nsrc); ux_puts(" sources (present-in-N; >=2 = corroborated):\n" as *u8) 143 ux_puts(" schema=" as *u8); ux_putn(acc[0]); ux_puts(" reader=" as *u8); ux_putn(acc[1]); ux_puts(" writer=" as *u8); ux_putn(acc[2]); ux_puts(" evolution=" as *u8); ux_putn(acc[3]); ux_puts(" compatib=" as *u8); ux_putn(acc[4]); ux_puts(" reserved=" as *u8); ux_putn(acc[5]); ux_puts(" backward=" as *u8); ux_putn(acc[6]); ux_puts(" self-desc=" as *u8); ux_putn(acc[7]); ux_puts("\n" as *u8) 144 145 var corrob: i64 = 0 146 var k2: i64 = 0 147 while k2 < 8 { if acc[k2] >= 2 { corrob = corrob + 1 } k2 = k2 + 1 } 148 ux_puts("corroborated_concepts = " as *u8); ux_putn(corrob); ux_puts("/8\n" as *u8) 149 if nsrc >= 2 { ux_puts("R1b-3 verdict=GREEN (data-driven multi-source extract + corroboration, sovereign)\n" as *u8); sys_exit(0); return 0 } 150 ux_puts("R1b-3 verdict=RED (need >=2 sources)\n" as *u8) 151 sys_exit(2); return 2 152}