FST  openfst-1.6.1
OpenFst Library
rmepsilon.cc
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 #include <fst/script/fst-class.h>
5 #include <fst/script/rmepsilon.h>
7 
8 namespace fst {
9 namespace script {
10 
11 // 1: Full signature with RmEpsilonOptions.
12 void RmEpsilon(const FstClass &ifst, MutableFstClass *ofst, bool reverse,
13  const RmEpsilonOptions &opts) {
14  if (!ArcTypesMatch(ifst, *ofst, "RmEpsilon") ||
15  !ofst->WeightTypesMatch(opts.weight_threshold, "RmEpsilon")) {
16  ofst->SetProperties(kError, kError);
17  return;
18  }
19  RmEpsilonArgs1 args(ifst, ofst, reverse, opts);
20  Apply<Operation<RmEpsilonArgs1>>("RmEpsilon", ifst.ArcType(), &args);
21 }
22 
23 // 2: Full signature with flat arguments.
24 void RmEpsilon(MutableFstClass *fst, bool connect,
25  const WeightClass &weight_threshold, int64 state_threshold,
26  float delta) {
27  if (!fst->WeightTypesMatch(weight_threshold, "RmEpsilon")) {
29  return;
30  }
31  RmEpsilonArgs2 args(fst, connect, weight_threshold, state_threshold, delta);
32  Apply<Operation<RmEpsilonArgs2>>("RmEpsilon", fst->ArcType(), &args);
33 }
34 
35 // #2 signature with default WeightClass argument.
36 void RmEpsilon(MutableFstClass *fst, bool connect, int64 state_threshold,
37  float delta) {
38  const WeightClass weight_threshold = WeightClass::Zero(fst->WeightType());
39  RmEpsilon(fst, connect, weight_threshold, state_threshold, delta);
40 }
41 
42 // 3: Full signature with RmEpsilonOptions and weight vector.
43 void RmEpsilon(MutableFstClass *fst, std::vector<WeightClass> *distance,
44  const RmEpsilonOptions &opts) {
45  if (distance) {
46  for (auto it = distance->begin(); it != distance->end(); ++it) {
47  if (!fst->WeightTypesMatch(*it, "RmEpsilon")) {
49  return;
50  }
51  }
52  }
53  if (!fst->WeightTypesMatch(opts.weight_threshold, "RmEpsilon")) {
55  return;
56  }
57  RmEpsilonArgs3 args(fst, distance, opts);
58  Apply<Operation<RmEpsilonArgs3>>("RmEpsilon", fst->ArcType(), &args);
59 }
60 
64 
68 
72 
73 } // namespace script
74 } // namespace fst
bool WeightTypesMatch(const WeightClass &weight, const string &op_name) const
Definition: fst-class.cc:74
void RmEpsilon(RmEpsilonArgs1 *args)
Definition: rmepsilon.h:99
const WeightClass & weight_threshold
Definition: rmepsilon.h:21
const string & ArcType() const override
Definition: fst-class.h:289
REGISTER_FST_OPERATION(Compress, StdArc, CompressArgs)
int64_t int64
Definition: types.h:27
constexpr uint64 kError
Definition: properties.h:33
bool ArcTypesMatch(const M &m, const N &n, const string &op_name)
Definition: script-impl.h:177
static WeightClass Zero(const string &weight_type)
Definition: weight-class.cc:24
void SetProperties(uint64 props, uint64 mask)
Definition: fst-class.h:455
const string & WeightType() const override
Definition: fst-class.h:327