FST  openfst-1.7.2
OpenFst Library
rmepsilon.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 #ifndef FST_SCRIPT_RMEPSILON_H_
5 #define FST_SCRIPT_RMEPSILON_H_
6 
7 #include <utility>
8 #include <vector>
9 
10 #include <fst/queue.h>
11 #include <fst/rmepsilon.h>
12 #include <fst/script/fst-class.h>
15 
16 namespace fst {
17 namespace script {
18 
20  const bool connect;
23 
25  const WeightClass &weight_threshold,
26  int64 state_threshold = kNoStateId, float delta = kDelta)
28  delta),
29  connect(connect),
30  weight_threshold(weight_threshold),
31  state_threshold(state_threshold) {}
32 };
33 
34 namespace internal {
35 
36 // Code to implement switching on queue types.
37 
38 template <class Arc, class Queue>
40  std::vector<typename Arc::Weight> *distance,
41  const RmEpsilonOptions &opts, Queue *queue) {
42  using Weight = typename Arc::Weight;
44  queue, opts.delta, opts.connect,
45  *opts.weight_threshold.GetWeight<Weight>(), opts.state_threshold);
46  RmEpsilon(fst, distance, ropts);
47 }
48 
49 template <class Arc>
51  using StateId = typename Arc::StateId;
52  using Weight = typename Arc::Weight;
53  std::vector<Weight> distance;
54  switch (opts.queue_type) {
55  case AUTO_QUEUE: {
56  AutoQueue<StateId> queue(*fst, &distance, EpsilonArcFilter<Arc>());
57  RmEpsilon(fst, &distance, opts, &queue);
58  return;
59  }
60  case FIFO_QUEUE: {
61  FifoQueue<StateId> queue;
62  RmEpsilon(fst, &distance, opts, &queue);
63  return;
64  }
65  case LIFO_QUEUE: {
66  LifoQueue<StateId> queue;
67  RmEpsilon(fst, &distance, opts, &queue);
68  return;
69  }
70  case SHORTEST_FIRST_QUEUE: {
72  RmEpsilon(fst, &distance, opts, &queue);
73  return;
74  }
75  case STATE_ORDER_QUEUE: {
77  RmEpsilon(fst, &distance, opts, &queue);
78  return;
79  }
80  case TOP_ORDER_QUEUE: {
82  internal::RmEpsilon(fst, &distance, opts, &queue);
83  return;
84  }
85  default: {
86  FSTERROR() << "RmEpsilon: Unknown queue type: " << opts.queue_type;
88  return;
89  }
90  }
91 }
92 
93 } // namespace internal
94 
95 using RmEpsilonArgs = std::pair<MutableFstClass *, const RmEpsilonOptions &>;
96 
97 template <class Arc>
98 void RmEpsilon(RmEpsilonArgs *args) {
99  MutableFst<Arc> *fst = std::get<0>(*args)->GetMutableFst<Arc>();
100  const auto &opts = std::get<1>(*args);
101  internal::RmEpsilon(fst, opts);
102 }
103 
104 void RmEpsilon(MutableFstClass *fst, const RmEpsilonOptions &opts);
105 
106 } // namespace script
107 } // namespace fst
108 
109 #endif // FST_SCRIPT_RMEPSILON_H_
QueueType
Definition: queue.h:56
RmEpsilonOptions(QueueType queue_type, bool connect, const WeightClass &weight_threshold, int64 state_threshold=kNoStateId, float delta=kDelta)
Definition: rmepsilon.h:24
const WeightClass & weight_threshold
Definition: rmepsilon.h:21
void RmEpsilon(RmEpsilonArgs *args)
Definition: rmepsilon.h:98
constexpr int kNoStateId
Definition: fst.h:180
int64_t int64
Definition: types.h:27
#define FSTERROR()
Definition: util.h:35
const W * GetWeight() const
Definition: weight-class.h:133
constexpr uint64 kError
Definition: properties.h:33
void RmEpsilon(MutableFst< Arc > *fst, std::vector< typename Arc::Weight > *distance, const RmEpsilonOptions &opts, Queue *queue)
Definition: rmepsilon.h:39
std::pair< MutableFstClass *, const RmEpsilonOptions & > RmEpsilonArgs
Definition: rmepsilon.h:95
constexpr float kDelta
Definition: weight.h:109
virtual void SetProperties(uint64 props, uint64 mask)=0