use core::ops::Range;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Confidence {
Solid,
Unverified,
Heuristic,
}
impl Confidence {
fn rank(self) -> u8 {
match self {
Confidence::Solid => 0,
Confidence::Unverified => 1,
Confidence::Heuristic => 2,
}
}
#[must_use]
pub fn most_concerning(self, other: Self) -> Self {
if other.rank() > self.rank() {
other
} else {
self
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum CasingRule {
FirstWord,
LastWord,
SubtitleBoundary,
HyphenatedCompound,
SmallWord,
AdverbialParticle,
NameParticle,
ContractedAnd,
ProtectedSpelling,
Abbreviation,
DottedAbbreviation,
CanonicalLexicon,
MultiwordLexicon,
AllCapsNormalized,
AllCapsPreservedAcronym,
AcronymPreserved,
MixedCasePreserved,
Capitalized,
}
impl CasingRule {
#[must_use]
pub fn confidence(self) -> Confidence {
match self {
CasingRule::FirstWord
| CasingRule::LastWord
| CasingRule::SubtitleBoundary
| CasingRule::HyphenatedCompound
| CasingRule::SmallWord
| CasingRule::ContractedAnd
| CasingRule::ProtectedSpelling
| CasingRule::Abbreviation
| CasingRule::DottedAbbreviation
| CasingRule::CanonicalLexicon
| CasingRule::MultiwordLexicon
| CasingRule::MixedCasePreserved => Confidence::Solid,
CasingRule::AdverbialParticle
| CasingRule::NameParticle
| CasingRule::AllCapsNormalized
| CasingRule::AllCapsPreservedAcronym
| CasingRule::AcronymPreserved => Confidence::Heuristic,
CasingRule::Capitalized => Confidence::Unverified,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CasingSpan {
pub source: Range<usize>,
pub output: Range<usize>,
pub rule: CasingRule,
pub confidence: Confidence,
pub changed: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct TitleCaseAnalysis {
pub output: String,
pub confidence: Confidence,
pub spans: Vec<CasingSpan>,
}