nibli-render 0.1.0

Shared human-readable rendering for the Transparency Triad back-translation and proof traces
Documentation
//! Domain-gloss overlays for the shipped curated corpora.
//!
//! These are the documented "reader's overlay" for each case-study corpus (the
//! mapping disclosed in the corpus comments and the book's Ch 19/20 tables): the
//! proxy gismu (`prevents`, `se permits`, …) and the opaque transliterated constants
//! (`varfarin`, `siptucin`, …) rendered in real domain language. They are applied
//! ONLY when the matching read-only example is loaded in the UI; Custom KBs and
//! every other surface fall through to the engine's literal glosses.
//!
//! Honesty note: nothing here is engine-derived knowledge. The overlay is a
//! display layer that makes the proof read consistently with the example's
//! already-domain-English Source tab. It never touches the back-translation
//! (the firewall's verification surface).

use crate::overlay::DomainGloss;

/// Drug-interaction case study (`drug-interactions.nibli`, book Ch 20).
///
/// `cuts` is keyed `se`-converted: the corpus uses `se cuts` ("is metabolized
/// by"), whose IR stores the enzyme in x1 and the substrate in x2, so the
/// template reorders to read substrate-first.
pub static DRUG_INTERACTIONS_OVERLAY: DomainGloss = DomainGloss {
    templates: &[
        ("prevents", "{x1} inhibits {x2}"),
        ("cuts", "{x2} is metabolized by {x1}"),
        ("thin", "{x1} has a narrow therapeutic index"),
        ("increases", "{x1} has a raised concentration"),
        ("dangerous", "{x1} is at toxicity risk"),
        ("warns", "{x1} warrants a safety alert"),
        ("chemical", "{x1} is a drug"),
        ("uses", "{x1} takes {x2}"),
    ],
    glosses: &[("chemical", "drug")],
    names: &[
        ("varfarin", "warfarin"),
        ("flukonazol", "fluconazole"),
        ("apiksaban", "apixaban"),
        ("fenitoin", "phenytoin"),
        ("siptucin", "CYP2C9"),
        ("sipcivon", "CYP3A4"),
        ("adam", "Adam"),
    ],
};

/// GDPR compliance case study (`gdpr.nibli`, book Ch 19).
///
/// `permits` is keyed `se`-converted: `se permits` ("has a lawful basis for
/// processing") stores the data subject in x2, so the template reads off x2.
pub static GDPR_OVERLAY: DomainGloss = DomainGloss {
    templates: &[
        ("permits", "{x2} has a lawful basis for processing"),
        ("data", "{x1} is personal data"),
        ("approves", "{x1} consents"),
        ("promise", "{x1} is bound by a contract"),
        ("obliged", "{x1} is under a legal obligation"),
        ("flaw", "{x1} has suffered a breach"),
        // Embedded `lo nu <event>` obligation/right contents.
        ("correct", "{x1} is accurate"),
        ("shelter", "{x1} is kept secure"),
        ("necessary", "{x1} is necessary"),
        ("exact", "{x1} has a specific basis"),
        ("message", "{x1} notifies"),
        ("removes", "{x1} is erased"),
        ("discovers", "{x1} accesses {x2}"),
    ],
    glosses: &[("data", "personal data")],
    names: &[
        ("adam", "Adam"),
        ("akmes", "AkmeCorp"),
        ("gugli", "Google"),
        ("kanrek", "Adam's health record"),
        ("ordrek", "Adam's ordinary record"),
    ],
};

/// Utopia constitutional provocation (`utopia.nibli`).
///
/// Proof-path overlay only (never the back-translation tab). Maps legal-status
/// proxies and facility constants into domain English; the KR and back-
/// translation stay on the engine's literal / global template path.
pub static UTOPIA_OVERLAY: DomainGloss = DomainGloss {
    templates: &[
        ("false", "{x1}'s standing is voided"),
        ("home", "{x1} is under home confinement"),
        ("family", "{x1} has a domestic offense"),
        ("severe", "{x1}'s offense is severe"),
        ("reward", "{x1} is rewarded"),
        ("prisoner", "{x1} is a prisoner"),
        ("travel", "{x1} may travel"),
        ("dwell", "{x1} has shelter"),
        ("expresses", "{x1} may express"),
        ("lose", "{x2} loses {x1}"),
        ("building", "{x2} is placed at {x1}"),
        ("capture", "{x1} captures fraud by {x2}"),
        ("deceive", "{x1} falsely accuses {x2}"),
        ("judge", "{x1} judges {x2}"),
        ("parent", "{x1} is a parent of {x2}"),
        ("injure", "{x1} injures {x2}"),
        ("work", "{x1} works on {x2}"),
        ("teaches", "{x1} teaches {x2}"),
        ("permits", "{x1} permits {x2}"),
    ],
    glosses: &[],
    names: &[
        ("points", "merit tokens"),
        ("highsec", "High Security"),
        ("lowsec", "Low Security"),
        ("court", "the Court"),
        ("appeals", "Appeals"),
        ("review", "Review"),
        ("census", "the Census"),
    ],
};

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn ddi_overlay_key_mappings() {
        assert_eq!(
            DRUG_INTERACTIONS_OVERLAY.template("prevents"),
            Some("{x1} inhibits {x2}")
        );
        // `se cuts` reorders so the substrate (x2) heads the clause.
        assert_eq!(
            DRUG_INTERACTIONS_OVERLAY.template("cuts"),
            Some("{x2} is metabolized by {x1}")
        );
        assert_eq!(
            DRUG_INTERACTIONS_OVERLAY.template("dangerous"),
            Some("{x1} is at toxicity risk")
        );
        assert_eq!(DRUG_INTERACTIONS_OVERLAY.name("varfarin"), Some("warfarin"));
        assert_eq!(DRUG_INTERACTIONS_OVERLAY.name("siptucin"), Some("CYP2C9"));
    }

    #[test]
    fn utopia_overlay_key_mappings() {
        assert_eq!(
            UTOPIA_OVERLAY.template("false"),
            Some("{x1}'s standing is voided")
        );
        assert_eq!(UTOPIA_OVERLAY.name("highsec"), Some("High Security"));
        assert_eq!(UTOPIA_OVERLAY.name("points"), Some("merit tokens"));
    }

    #[test]
    fn gdpr_overlay_key_mappings() {
        assert_eq!(
            GDPR_OVERLAY.template("permits"),
            Some("{x2} has a lawful basis for processing")
        );
        assert_eq!(GDPR_OVERLAY.template("data"), Some("{x1} is personal data"));
        assert_eq!(GDPR_OVERLAY.name("akmes"), Some("AkmeCorp"));
    }
}