rustfst/algorithms/replace/
config.rs

1use crate::Label;
2
3/// This specifies what labels to output on the call or return transition.
4#[derive(PartialOrd, PartialEq, Copy, Clone, Debug, Eq)]
5pub enum ReplaceLabelType {
6    /// Epsilon labels on both input and output.
7    Neither,
8    /// Non-epsilon labels on input and epsilon on output.
9    Input,
10    /// Epsilon on input and non-epsilon on output.
11    Output,
12    #[allow(unused)]
13    /// Non-epsilon labels on both input and output.
14    Both,
15}
16
17#[derive(PartialOrd, PartialEq, Clone, Debug, Eq)]
18pub struct ReplaceFstOptions {
19    /// Index of root rule for expansion.
20    pub root: Label,
21    /// How to label call transition.
22    pub call_label_type: ReplaceLabelType,
23    /// How to label return transition.
24    pub return_label_type: ReplaceLabelType,
25    /// Specifies output label to put on call transition; if `None`, use existing label
26    /// on call transition. Otherwise, use this field as the output label.
27    pub call_output_label: Option<Label>,
28    /// Specifies label to put on return transition.
29    pub return_label: Label,
30}
31
32impl ReplaceFstOptions {
33    pub fn new(root: Label, epsilon_on_replace: bool) -> Self {
34        Self {
35            root,
36            call_label_type: if epsilon_on_replace {
37                ReplaceLabelType::Neither
38            } else {
39                ReplaceLabelType::Input
40            },
41            return_label_type: ReplaceLabelType::Neither,
42            call_output_label: if epsilon_on_replace { Some(0) } else { None },
43            return_label: 0,
44        }
45    }
46}