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