FST  openfst-1.7.1
OpenFst Library
getters.h
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 //
4 // Getters for converting command-line arguments into the appropriate enums
5 // or bitmasks, with the simplest ones defined as inline.
6 
7 #ifndef FST_SCRIPT_GETTERS_H_
8 #define FST_SCRIPT_GETTERS_H_
9 
10 #include <string>
11 
12 #include <fst/compose.h> // For ComposeFilter.
13 #include <fst/determinize.h> // For DeterminizeType.
14 #include <fst/encode.h> // For kEncodeLabels (etc.).
15 #include <fst/epsnormalize.h> // For EpsNormalizeType.
16 #include <fst/project.h> // For ProjectType.
17 #include <fst/push.h> // For kPushWeights (etc.).
18 #include <fst/queue.h> // For QueueType.
19 #include <fst/rational.h> // For ClosureType.
20 #include <fst/script/arcsort.h> // For ArcSortType.
21 #include <fst/script/map.h> // For MapType.
22 #include <fst/script/script-impl.h> // For RandArcSelection.
23 
24 #include <fst/log.h>
25 
26 namespace fst {
27 namespace script {
28 
29 bool GetArcSortType(const string &str, ArcSortType *sort_type);
30 
31 inline ClosureType GetClosureType(bool closure_plus) {
32  return closure_plus ? CLOSURE_PLUS : CLOSURE_STAR;
33 }
34 
35 bool GetComposeFilter(const string &str, ComposeFilter *compose_filter);
36 
37 bool GetDeterminizeType(const string &str, DeterminizeType *det_type);
38 
39 inline uint32 GetEncodeFlags(bool encode_labels, bool encode_weights) {
40  return (encode_labels ? kEncodeLabels : 0) |
41  (encode_weights ? kEncodeWeights : 0);
42 }
43 
44 inline EpsNormalizeType GetEpsNormalizeType(bool eps_norm_output) {
45  return eps_norm_output ? EPS_NORM_OUTPUT : EPS_NORM_INPUT;
46 }
47 
48 bool GetMapType(const string &str, MapType *map_type);
49 
50 inline ProjectType GetProjectType(bool project_output) {
51  return project_output ? PROJECT_OUTPUT : PROJECT_INPUT;
52 }
53 
54 inline uint32 GetPushFlags(bool push_weights, bool push_labels,
55  bool remove_total_weight, bool remove_common_affix) {
56  return ((push_weights ? kPushWeights : 0) |
57  (push_labels ? kPushLabels : 0) |
58  (remove_total_weight ? kPushRemoveTotalWeight : 0) |
59  (remove_common_affix ? kPushRemoveCommonAffix : 0));
60 }
61 
62 bool GetQueueType(const string &str, QueueType *queue_type);
63 
64 bool GetRandArcSelection(const string &str, RandArcSelection *ras);
65 
66 bool GetReplaceLabelType(const string &str, bool epsilon_on_replace,
67  ReplaceLabelType *rlt);
68 
69 inline ReweightType GetReweightType(bool to_final) {
70  return to_final ? REWEIGHT_TO_FINAL : REWEIGHT_TO_INITIAL;
71 }
72 
73 } // namespace script
74 } // namespace fst
75 
76 #endif // FST_SCRIPT_GETTERS_H_
MapType
Definition: map.h:37
ReweightType GetReweightType(bool to_final)
Definition: getters.h:69
QueueType
Definition: queue.h:55
ReplaceLabelType
Definition: replace-util.h:27
ReweightType
Definition: reweight.h:17
EpsNormalizeType GetEpsNormalizeType(bool eps_norm_output)
Definition: getters.h:44
bool GetRandArcSelection(const string &str, RandArcSelection *ras)
Definition: getters.cc:86
bool GetReplaceLabelType(const string &str, bool epsilon_on_replace, ReplaceLabelType *rlt)
Definition: getters.cc:118
constexpr uint32 kPushRemoveTotalWeight
Definition: push.h:95
ProjectType
Definition: project.h:16
EpsNormalizeType
Definition: epsnormalize.h:18
bool GetArcSortType(const string &str, ArcSortType *sort_type)
Definition: getters.cc:6
ClosureType GetClosureType(bool closure_plus)
Definition: getters.h:31
bool GetMapType(const string &str, MapType *map_type)
Definition: getters.cc:49
uint32 GetEncodeFlags(bool encode_labels, bool encode_weights)
Definition: getters.h:39
uint32 GetPushFlags(bool push_weights, bool push_labels, bool remove_total_weight, bool remove_common_affix)
Definition: getters.h:54
uint32_t uint32
Definition: types.h:31
bool GetQueueType(const string &str, QueueType *queue_type)
Definition: getters.cc:99
ClosureType
Definition: rational.h:24
ProjectType GetProjectType(bool project_output)
Definition: getters.h:50
constexpr uint32 kPushRemoveCommonAffix
Definition: push.h:96
constexpr uint32 kPushWeights
Definition: push.h:93
bool GetDeterminizeType(const string &str, DeterminizeType *det_type)
Definition: getters.cc:36
ComposeFilter
Definition: compose.h:929
bool GetComposeFilter(const string &str, ComposeFilter *compose_filter)
Definition: getters.cc:17
DeterminizeType
Definition: determinize.h:358
constexpr uint32 kPushLabels
Definition: push.h:94