FST  openfst-1.7.2
OpenFst Library
fstproject-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 // Projects a transduction onto its input or output language.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
12 #include <fst/script/getters.h>
13 #include <fst/script/project.h>
14 
15 DECLARE_bool(project_output);
16 
17 int fstproject_main(int argc, char **argv) {
18  namespace s = fst::script;
20 
21  string usage =
22  "Projects a transduction onto its input"
23  " or output language.\n\n Usage: ";
24  usage += argv[0];
25  usage += " [in.fst [out.fst]]\n";
26 
27  std::set_new_handler(FailedNewHandler);
28  SET_FLAGS(usage.c_str(), &argc, &argv, true);
29  if (argc > 3) {
30  ShowUsage();
31  return 1;
32  }
33 
34  const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
35  const string out_name = argc > 2 ? argv[2] : "";
36 
37  std::unique_ptr<MutableFstClass> fst(MutableFstClass::Read(in_name, true));
38  if (!fst) return 1;
39 
40  s::Project(fst.get(), s::GetProjectType(FLAGS_project_output));
41 
42  return !fst->Write(out_name);
43 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
void Project(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, ProjectType project_type)
Definition: project.h:65
ProjectType GetProjectType(bool project_output)
Definition: getters.h:50
DECLARE_bool(project_output)
int fstproject_main(int argc, char **argv)