jpreprocess_jpcommon/label/
breath_group.rs1use crate::limit::Limit;
2
3use super::*;
4
5#[derive(Clone, Debug)]
6pub struct BreathGroup {
7 pub accent_phrases: Vec<AccentPhrase>,
8}
9
10impl BreathGroup {
11 pub fn new(accent_phrases: Vec<AccentPhrase>) -> Self {
12 Self { accent_phrases }
13 }
14
15 pub fn to_h(&self) -> jlabel::BreathGroupPrevNext {
16 jlabel::BreathGroupPrevNext {
17 accent_phrase_count: Limit::M.ulimit(self.count_accent_phrase()),
18 mora_count: Limit::L.ulimit(self.count_mora()),
19 }
20 }
21 pub fn to_i(
22 &self,
23 breath_group_count_in_utterance: usize,
24 breath_group_index_in_utterance: usize,
25 accent_phrase_count_in_utterance: usize,
26 accent_phrase_index_in_utterance: usize,
27 mora_count_in_utterance: usize,
28 mora_index_in_utterance: usize,
29 ) -> jlabel::BreathGroupCurrent {
30 jlabel::BreathGroupCurrent {
31 accent_phrase_count: Limit::M.ulimit(self.count_accent_phrase()),
32 mora_count: Limit::L.ulimit(self.count_mora()),
33 breath_group_position_forward: Limit::S.ulimit(breath_group_index_in_utterance + 1),
34 breath_group_position_backward: Limit::S
35 .ulimit(breath_group_count_in_utterance - breath_group_index_in_utterance),
36 accent_phrase_position_forward: Limit::M.ulimit(accent_phrase_index_in_utterance + 1),
37 accent_phrase_position_backward: Limit::M
38 .ulimit(accent_phrase_count_in_utterance - accent_phrase_index_in_utterance),
39 mora_position_forward: Limit::LL.ulimit(mora_index_in_utterance + 1),
40 mora_position_backward: Limit::LL
41 .ulimit(mora_count_in_utterance - mora_index_in_utterance),
42 }
43 }
44 pub fn to_j(&self) -> jlabel::BreathGroupPrevNext {
45 jlabel::BreathGroupPrevNext {
46 accent_phrase_count: Limit::M.ulimit(self.count_accent_phrase()),
47 mora_count: Limit::L.ulimit(self.count_mora()),
48 }
49 }
50
51 pub fn count_accent_phrase(&self) -> usize {
52 self.accent_phrases.len()
53 }
54 pub fn count_mora(&self) -> usize {
55 self.accent_phrases.iter().map(|ap| ap.count_mora()).sum()
56 }
57}