use super::VowelClassifier;
#[derive(Debug, Clone, Copy, Default)]
pub struct HebrewClassifier;
impl HebrewClassifier {
pub fn new() -> Self {
Self
}
}
static HEBREW_VOWELS: &[char] = &[
'\u{05B0}', '\u{05B1}', '\u{05B2}', '\u{05B3}', '\u{05B4}', '\u{05B5}', '\u{05B6}', '\u{05B7}', '\u{05B8}', '\u{05B9}', '\u{05BA}', '\u{05BB}', '\u{05BC}', ];
impl VowelClassifier for HebrewClassifier {
fn is_vowel(&self, c: char) -> bool {
let code = c as u32;
#[allow(unreachable_patterns)]
match code {
0x05B0..=0x05BB => true,
0x05BA => true,
_ => false,
}
}
fn script_name(&self) -> &'static str {
"Hebrew"
}
fn vowels(&self) -> &[char] {
HEBREW_VOWELS
}
fn is_consonant(&self, c: char) -> bool {
let code = c as u32;
#[allow(unreachable_patterns)]
match code {
0x05D0..=0x05EA => true,
0x05DA | 0x05DD | 0x05DF | 0x05E3 | 0x05E5 => true,
_ => false,
}
}
fn normalize(&self, input: &str) -> String {
use unicode_normalization::UnicodeNormalization;
input.nfd().collect()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_niqqud_vowels() {
let c = HebrewClassifier::new();
assert!(c.is_vowel('\u{05B0}')); assert!(c.is_vowel('\u{05B4}')); assert!(c.is_vowel('\u{05B5}')); assert!(c.is_vowel('\u{05B6}')); assert!(c.is_vowel('\u{05B7}')); assert!(c.is_vowel('\u{05B8}')); assert!(c.is_vowel('\u{05B9}')); assert!(c.is_vowel('\u{05BB}')); }
#[test]
fn test_consonant_letters() {
let c = HebrewClassifier::new();
assert!(!c.is_vowel('א')); assert!(!c.is_vowel('ב')); assert!(!c.is_vowel('ג')); assert!(!c.is_vowel('ד')); assert!(!c.is_vowel('ה')); assert!(!c.is_vowel('ו')); assert!(!c.is_vowel('ז')); assert!(!c.is_vowel('ח')); assert!(!c.is_vowel('ט')); assert!(!c.is_vowel('י')); }
#[test]
fn test_is_consonant() {
let c = HebrewClassifier::new();
assert!(c.is_consonant('א')); assert!(c.is_consonant('ב')); assert!(c.is_consonant('כ')); assert!(c.is_consonant('ך')); assert!(c.is_consonant('מ')); assert!(c.is_consonant('ם')); assert!(c.is_consonant('ת')); }
#[test]
fn test_dagesh_not_vowel() {
let c = HebrewClassifier::new();
assert!(!c.is_vowel('\u{05BC}')); }
}