FST  openfst-1.8.2.post1
OpenFst Library
getters.h
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 // Getters for converting command-line arguments into the appropriate enums
19 // or bitmasks, with the simplest ones defined as inline.
20 
21 #ifndef FST_SCRIPT_GETTERS_H_
22 #define FST_SCRIPT_GETTERS_H_
23 
24 #include <cstdint>
25 #include <string>
26 
27 #include <fst/log.h>
28 #include <fst/compose.h> // For ComposeFilter.
29 #include <fst/determinize.h> // For DeterminizeType.
30 #include <fst/encode.h> // For kEncodeLabels (etc.).
31 #include <fst/epsnormalize.h> // For EpsNormalizeType.
32 #include <fst/project.h> // For ProjectType.
33 #include <fst/push.h> // For kPushWeights (etc.).
34 #include <fst/queue.h> // For QueueType.
35 #include <fst/rational.h> // For ClosureType.
36 #include <fst/string.h> // For TokenType.
37 #include <fst/script/arcfilter-impl.h> // For ArcFilterType.
38 #include <fst/script/arcsort.h> // For ArcSortType.
39 #include <fst/script/map.h> // For MapType.
40 #include <fst/script/script-impl.h> // For RandArcSelection.
41 #include <string_view>
42 
43 namespace fst {
44 namespace script {
45 
46 bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type);
47 
48 bool GetArcSortType(std::string_view str, ArcSortType *sort_type);
49 
50 bool GetClosureType(std::string_view str, ClosureType *closure_type);
51 
52 bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter);
53 
54 bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type);
55 
56 inline uint8_t GetEncodeFlags(bool encode_labels, bool encode_weights) {
57  return (encode_labels ? kEncodeLabels : 0) |
58  (encode_weights ? kEncodeWeights : 0);
59 }
60 
61 bool GetEpsNormalizeType(std::string_view str,
62  EpsNormalizeType *eps_norm_type);
63 
64 bool GetMapType(std::string_view str, MapType *map_type);
65 
66 bool GetProjectType(std::string_view str, ProjectType *project_type);
67 
68 inline uint8_t GetPushFlags(bool push_weights, bool push_labels,
69  bool remove_total_weight,
70  bool remove_common_affix) {
71  return ((push_weights ? kPushWeights : 0) | (push_labels ? kPushLabels : 0) |
72  (remove_total_weight ? kPushRemoveTotalWeight : 0) |
73  (remove_common_affix ? kPushRemoveCommonAffix : 0));
74 }
75 
76 bool GetQueueType(std::string_view str, QueueType *queue_type);
77 
78 bool GetRandArcSelection(std::string_view str, RandArcSelection *ras);
79 
80 bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace,
81  ReplaceLabelType *rlt);
82 
83 bool GetReweightType(std::string_view str, ReweightType *reweight_type);
84 
85 bool GetTokenType(std::string_view str, TokenType *token_type);
86 
87 } // namespace script
88 } // namespace fst
89 
90 #endif // FST_SCRIPT_GETTERS_H_
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
constexpr uint8_t kPushRemoveCommonAffix
Definition: push.h:109
constexpr uint8_t kPushLabels
Definition: push.h:107
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
constexpr uint8_t kPushWeights
Definition: push.h:106
constexpr uint8_t kEncodeLabels
Definition: encode.h:43
bool GetQueueType(std::string_view str, QueueType *queue_type)
Definition: getters.cc:169
TokenType
Definition: string.h:47
uint8_t GetEncodeFlags(bool encode_labels, bool encode_weights)
Definition: getters.h:56
constexpr uint8_t kEncodeWeights
Definition: encode.h:44
ClosureType
Definition: rational.h:39
bool GetEpsNormalizeType(std::string_view str, EpsNormalizeType *eps_norm_type)
Definition: getters.cc:96
uint8_t GetPushFlags(bool push_weights, bool push_labels, bool remove_total_weight, bool remove_common_affix)
Definition: getters.h:68
constexpr uint8_t kPushRemoveTotalWeight
Definition: push.h:108
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