#[derive(Debug, Clone, PartialEq)]
pub struct WordPhonemePair {
pub word: String,
pub phonemes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WordPhonemeMap {
pub word: String,
pub phonemes: Vec<String>,
pub is_unknown: bool,
pub is_ignored: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WordPhonemeDetail {
pub word: String,
pub phonemes: Vec<String>,
pub features: Vec<String>,
pub pos: String,
pub pos_group1: String,
pub pos_group2: String,
pub pos_group3: String,
pub ctype: String,
pub cform: String,
pub orig: String,
pub read: String,
pub pron: String,
pub accent_nucleus: i32,
pub mora_count: i32,
pub chain_rule: String,
pub chain_flag: i32,
pub is_unknown: bool,
pub is_ignored: bool,
}
pub(crate) trait WordPhonemeEntry {
fn phonemes_mut(&mut self) -> &mut Vec<String>;
fn phonemes(&self) -> &[String];
fn merge_from(&mut self, other: &mut Self);
}
impl WordPhonemeEntry for WordPhonemePair {
fn phonemes_mut(&mut self) -> &mut Vec<String> {
&mut self.phonemes
}
fn phonemes(&self) -> &[String] {
&self.phonemes
}
fn merge_from(&mut self, other: &mut Self) {
let text_to_merge = std::mem::take(&mut other.word);
self.word.push_str(&text_to_merge);
}
}
impl WordPhonemeEntry for WordPhonemeDetail {
fn phonemes_mut(&mut self) -> &mut Vec<String> {
&mut self.phonemes
}
fn phonemes(&self) -> &[String] {
&self.phonemes
}
fn merge_from(&mut self, other: &mut Self) {
let text_to_merge = std::mem::take(&mut other.word);
self.word.push_str(&text_to_merge);
self.mora_count += other.mora_count;
if !other.orig.is_empty() && other.orig.chars().all(|c| c == 'ー') {
let orig_to_merge = std::mem::take(&mut other.orig);
self.orig.push_str(&orig_to_merge);
}
let read_to_merge = std::mem::take(&mut other.read);
self.read.push_str(&read_to_merge);
let pron_to_merge = std::mem::take(&mut other.pron);
self.pron.push_str(&pron_to_merge);
}
}