code wiki / (root) / nx_citator_lib.nx

nx_citator_lib.nx source

↩ module page · 123 lines · 5325 B

1// nx_citator_lib.nx -- F995: CITATION TREATMENT SIGNALS (Shepard's / KeyCite analog), on the CID plane. 2// 3// Verifying that a quote is REAL (nx_cite) is necessary but not sufficient: a perfectly real quote from 4// a case that has since been OVERRULED is bad law, and relying on it is malpractice. This layer records 5// how later authorities TREAT an earlier one, and answers the question a citator exists to answer: is 6// this still good law? 7// 8// Treatment vocabulary (a DECLARED data contract; severity = how much it undercuts reliance): 9// followed severity 0 positive, reinforces 10// distinguished severity 1 caution, limited to its facts 11// questioned severity 2 caution, reliability doubted 12// overruled severity 3 NEGATIVE -- no longer good law 13// 14// ★WORST-WINS: a case's status is the MAX severity across every treatment of it. One overruling kills 15// reliance no matter how many later courts followed it -- you cannot average away dead law. This is the 16// bright line: good_law == (worst severity < overruled). 17// 18// ★COMPOSES nx_cite: cit_safe_to_cite passes ONLY if the quote verifies (real span of a real source) 19// AND the cited authority is still good law. So a real quote from overruled law is UNSAFE -- the exact 20// trap a citator prevents and a chatbot walks straight into. 21// 22// SCALE ENVELOPE (declared): cit_status scans the treatment index for the cited case's key-prefix 23// (mirrors the proven trust-ledger per-key scan) -- O(total-treatments); a per-case index is the rung. 24// DRY: composes nx_cite_lib (cite_ok) + nx_matter_lib (reg_*/mt_*/canon_encode). license_tier: ORIGINAL LIB. 25 26import "nx_cite_lib.nx" 27const CIT_MAGIC_1048576: i64 = 1048576 28 29const CIT_COLON: i64 = 58 30 31// map a treatment string to its severity (unknown -> 0, a declared-vocabulary data error, not a crash). 32func cit_sev(t: *u8) -> i64 { 33 if mt_streq(t, "overruled" as *u8) == 1 { return 3 } 34 if mt_streq(t, "questioned" as *u8) == 1 { return 2 } 35 if mt_streq(t, "distinguished" as *u8) == 1 { return 1 } 36 if mt_streq(t, "followed" as *u8) == 1 { return 0 } 37 return 0 38} 39 40// record that `citing` treats `cited` with `treatment`. key = "<cited>:<citing>" so all treatments of a 41// cited case share its key-prefix and can be swept. 42func cit_treat_put(prefix: *u8, cited: *u8, citing: *u8, treatment: *u8) -> i64 { 43 let id: *u8 = sys_mmap(256) 44 var o: i64 = mt_catcopy(id, 0, cited) 45 id[o] = CIT_COLON as u8 46 o = o + 1 47 o = mt_catcopy(id, o, citing) 48 id[o] = 0 as u8 49 let k: *i64 = sys_mmap(8 * 2) as *i64 50 let v: *i64 = sys_mmap(8 * 2) as *i64 51 k[0] = ("treatment" as *u8) as i64 52 v[0] = treatment as i64 53 k[1] = ("citing" as *u8) as i64 54 v[1] = citing as i64 55 let rec: *u8 = sys_mmap(512) 56 let rl: i64 = canon_encode(k, v, 2, rec) 57 return reg_put(prefix, "cit:" as *u8, "cit:__idx__" as *u8, id, rec, rl) 58} 59 60// ★the WORST treatment severity recorded against `cited` (0 if none). worst-wins. 61func cit_status(prefix: *u8, cited: *u8) -> i64 { 62 let idx: *u8 = sys_mmap(CIT_MAGIC_1048576) 63 let ilen: i64 = reg_index(prefix, "cit:__idx__" as *u8, idx, CIT_MAGIC_1048576) 64 let cp: *u8 = sys_mmap(256) 65 var cpl: i64 = mt_catcopy(cp, 0, cited) 66 cp[cpl] = CIT_COLON as u8 67 cpl = cpl + 1 68 cp[cpl] = 0 as u8 69 let idb: *u8 = sys_mmap(256) 70 let po: *i64 = sys_mmap(16) as *i64 71 let lo: *i64 = sys_mmap(16) as *i64 72 let tf: *u8 = sys_mmap(64) 73 var worst: i64 = 0 74 var ls: i64 = 0 75 var i: i64 = 0 76 while i <= ilen { 77 var eol: i64 = 0 78 if i == ilen { eol = 1 } 79 if i < ilen { if idx[i] == 10 as u8 { eol = 1 } } 80 if eol == 1 { 81 if i > ls { 82 var c: i64 = 0 83 while ls + c < i { idb[c] = idx[ls + c]; c = c + 1 } 84 idb[c] = 0 as u8 85 var mtch: i64 = 1 86 var x: i64 = 0 87 while cp[x] != (0 as u8) { if idb[x] != cp[x] { mtch = 0 } x = x + 1 } 88 if mtch == 1 { 89 if reg_get(prefix, "cit:" as *u8, idb, po, lo) == 1 { 90 mt_field(po[0] as *u8, lo[0], "treatment" as *u8, 9, tf) 91 let s: i64 = cit_sev(tf) 92 if s > worst { worst = s } 93 } 94 } 95 } 96 ls = i + 1 97 } 98 i = i + 1 99 } 100 return worst 101} 102 103// 1 if `cited` is still good law (no overruling recorded); 0 if overruled. 104func cit_is_good_law(prefix: *u8, cited: *u8) -> i64 { 105 if cit_status(prefix, cited) >= 3 { return 0 } 106 return 1 107} 108 109// 1 if a citation carries CAUTION (distinguished/questioned) but is not dead -- a yellow flag. 110func cit_is_caution(prefix: *u8, cited: *u8) -> i64 { 111 let s: i64 = cit_status(prefix, cited) 112 if s >= 1 { if s < 3 { return 1 } } 113 return 0 114} 115 116// ★THE COMPOSED GATE: safe to cite ONLY if the quote verifies (nx_cite) AND the cited authority is 117// still good law. A real quote from overruled law returns 0. Same prefix holds both the cite: sources 118// and the cit: treatments (distinct keyprefixes, one plane). 119func cit_safe_to_cite(prefix: *u8, source_id: *u8, quoted: *u8) -> i64 { 120 if cite_ok(prefix, source_id, quoted) == 0 { return 0 } 121 if cit_is_good_law(prefix, source_id) == 0 { return 0 } 122 return 1 123}