FST  openfst-1.7.3
OpenFst Library
fstepsnormalize-main.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 // Epsilon-normalizes an FST.
5 
6 #include <cstring>
7 #include <memory>
8 #include <string>
9 
10 #include <fst/flags.h>
12 #include <fst/script/getters.h>
13 
14 DECLARE_bool(eps_norm_output);
15 
16 int fstepsnormalize_main(int argc, char **argv) {
17  namespace s = fst::script;
20 
21  std::string usage = "Epsilon normalizes an FST.\n\n Usage: ";
22  usage += argv[0];
23  usage += " [in.fst [out.fst]]\n";
24 
25  std::set_new_handler(FailedNewHandler);
26  SET_FLAGS(usage.c_str(), &argc, &argv, true);
27  if (argc > 3) {
28  ShowUsage();
29  return 1;
30  }
31 
32  const std::string in_name =
33  (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
34  const std::string out_name =
35  (argc > 2 && strcmp(argv[2], "-") != 0) ? argv[2] : "";
36 
37  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
38  if (!ifst) return 1;
39 
40  VectorFstClass ofst(ifst->ArcType());
41 
42  s::EpsNormalize(*ifst, &ofst, s::GetEpsNormalizeType(FLAGS_eps_norm_output));
43 
44  return !ofst.Write(out_name);
45 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:121
DECLARE_bool(eps_norm_output)
EpsNormalizeType GetEpsNormalizeType(bool eps_norm_output)
Definition: getters.h:43
void FailedNewHandler()
Definition: compat.cc:20
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:209
int fstepsnormalize_main(int argc, char **argv)
void EpsNormalize(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, EpsNormalizeType type=EPS_NORM_INPUT)
Definition: epsnormalize.h:32