Skip to main content

nibli_render/
corpus_overlay.rs

1//! Domain-gloss overlays for the shipped curated corpora.
2//!
3//! These are the documented "reader's overlay" for each case-study corpus (the
4//! mapping disclosed in the corpus comments and the book's Ch 19/20 tables): the
5//! proxy gismu (`prevents`, `se permits`, …) and the opaque transliterated constants
6//! (`varfarin`, `siptucin`, …) rendered in real domain language. They are applied
7//! ONLY when the matching read-only example is loaded in the UI; Custom KBs and
8//! every other surface fall through to the engine's literal glosses.
9//!
10//! Honesty note: nothing here is engine-derived knowledge. The overlay is a
11//! display layer that makes the proof read consistently with the example's
12//! already-domain-English Source tab. It never touches the back-translation
13//! (the firewall's verification surface).
14
15use crate::overlay::DomainGloss;
16
17/// Drug-interaction case study (`drug-interactions.nibli`, book Ch 20).
18///
19/// `cuts` is keyed `se`-converted: the corpus uses `se cuts` ("is metabolized
20/// by"), whose IR stores the enzyme in x1 and the substrate in x2, so the
21/// template reorders to read substrate-first.
22pub static DRUG_INTERACTIONS_OVERLAY: DomainGloss = DomainGloss {
23    templates: &[
24        ("prevents", "{x1} inhibits {x2}"),
25        ("cuts", "{x2} is metabolized by {x1}"),
26        ("thin", "{x1} has a narrow therapeutic index"),
27        ("increases", "{x1} has a raised concentration"),
28        ("dangerous", "{x1} is at toxicity risk"),
29        ("warns", "{x1} warrants a safety alert"),
30        ("chemical", "{x1} is a drug"),
31        ("uses", "{x1} takes {x2}"),
32    ],
33    glosses: &[("chemical", "drug")],
34    names: &[
35        ("varfarin", "warfarin"),
36        ("flukonazol", "fluconazole"),
37        ("apiksaban", "apixaban"),
38        ("fenitoin", "phenytoin"),
39        ("siptucin", "CYP2C9"),
40        ("sipcivon", "CYP3A4"),
41        ("adam", "Adam"),
42    ],
43};
44
45/// GDPR compliance case study (`gdpr.nibli`, book Ch 19).
46///
47/// `permits` is keyed `se`-converted: `se permits` ("has a lawful basis for
48/// processing") stores the data subject in x2, so the template reads off x2.
49pub static GDPR_OVERLAY: DomainGloss = DomainGloss {
50    templates: &[
51        ("permits", "{x2} has a lawful basis for processing"),
52        ("data", "{x1} is personal data"),
53        ("approves", "{x1} consents"),
54        ("promise", "{x1} is bound by a contract"),
55        ("obliged", "{x1} is under a legal obligation"),
56        ("flaw", "{x1} has suffered a breach"),
57        // Embedded `lo nu <event>` obligation/right contents.
58        ("correct", "{x1} is accurate"),
59        ("shelter", "{x1} is kept secure"),
60        ("necessary", "{x1} is necessary"),
61        ("exact", "{x1} has a specific basis"),
62        ("message", "{x1} notifies"),
63        ("removes", "{x1} is erased"),
64        ("discovers", "{x1} accesses {x2}"),
65    ],
66    glosses: &[("data", "personal data")],
67    names: &[
68        ("adam", "Adam"),
69        ("akmes", "AkmeCorp"),
70        ("gugli", "Google"),
71        ("kanrek", "Adam's health record"),
72        ("ordrek", "Adam's ordinary record"),
73    ],
74};
75
76/// Utopia constitutional provocation (`utopia.nibli`).
77///
78/// Proof-path overlay only (never the back-translation tab). Maps legal-status
79/// proxies and facility constants into domain English; the KR and back-
80/// translation stay on the engine's literal / global template path.
81pub static UTOPIA_OVERLAY: DomainGloss = DomainGloss {
82    templates: &[
83        ("false", "{x1}'s standing is voided"),
84        ("home", "{x1} is under home confinement"),
85        ("family", "{x1} has a domestic offense"),
86        ("severe", "{x1}'s offense is severe"),
87        ("reward", "{x1} is rewarded"),
88        ("prisoner", "{x1} is a prisoner"),
89        ("travel", "{x1} may travel"),
90        ("dwell", "{x1} has shelter"),
91        ("expresses", "{x1} may express"),
92        ("lose", "{x2} loses {x1}"),
93        ("building", "{x2} is placed at {x1}"),
94        ("capture", "{x1} captures fraud by {x2}"),
95        ("deceive", "{x1} falsely accuses {x2}"),
96        ("judge", "{x1} judges {x2}"),
97        ("parent", "{x1} is a parent of {x2}"),
98        ("injure", "{x1} injures {x2}"),
99        ("work", "{x1} works on {x2}"),
100        ("teaches", "{x1} teaches {x2}"),
101        ("permits", "{x1} permits {x2}"),
102    ],
103    glosses: &[],
104    names: &[
105        ("points", "merit tokens"),
106        ("highsec", "High Security"),
107        ("lowsec", "Low Security"),
108        ("court", "the Court"),
109        ("appeals", "Appeals"),
110        ("review", "Review"),
111        ("census", "the Census"),
112    ],
113};
114
115#[cfg(test)]
116mod tests {
117    use super::*;
118
119    #[test]
120    fn ddi_overlay_key_mappings() {
121        assert_eq!(
122            DRUG_INTERACTIONS_OVERLAY.template("prevents"),
123            Some("{x1} inhibits {x2}")
124        );
125        // `se cuts` reorders so the substrate (x2) heads the clause.
126        assert_eq!(
127            DRUG_INTERACTIONS_OVERLAY.template("cuts"),
128            Some("{x2} is metabolized by {x1}")
129        );
130        assert_eq!(
131            DRUG_INTERACTIONS_OVERLAY.template("dangerous"),
132            Some("{x1} is at toxicity risk")
133        );
134        assert_eq!(DRUG_INTERACTIONS_OVERLAY.name("varfarin"), Some("warfarin"));
135        assert_eq!(DRUG_INTERACTIONS_OVERLAY.name("siptucin"), Some("CYP2C9"));
136    }
137
138    #[test]
139    fn utopia_overlay_key_mappings() {
140        assert_eq!(
141            UTOPIA_OVERLAY.template("false"),
142            Some("{x1}'s standing is voided")
143        );
144        assert_eq!(UTOPIA_OVERLAY.name("highsec"), Some("High Security"));
145        assert_eq!(UTOPIA_OVERLAY.name("points"), Some("merit tokens"));
146    }
147
148    #[test]
149    fn gdpr_overlay_key_mappings() {
150        assert_eq!(
151            GDPR_OVERLAY.template("permits"),
152            Some("{x2} has a lawful basis for processing")
153        );
154        assert_eq!(GDPR_OVERLAY.template("data"), Some("{x1} is personal data"));
155        assert_eq!(GDPR_OVERLAY.name("akmes"), Some("AkmeCorp"));
156    }
157}