use super::Claim;
use super::text::normalise;
pub(super) const DERIVATIVE_MARKERS: &[&str] = &[
"reply",
"erratum",
"errata",
"corrigendum",
"correction",
"comment on",
"response to",
"in response",
"faculty opinions recommendation",
"retraction of",
"expression of concern",
];
const LEADING_MARKERS: &[&str] = &["comment on", "response to", "in response", "correction"];
pub fn is_derivative(title: &str) -> bool {
let norm = normalise(title);
let words = format!(" {norm} ");
let leading = |m: &str| match m {
"correction" => {
norm == "correction"
|| norm.starts_with("correction to ")
|| title
.trim_start()
.get(..11)
.is_some_and(|h| h.eq_ignore_ascii_case("correction:"))
}
_ => words.starts_with(&format!(" {m} ")),
};
DERIVATIVE_MARKERS
.iter()
.any(|m| match LEADING_MARKERS.contains(m) {
true => leading(m),
false => words.contains(&format!(" {m} ")),
})
}
pub(super) fn claim_mentions_derivative(claim: &Claim) -> bool {
[claim.text.as_deref(), claim.title.as_deref()]
.into_iter()
.flatten()
.any(|text| {
let words = format!(" {} ", normalise(text));
DERIVATIVE_MARKERS
.iter()
.any(|m| words.contains(&format!(" {m} ")))
})
}