FST  openfst-1.8.3
OpenFst Library
getters.h
Go to the documentation of this file.
1 // Copyright 2005-2024 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 <limits>
26 #include <string>
27 
28 #include <fst/log.h>
29 #include <fst/compose.h> // For ComposeFilter.
30 #include <fst/determinize.h> // For DeterminizeType.
31 #include <fst/encode.h> // For kEncodeLabels (etc.).
32 #include <fst/epsnormalize.h> // For EpsNormalizeType.
33 #include <fst/project.h> // For ProjectType.
34 #include <fst/push.h> // For kPushWeights (etc.).
35 #include <fst/queue.h> // For QueueType.
36 #include <fst/rational.h> // For ClosureType.
37 #include <fst/replace-util.h>
38 #include <fst/reweight.h>
39 #include <fst/string.h> // For TokenType.
40 #include <fst/script/arcfilter-impl.h> // For ArcFilterType.
41 #include <fst/script/arcsort.h> // For ArcSortType.
42 #include <fst/script/map.h> // For MapType.
43 #include <fst/script/script-impl.h> // For RandArcSelection.
44 #include <string_view>
45 
46 namespace fst {
47 namespace script {
48 
49 inline constexpr uint64_t kDefaultSeed = std::numeric_limits<uint64_t>::max();
50 
51 bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type);
52 
53 bool GetArcSortType(std::string_view str, ArcSortType *sort_type);
54 
55 bool GetClosureType(std::string_view str, ClosureType *closure_type);
56 
57 bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter);
58 
59 bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type);
60 
61 inline uint8_t GetEncodeFlags(bool encode_labels, bool encode_weights) {
62  return (encode_labels ? kEncodeLabels : 0) |
63  (encode_weights ? kEncodeWeights : 0);
64 }
65 
66 bool GetEpsNormalizeType(std::string_view str,
67  EpsNormalizeType *eps_norm_type);
68 
69 bool GetMapType(std::string_view str, MapType *map_type);
70 
71 bool GetProjectType(std::string_view str, ProjectType *project_type);
72 
73 inline uint8_t GetPushFlags(bool push_weights, bool push_labels,
74  bool remove_total_weight,
75  bool remove_common_affix) {
76  return ((push_weights ? kPushWeights : 0) | (push_labels ? kPushLabels : 0) |
77  (remove_total_weight ? kPushRemoveTotalWeight : 0) |
78  (remove_common_affix ? kPushRemoveCommonAffix : 0));
79 }
80 
81 bool GetQueueType(std::string_view str, QueueType *queue_type);
82 
83 bool GetRandArcSelection(std::string_view str, RandArcSelection *ras);
84 
85 bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace,
86  ReplaceLabelType *rlt);
87 
88 bool GetReweightType(std::string_view str, ReweightType *reweight_type);
89 
90 uint64_t GetSeed(uint64_t seed);
91 
92 bool GetTokenType(std::string_view str, TokenType *token_type);
93 
94 } // namespace script
95 } // namespace fst
96 
97 #endif // FST_SCRIPT_GETTERS_H_
bool GetTokenType(std::string_view str, TokenType *token_type)
Definition: getters.cc:234
bool GetMapType(std::string_view str, MapType *map_type)
Definition: getters.cc:123
constexpr uint64_t kDefaultSeed
Definition: getters.h:49
constexpr uint8_t kPushRemoveCommonAffix
Definition: push.h:112
constexpr uint8_t kPushLabels
Definition: push.h:110
bool GetArcSortType(std::string_view str, ArcSortType *sort_type)
Definition: getters.cc:55
QueueType
Definition: queue.h:76
MapType
Definition: map.h:56
ReplaceLabelType
Definition: replace-util.h:48
ReweightType
Definition: reweight.h:35
bool GetRandArcSelection(std::string_view str, RandArcSelection *ras)
Definition: getters.cc:171
bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type)
Definition: getters.cc:98
ProjectType
Definition: project.h:37
bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace, ReplaceLabelType *rlt)
Definition: getters.cc:203
bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter)
Definition: getters.cc:77
bool GetClosureType(std::string_view str, ClosureType *closure_type)
Definition: getters.cc:66
EpsNormalizeType
Definition: epsnormalize.h:38
uint64_t GetSeed(uint64_t seed)
Definition: getters.cc:230
constexpr uint8_t kPushWeights
Definition: push.h:109
constexpr uint8_t kEncodeLabels
Definition: encode.h:55
bool GetQueueType(std::string_view str, QueueType *queue_type)
Definition: getters.cc:184
TokenType
Definition: string.h:49
uint8_t GetEncodeFlags(bool encode_labels, bool encode_weights)
Definition: getters.h:61
constexpr uint8_t kEncodeWeights
Definition: encode.h:56
ClosureType
Definition: rational.h:45
bool GetEpsNormalizeType(std::string_view str, EpsNormalizeType *eps_norm_type)
Definition: getters.cc:111
uint8_t GetPushFlags(bool push_weights, bool push_labels, bool remove_total_weight, bool remove_common_affix)
Definition: getters.h:73
constexpr uint8_t kPushRemoveTotalWeight
Definition: push.h:111
ComposeFilter
Definition: compose.h:953
bool GetReweightType(std::string_view str, ReweightType *reweight_type)
Definition: getters.cc:219
bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type)
Definition: getters.cc:40
DeterminizeType
Definition: determinize.h:394
bool GetProjectType(std::string_view str, ProjectType *project_type)
Definition: getters.cc:160