code wiki / _hdl_build / nx_brand_voice.nx

nx_brand_voice.nx source

↩ module page · 70 lines · 3041 B

1// nx_brand_voice.nx -- brand VOICE & TONE guidelines as DATA + a basic clarity check. Voice is stored as 2// `voice|<aspect>|<value>` lines (tone / reading-grade / person) alongside the brand; bv_lookup resolves an aspect. 3// bv_clarity_ok flags copy whose longest sentence exceeds a max word count (the measurable core of "plain, on-brand 4// voice"). HONEST SCOPE: this is the guideline + a clarity gate; deep tone rewriting is the Nishi Writer arc. 5// Library. 100% sovereign. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8// resolve a voice aspect: "voice|<aspect>|<value>" -> value into out; return len or -1. 9func bv_lookup(text: *u8, n: i64, aspect: *u8, out: *u8, cap: i64) -> i64 { 10 var alen: i64 = 0; while aspect[alen] != (0 as u8) { alen = alen + 1 } 11 let pipes: *i64 = sys_mmap(64) as *i64 12 var i: i64 = 0 13 while i < n { 14 var le: i64 = i 15 while le < n { if text[le] == (10 as u8) { break } le = le + 1 } 16 var np: i64 = 0 17 var k: i64 = i 18 while k < le { if text[k] == (124 as u8) { if np < 2 { pipes[np] = k; np = np + 1 } } k = k + 1 } 19 if np == 2 { 20 // field0 = [i, pipes[0]) == "voice" ? 21 var isv: i64 = 0 22 if pipes[0] - i == 5 { if text[i]==(118 as u8) { if text[i+1]==(111 as u8) { if text[i+2]==(105 as u8) { if text[i+3]==(99 as u8) { if text[i+4]==(101 as u8) { isv = 1 } } } } } } 23 if isv == 1 { 24 let a0: i64 = pipes[0] + 1; let a1: i64 = pipes[1] 25 var ismatch: i64 = 0 26 if a1 - a0 == alen { ismatch = 1; var j: i64 = 0; while j < alen { if text[a0+j] != aspect[j] { ismatch = 0 } j = j + 1 } } 27 if ismatch == 1 { 28 let vs: i64 = pipes[1] + 1 29 var o: i64 = 0; var p: i64 = vs 30 while p < le { if o < cap - 1 { out[o] = text[p]; o = o + 1 } p = p + 1 } 31 out[o] = 0 as u8 32 return o 33 } 34 } 35 } 36 i = le + 1 37 } 38 return 0 - 1 39} 40 41// longest sentence (split on . ! ?) word count in text[0..n). 42func bv_longest_sentence_words(text: *u8, n: i64) -> i64 { 43 var maxw: i64 = 0; var w: i64 = 0; var inword: i64 = 0 44 var i: i64 = 0 45 while i < n { 46 let c: i64 = text[i] as i64 47 var eos: i64 = 0 48 if c == 46 { eos = 1 } 49 if c == 33 { eos = 1 } 50 if c == 63 { eos = 1 } 51 if eos == 1 { 52 if w > maxw { maxw = w } 53 w = 0; inword = 0 54 } else { 55 var ws: i64 = 0 56 if c == 32 { ws = 1 } 57 if c == 10 { ws = 1 } 58 if c == 9 { ws = 1 } 59 if ws == 1 { inword = 0 } else { if inword == 0 { w = w + 1; inword = 1 } } 60 } 61 i = i + 1 62 } 63 if w > maxw { maxw = w } 64 return maxw 65} 66// 1 iff every sentence is <= max words (clear, on-voice); 0 if any sentence is a run-on. 67func bv_clarity_ok(text: *u8, n: i64, max: i64) -> i64 { 68 if bv_longest_sentence_words(text, n) <= max { return 1 } 69 return 0 70}