FST  openfst-1.7.3
OpenFst Library
fstclosure-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 // Creates the Kleene closure of an FST.
5 
6 #include <cstring>
7 #include <memory>
8 #include <string>
9 
10 #include <fst/flags.h>
11 #include <fst/script/closure.h>
12 #include <fst/script/getters.h>
13 
14 DECLARE_bool(closure_plus);
15 
16 int fstclosure_main(int argc, char **argv) {
17  namespace s = fst::script;
19 
20  std::string usage = "Creates the Kleene closure of an FST.\n\n Usage: ";
21  usage += argv[0];
22  usage += " [in.fst [out.fst]]\n";
23 
24  std::set_new_handler(FailedNewHandler);
25  SET_FLAGS(usage.c_str(), &argc, &argv, true);
26  if (argc > 3) {
27  ShowUsage();
28  return 1;
29  }
30 
31  const std::string in_name =
32  (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
33  const std::string out_name =
34  (argc > 2 && strcmp(argv[2], "-") != 0) ? argv[2] : "";
35 
36  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
37  if (!fst) return 1;
38 
39  s::Closure(fst.get(), s::GetClosureType(FLAGS_closure_plus));
40 
41  return !fst->Write(out_name);
42 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:121
void Closure(MutableFst< Arc > *fst, ClosureType closure_type)
Definition: closure.h:32
void FailedNewHandler()
Definition: compat.cc:20
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:209
ClosureType GetClosureType(bool closure_plus)
Definition: getters.h:30
DECLARE_bool(closure_plus)
int fstclosure_main(int argc, char **argv)