code wiki / _hdl_build / nx_langintel_axismap.nx
nx_langintel_axismap.nx source
↩ module page · 170 lines · 6747 B
1// nx_langintel_axismap.nx -- LangIntel LI5 v3: DATA-DRIVEN source-agnostic classifier (LADDER stage 2).
2// Keyword->axis table is now a HOT-READ conf (knowledge/status/langintel_axiskw.conf, keyword TAB axis),
3// matched CASE-INSENSITIVELY (title lowercased) -- add axes/keywords with NO reship (rule 6 data-driven,
4// the nx_triage pattern). First conf-row match wins (order = priority); no match -> soundness-other.
5// Input+output planes = argv. SUBCLASS of nx_ingest_base (adopts ib_read/ib_find/ib_werr/ib_wn/ib_refuse).
6// license_tier: ORACLE-INDEX No hw writes (Rule 26). expect_exit: 0
7import "nx_ingest_base.nx"
8import "nx_store_seed_lib.nx"
9import "nx_syscalls.nx"
10
11const AX_CAP: i64 = 1048576
12const AX_OCAP: i64 = 262144
13const AX_CONFCAP: i64 = 65536
14const AX_TAB: i64 = 9
15const AX_NL: i64 = 10
16const AX_STDERR: i64 = 2
17const AX_MAXCOL: i64 = 8
18const AX_PAIR: i64 = 2
19const AX_SPB: i64 = 128
20const AX_VCAP: i64 = 1024
21const AX_UA: i64 = 65
22const AX_UZ: i64 = 90
23const AX_CASE: i64 = 32
24const AX_ARGC_MIN: i64 = 3
25const AX_EXIT_USAGE: i64 = 2
26const AX_EXIT_IO: i64 = 1
27const AX_EXIT_RED: i64 = 3
28const AX_CONF: *u8 = "knowledge/status/langintel_axiskw.conf" as *u8
29const AX_OTHER: *u8 = "soundness-other" as *u8
30
31static g_out: *u8
32static g_o: i64
33static g_rows: i64
34
35func ax_emit(s: *u8) -> i64 {
36 var j: i64 = 0
37 while s[j] != (0 as u8) { if g_o < AX_OCAP - 2 { g_out[g_o] = s[j]; g_o = g_o + 1 } j = j + 1 }
38 return 0
39}
40func ax_emitc(c: i64) -> i64 { if g_o < AX_OCAP - 2 { g_out[g_o] = c as u8; g_o = g_o + 1 } return 0 }
41func ax_emit_slice(q: *u8, a: i64, b: i64) -> i64 {
42 var i: i64 = a
43 while i < b { if g_o < AX_OCAP - 2 { g_out[g_o] = q[i]; g_o = g_o + 1 } i = i + 1 }
44 return 0
45}
46func ax_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 {
47 var c: i64 = 0
48 var p: i64 = ls
49 while c < AX_MAXCOL {
50 var e: i64 = p
51 var s: i64 = 1
52 while s == 1 { if e >= le { s = 0 } else { if q[e] == (AX_TAB as u8) { s = 0 } else { e = e + 1 } } }
53 sp[c*AX_PAIR] = p
54 sp[c*AX_PAIR+1] = e
55 c = c + 1
56 if e >= le { return c }
57 p = e + 1
58 }
59 return c
60}
61// lowercase slice [a,b) of q into dst (NUL-term); return length
62func ax_lower(dst: *u8, q: *u8, a: i64, b: i64) -> i64 {
63 var k: i64 = 0
64 var i: i64 = a
65 while i < b { var c: i64 = q[i] as i64; if c >= AX_UA { if c <= AX_UZ { c = c + AX_CASE } } dst[k] = c as u8; k = k + 1; i = i + 1 }
66 dst[k] = 0 as u8
67 return k
68}
69// scan conf (keyword TAB axis per line); if lowercased title contains a keyword, copy its axis into
70// axisbuf (NUL-term) and return 1; else return 0. kwbuf is scratch for the NUL-term needle.
71func ax_match(conf: *u8, cn: i64, lt: *u8, ltn: i64, kwbuf: *u8, axisbuf: *u8) -> i64 {
72 var i: i64 = 0
73 while i < cn {
74 var le: i64 = i
75 var s: i64 = 1
76 while s == 1 { if le >= cn { s = 0 } else { if conf[le] == (AX_NL as u8) { s = 0 } else { le = le + 1 } } }
77 if le > i {
78 var tab: i64 = i
79 var ft: i64 = 1
80 while ft == 1 { if tab >= le { ft = 0 } else { if conf[tab] == (AX_TAB as u8) { ft = 0 } else { tab = tab + 1 } } }
81 if tab < le {
82 var k: i64 = 0
83 var j: i64 = i
84 while j < tab { kwbuf[k] = conf[j]; k = k + 1; j = j + 1 }
85 kwbuf[k] = 0 as u8
86 if k > 0 { if ib_find(lt, ltn, kwbuf, 0) >= 0 {
87 var k2: i64 = 0
88 var j2: i64 = tab + 1
89 while j2 < le { axisbuf[k2] = conf[j2]; k2 = k2 + 1; j2 = j2 + 1 }
90 axisbuf[k2] = 0 as u8
91 return 1
92 } }
93 }
94 }
95 i = le + 1
96 }
97 return 0
98}
99
100func main(argc: i64, argv: *i64) -> i64 {
101 if argc < AX_ARGC_MIN {
102 ib_refuse("LANGINTEL-AXISMAP" as *u8, "missing args <input-plane> <output-plane>" as *u8, "seed a plan row: 1 TAB nx_langintel_axismap TAB <in-plane> TAB <out-plane>" as *u8)
103 sys_exit(AX_EXIT_USAGE)
104 return AX_EXIT_USAGE
105 }
106 let in_plane: *u8 = argv[1] as *u8
107 let out_plane: *u8 = argv[2] as *u8
108 let conf: *u8 = sys_mmap(AX_CONFCAP)
109 let cn: i64 = ib_read(AX_CONF, conf, AX_CONFCAP)
110 if cn <= 0 {
111 ib_refuse("LANGINTEL-AXISMAP" as *u8, "keyword conf absent/empty" as *u8, "write knowledge/status/langintel_axiskw.conf with 'keyword TAB axis' rows (hot-read, no reship)" as *u8)
112 sys_exit(AX_EXIT_IO)
113 return AX_EXIT_IO
114 }
115 g_out = sys_mmap(AX_OCAP)
116 g_o = 0
117 g_rows = 0
118 let plane: *u8 = sys_mmap(AX_CAP)
119 let n: i64 = sts_load(in_plane, plane, AX_CAP)
120 if n <= 0 {
121 ib_refuse("LANGINTEL-AXISMAP" as *u8, "input plane EMPTY" as *u8, "run the ingest connector first (nx_plan_run langintelrun / llvmrun)" as *u8)
122 sys_exit(AX_EXIT_IO)
123 return AX_EXIT_IO
124 }
125 let sp: *i64 = sys_mmap(AX_SPB) as *i64
126 let lt: *u8 = sys_mmap(AX_VCAP)
127 let kwbuf: *u8 = sys_mmap(AX_VCAP)
128 let axisbuf: *u8 = sys_mmap(AX_VCAP)
129 var i: i64 = 0
130 while i < n {
131 var le: i64 = i
132 var s: i64 = 1
133 while s == 1 { if le >= n { s = 0 } else { if plane[le] == (AX_NL as u8) { s = 0 } else { le = le + 1 } } }
134 if le > i {
135 let nc: i64 = ax_cols(plane, i, le, sp)
136 if nc >= 6 {
137 let ltn: i64 = ax_lower(lt, plane, sp[10], sp[11])
138 let found: i64 = ax_match(conf, cn, lt, ltn, kwbuf, axisbuf)
139 ax_emit_slice(plane, sp[0], sp[1])
140 ax_emitc(AX_TAB)
141 if found == 1 { ax_emit(axisbuf) } else { ax_emit(AX_OTHER) }
142 ax_emitc(AX_TAB)
143 ax_emit("GAP" as *u8)
144 ax_emitc(AX_TAB)
145 ax_emit_slice(plane, sp[6], sp[7])
146 ax_emitc(AX_TAB)
147 ax_emit_slice(plane, sp[10], sp[11])
148 ax_emitc(AX_NL)
149 g_rows = g_rows + 1
150 }
151 }
152 i = le + 1
153 }
154 if g_rows < 1 {
155 ib_refuse("LANGINTEL-AXISMAP" as *u8, "0 rows classified" as *u8, "verify input rows have >=6 TAB cols (number/state/flag/url/hash/title)" as *u8)
156 sys_exit(AX_EXIT_RED)
157 return AX_EXIT_RED
158 }
159 let rc: i64 = sts_seed(out_plane, g_out, g_o)
160 if rc < 0 {
161 ib_refuse("LANGINTEL-AXISMAP" as *u8, "store commit failed" as *u8, "check seg-store health for the output plane; retry" as *u8)
162 sys_exit(AX_EXIT_IO)
163 return AX_EXIT_IO
164 }
165 ib_werr("LANGINTEL-AXISMAP OK verdict=GREEN rows=" as *u8)
166 ib_wn(AX_STDERR, g_rows)
167 ib_werr(" (data-driven keyword conf; real bugs -> NishiLang capability axes; GAP per 0/184 prim void)\n" as *u8)
168 sys_exit(0)
169 return 0
170}