use super::TraditionLens;
struct LensSignal {
markers: &'static [&'static str],
lenses: &'static [TraditionLens],
}
use TraditionLens::*;
const LENS_SIGNALS: &[LensSignal] = &[
LensSignal { markers: &["veil", "illusion", "awaken", "true reality", "hidden world", "the real world"], lenses: &[Gnostic, Buddhism, SecularPhilosophy] },
LensSignal { markers: &["destiny", "prophecy", "chosen", "foretold", "born to", "calling"], lenses: &[Lds, Gnostic, Hinduism] },
LensSignal { markers: &["suffering", "agony", "torment", "innocent", "undeserved", "why me"], lenses: &[Judaism, Buddhism, Catholic] },
LensSignal { markers: &["family", "ancestor", "generations", "bloodline", "covenant", "lineage"], lenses: &[Lds, Judaism, Confucianism] },
LensSignal { markers: &["god", "goddess", "divine", "avatar", "incarnate", "demigod"], lenses: &[Lds, Hinduism, SecularPhilosophy] },
LensSignal { markers: &["sacrifice", "gave his life", "gave her life", "laid down", "for the others"], lenses: &[Orthodox, Catholic, Protestant] },
LensSignal { markers: &["awakening", "realised the truth", "enlighten", "saw clearly", "knowledge"], lenses: &[Gnostic, Buddhism, SecularPhilosophy] },
LensSignal { markers: &["empire", "the council", "the church", "authority", "corrupt", "regime"], lenses: &[Gnostic, Islam, Confucianism] },
LensSignal { markers: &["promise", "duty", "oath", "betrayed", "obligation", "owed"], lenses: &[Confucianism, Judaism, SecularPhilosophy] },
LensSignal { markers: &["war", "battle", "kill", "for duty", "had to", "command"], lenses: &[Hinduism, Islam, SecularPhilosophy] },
];
pub(crate) fn suggest_lenses(passage: &str) -> Vec<TraditionLens> {
let lc = passage.to_lowercase();
let mut out: Vec<TraditionLens> = Vec::new();
for sig in LENS_SIGNALS {
if sig.markers.iter().any(|m| marker_hit(&lc, m)) {
for &lens in sig.lenses {
if !out.contains(&lens) {
out.push(lens);
}
}
}
}
out.truncate(5);
out
}
fn marker_hit(lc: &str, marker: &str) -> bool {
if marker.contains(' ') {
lc.contains(marker)
} else {
lc.split(|c: char| !c.is_alphanumeric()).any(|tok| tok == marker)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn markers_suggest_their_lenses() {
let s = suggest_lenses("She awakened and saw the veil over the true reality.");
assert!(s.contains(&Gnostic));
let d = suggest_lenses("He gave his life as a sacrifice for the others.");
assert!(d.contains(&Orthodox));
}
#[test]
fn no_marker_yields_empty_so_persona_picks_from_all() {
let s = suggest_lenses("The afternoon was warm and the tea had gone cold.");
assert!(s.is_empty());
}
#[test]
fn dedups_and_caps_at_five() {
let s = suggest_lenses(
"war and sacrifice and prophecy and family and the corrupt empire and a broken promise",
);
assert!(s.len() <= 5);
let mut uniq = s.clone();
uniq.dedup();
assert_eq!(uniq.len(), s.len());
}
}