nx_descriptor.nx source
↩ module page · 50 lines · 2210 B
1// nx_descriptor.nx -- WRITING arc, rung W-ING-2: the scene -> IMAGE-GEN descriptor
2// profiler. Rides on the scene structure from nx_ingest (W-ING-1): given a
3// DESCRIPTOR LEXICON (packed terms + a parallel category id per term), it reports,
4// per scene, how many descriptor hits fall in each category -> the structured
5// fields image-gen turns into a prompt (setting / time-of-day / mood / weather /
6// outfit / ... -- the categories are the caller's DATA, not baked in here).
7//
8// The LEXICON is DATA (rule 25): the SFW lane and the operator's local-LLM lane
9// each extend it (outfit/MPL terms, register-specific terms) WITHOUT touching this
10// organ. This file ships only the content-agnostic MECHANISM; the gate proves it
11// with benign terms (forest/castle/night/dawn/...).
12//
13// Matching reuses nx_ingest's WHOLE-WORD, case-insensitive counter (DRY), so
14// "forestry" does not count as "forest" and "midnight" does not count as "night".
15//
16// dx_profile(t, a, b, terms, cats, nterms, ncat, prof)
17// prof[c] = total descriptor hits in category c over t[a..b)
18// returns total hits across all categories.
19// Pipeline: ig_extract (segment) -> dx_profile per scene range -> image-gen.
20//
21// Pure integer, NO syscalls. Reuses nx_ingest (-> nx_writecraft).
22//
23// license_tier: ORIGINAL
24// module: nishi-core.write.descriptor
25// depends: nishi-core.write.ingest
26// capability: WRITE_SCENE_DESCRIPTORS
27import "nx_ingest.nx"
28import "nx_ingest_scene.nx" // ig_* scene/entity extractor
29
30// fill prof[0..ncat) with per-category descriptor hit counts over t[a..b);
31// returns the total number of hits.
32func dx_profile(t: *u8, a: i64, b: i64, terms: *u8, cats: *i64, nterms: i64, ncat: i64, prof: *i64) -> i64 {
33 var c: i64 = 0
34 while c < ncat { prof[c] = 0; c = c + 1 }
35 var total: i64 = 0
36 var k: i64 = 0
37 while k < nterms {
38 let off: i64 = ig_name_off(terms, k)
39 let cnt: i64 = ig_count_name_in(t, a, b, terms, off)
40 if cnt > 0 {
41 let cat: i64 = cats[k]
42 if cat >= 0 {
43 if cat < ncat { prof[cat] = prof[cat] + cnt }
44 }
45 total = total + cnt
46 }
47 k = k + 1
48 }
49 return total
50}