code wiki / _hdl_build / nx_reader_xray.nx
nx_reader_xray.nx
buildroot/runtime/_hdl_build/nx_reader_xray.nx
about
nx_reader_xray.nx -- SOVEREIGN, ZERO-DEPENDENCY, book-INTRINSIC X-Ray. Operator law: attack the BEHIND "aids
ecosystem" axis of nx_reader_exceed_gate with a REAL capability, not a sovereignty restatement. Kindle's X-Ray
is PROVISIONED-ONLY (exists only where Amazon pre-built the data, so most books show "X-Ray: Not available").
This organ DERIVES an X-Ray from the book's OWN text -- works on ANY book, offline, deterministic, auditable.
Algorithm (deterministic, no random, no external data):
- per chapter, skip the leading duplicate-title lines exactly as nx_reader_render does (index PROSE not headings)
- tokenize into maximal A-Za-z runs; track for each token: capitalized? sentence-initial? space-joined-to-prev?
- a NAME = a maximal run of consecutive capitalized tokens joined ONLY by spaces (so "White Rabbit" is one
entity, but "Alice. Rabbit" is two). A multi-token run always qualifies (proper-noun phrase). A single
capitalized token qualifies only if it is MID-sentence (not sentence-initial) AND not a stopword -- this
is what separates "thought Alice" (entity) from "But when" / "There was" (sentence openers, not entities).
- count occurrences per distinct name + remember the first chapter it appears in (for jump-to-first-mention)
- keep names with count >= MINOCC; sort by count desc, then name asc (fully deterministic)
Emits knowledge/staging/media/reader/<slug>/xray.json + prints a raw scorecard. Reads OUR own book.json +
chap<N>.txt (emitted by nx_epub_book). expect_exit: 0 license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 18 | const K_MAGIC_1000000: i64 = 1000000 |
| 19 | const K_MAGIC_1024: i64 = 1024 |
| 21 | const MAXTERMS: i64 = 512 |
| 22 | const NAMELEN: i64 = 64 |
| 23 | const MAXTOK: i64 = 8192 |
| 24 | const MINOCC: i64 = 2 // a term must recur >=2x to be "notable" (filters one-off caps). TODO: promote to reader svc-config. |
| 25 | const MAXCHAP: i64 = 256 // per-chapter occurrence-distribution cap (concordance); books rarely exceed, distribution truncates beyond |
functions
| 27 | func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 28 | func w(fd: i64, s: *u8) -> i64 { sys_write(fd, s, slen(s)); return 0 } |
| 29 | func wn(fd: i64, v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(fd,"-" as *u8,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(fd,o,k); return 0 } |
| 30 | func p(s: *u8) -> i64 { w(1, s); return 0 } |
| 33 | func jfrom(hay: *u8, hl: i64, start: i64, needle: *u8) -> i64 |
| 39 | func jint(hay: *u8, hl: i64, pos: i64) -> i64 called by 1: main |
| 49 | func jstr(hay: *u8, hl: i64, pos: i64, out: *u8, cap: i64) -> i64 |
| 62 | func jval_str(hay: *u8, hl: i64, key: *u8, out: *u8, cap: i64) -> i64 |
| 69 | func is_upper(c: i64) -> i64 { if c>=65 { if c<=90 { return 1 } } return 0 } called by 1: process_chapter |
| 70 | func is_alpha(c: i64) -> i64 { if c>=65 { if c<=90 { return 1 } } if c>=97 { if c<=122 { return 1 } } return 0 } called by 1: process_chapter |
| 71 | func streq(a: *u8, b: *u8) -> i64 |
| 82 | func strlt(a: *u8, b: *u8) -> i64 called by 1: main |
| 93 | func wesc_json(fd: i64, s: *u8) -> i64 |
| 109 | func is_stopword(s: *u8) -> i64 |
| 176 | func line_eq(txt: *u8, s: i64, e: i64, title: *u8) -> i64 called by 1: skip_title |
| 185 | func skip_title(txt: *u8, n: i64, title: *u8) -> i64 |
| 202 | func tt_register(ctx: *i64, nm: *u8, cidx: i64) -> i64 |
| 234 | func process_chapter(txt: *u8, n: i64, title: *u8, cidx: i64, ctx: *i64) -> i64 |
| 301 | func main(argc: i64, argv: *i64) -> i64 |