FST  openfst-1.8.2.post1
OpenFst Library
getters.cc
Go to the documentation of this file.
1 // Copyright 2005-2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the 'License');
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an 'AS IS' BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // See www.openfst.org for extensive documentation on this weighted
16 // finite-state transducer library.
17 
18 #include <fst/script/getters.h>
19 
20 #include <string_view>
21 
22 namespace fst {
23 namespace script {
24 
25 bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type) {
26  if (str == "any") {
27  *arc_filter_type = ArcFilterType::ANY;
28  } else if (str == "epsilon") {
29  *arc_filter_type = ArcFilterType::EPSILON;
30  } else if (str == "iepsilon") {
31  *arc_filter_type = ArcFilterType::INPUT_EPSILON;
32  } else if (str == "oepsilon") {
33  *arc_filter_type = ArcFilterType::OUTPUT_EPSILON;
34  } else {
35  return false;
36  }
37  return true;
38 }
39 
40 bool GetArcSortType(std::string_view str, ArcSortType *sort_type) {
41  if (str == "ilabel") {
42  *sort_type = ArcSortType::ILABEL;
43  } else if (str == "olabel") {
44  *sort_type = ArcSortType::OLABEL;
45  } else {
46  return false;
47  }
48  return true;
49 }
50 
51 bool GetClosureType(std::string_view str, ClosureType *closure_type) {
52  if (str == "star") {
53  *closure_type = CLOSURE_STAR;
54  } else if (str == "plus") {
55  *closure_type = CLOSURE_PLUS;
56  } else {
57  return false;
58  }
59  return true;
60 }
61 
62 bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter) {
63  if (str == "alt_sequence") {
64  *compose_filter = ALT_SEQUENCE_FILTER;
65  } else if (str == "auto") {
66  *compose_filter = AUTO_FILTER;
67  } else if (str == "match") {
68  *compose_filter = MATCH_FILTER;
69  } else if (str == "no_match") {
70  *compose_filter = NO_MATCH_FILTER;
71  } else if (str == "null") {
72  *compose_filter = NULL_FILTER;
73  } else if (str == "sequence") {
74  *compose_filter = SEQUENCE_FILTER;
75  } else if (str == "trivial") {
76  *compose_filter = TRIVIAL_FILTER;
77  } else {
78  return false;
79  }
80  return true;
81 }
82 
83 bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type) {
84  if (str == "functional") {
85  *det_type = DETERMINIZE_FUNCTIONAL;
86  } else if (str == "nonfunctional") {
87  *det_type = DETERMINIZE_NONFUNCTIONAL;
88  } else if (str == "disambiguate") {
89  *det_type = DETERMINIZE_DISAMBIGUATE;
90  } else {
91  return false;
92  }
93  return true;
94 }
95 
96 bool GetEpsNormalizeType(std::string_view str,
97  EpsNormalizeType *eps_norm_type) {
98  if (str == "input") {
99  *eps_norm_type = EPS_NORM_INPUT;
100  } else if (str == "output") {
101  *eps_norm_type = EPS_NORM_OUTPUT;
102  } else {
103  return false;
104  }
105  return true;
106 }
107 
108 bool GetMapType(std::string_view str, MapType *map_type) {
109  if (str == "arc_sum") {
110  *map_type = MapType::ARC_SUM;
111  } else if (str == "arc_unique") {
112  *map_type = MapType::ARC_UNIQUE;
113  } else if (str == "identity") {
114  *map_type = MapType::IDENTITY;
115  } else if (str == "input_epsilon") {
116  *map_type = MapType::INPUT_EPSILON;
117  } else if (str == "invert") {
118  *map_type = MapType::INVERT;
119  } else if (str == "output_epsilon") {
120  *map_type = MapType::OUTPUT_EPSILON;
121  } else if (str == "plus") {
122  *map_type = MapType::PLUS;
123  } else if (str == "power") {
124  *map_type = MapType::POWER;
125  } else if (str == "quantize") {
126  *map_type = MapType::QUANTIZE;
127  } else if (str == "rmweight") {
128  *map_type = MapType::RMWEIGHT;
129  } else if (str == "superfinal") {
130  *map_type = MapType::SUPERFINAL;
131  } else if (str == "times") {
132  *map_type = MapType::TIMES;
133  } else if (str == "to_log") {
134  *map_type = MapType::TO_LOG;
135  } else if (str == "to_log64") {
136  *map_type = MapType::TO_LOG64;
137  } else if (str == "to_std" || str == "to_standard") {
138  *map_type = MapType::TO_STD;
139  } else {
140  return false;
141  }
142  return true;
143 }
144 
145 bool GetProjectType(std::string_view str, ProjectType *project_type) {
146  if (str == "input") {
147  *project_type = ProjectType::INPUT;
148  } else if (str == "output") {
149  *project_type = ProjectType::OUTPUT;
150  } else {
151  return false;
152  }
153  return true;
154 }
155 
156 bool GetRandArcSelection(std::string_view str, RandArcSelection *ras) {
157  if (str == "uniform") {
159  } else if (str == "log_prob") {
161  } else if (str == "fast_log_prob") {
163  } else {
164  return false;
165  }
166  return true;
167 }
168 
169 bool GetQueueType(std::string_view str, QueueType *queue_type) {
170  if (str == "auto") {
171  *queue_type = AUTO_QUEUE;
172  } else if (str == "fifo") {
173  *queue_type = FIFO_QUEUE;
174  } else if (str == "lifo") {
175  *queue_type = LIFO_QUEUE;
176  } else if (str == "shortest") {
177  *queue_type = SHORTEST_FIRST_QUEUE;
178  } else if (str == "state") {
179  *queue_type = STATE_ORDER_QUEUE;
180  } else if (str == "top") {
181  *queue_type = TOP_ORDER_QUEUE;
182  } else {
183  return false;
184  }
185  return true;
186 }
187 
188 bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace,
189  ReplaceLabelType *rlt) {
190  if (epsilon_on_replace || str == "neither") {
191  *rlt = REPLACE_LABEL_NEITHER;
192  } else if (str == "input") {
193  *rlt = REPLACE_LABEL_INPUT;
194  } else if (str == "output") {
195  *rlt = REPLACE_LABEL_OUTPUT;
196  } else if (str == "both") {
197  *rlt = REPLACE_LABEL_BOTH;
198  } else {
199  return false;
200  }
201  return true;
202 }
203 
204 bool GetReweightType(std::string_view str, ReweightType *reweight_type) {
205  if (str == "to_initial") {
206  *reweight_type = REWEIGHT_TO_INITIAL;
207  } else if (str == "to_final") {
208  *reweight_type = REWEIGHT_TO_FINAL;
209  } else {
210  return false;
211  }
212  return true;
213 }
214 
215 bool GetTokenType(std::string_view str, TokenType *token_type) {
216  if (str == "byte") {
217  *token_type = TokenType::BYTE;
218  } else if (str == "utf8") {
219  *token_type = TokenType::UTF8;
220  } else if (str == "symbol") {
221  *token_type = TokenType::SYMBOL;
222  } else {
223  return false;
224  }
225  return true;
226 }
227 
228 } // namespace script
229 } // namespace fst
bool GetTokenType(std::string_view str, TokenType *token_type)
Definition: getters.cc:215
bool GetMapType(std::string_view str, MapType *map_type)
Definition: getters.cc:108
bool GetArcSortType(std::string_view str, ArcSortType *sort_type)
Definition: getters.cc:40
QueueType
Definition: queue.h:70
MapType
Definition: map.h:52
ReplaceLabelType
Definition: replace-util.h:43
ReweightType
Definition: reweight.h:34
bool GetRandArcSelection(std::string_view str, RandArcSelection *ras)
Definition: getters.cc:156
bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type)
Definition: getters.cc:83
ProjectType
Definition: project.h:32
bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace, ReplaceLabelType *rlt)
Definition: getters.cc:188
bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter)
Definition: getters.cc:62
bool GetClosureType(std::string_view str, ClosureType *closure_type)
Definition: getters.cc:51
EpsNormalizeType
Definition: epsnormalize.h:32
bool GetQueueType(std::string_view str, QueueType *queue_type)
Definition: getters.cc:169
TokenType
Definition: string.h:47
ClosureType
Definition: rational.h:39
bool GetEpsNormalizeType(std::string_view str, EpsNormalizeType *eps_norm_type)
Definition: getters.cc:96
ComposeFilter
Definition: compose.h:943
bool GetReweightType(std::string_view str, ReweightType *reweight_type)
Definition: getters.cc:204
bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type)
Definition: getters.cc:25
DeterminizeType
Definition: determinize.h:377
bool GetProjectType(std::string_view str, ProjectType *project_type)
Definition: getters.cc:145