FST  openfst-1.7.2
OpenFst Library
fstdisambiguate-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 // Disambiguates an FST.
5 
6 #include <cstring>
7 
8 #include <memory>
9 #include <string>
10 
11 #include <fst/flags.h>
13 
14 DECLARE_double(delta);
15 DECLARE_int64(nstate);
16 DECLARE_string(weight);
17 DECLARE_int64(subsequential_label);
18 
19 int fstdisambiguate_main(int argc, char **argv) {
20  namespace s = fst::script;
24 
25  string usage = "Disambiguates an FST.\n\n Usage: ";
26  usage += argv[0];
27  usage += " [in.fst [out.fst]]\n";
28 
29  std::set_new_handler(FailedNewHandler);
30  SET_FLAGS(usage.c_str(), &argc, &argv, true);
31  if (argc > 3) {
32  ShowUsage();
33  return 1;
34  }
35 
36  const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : "";
37  const string out_name = argc > 2 ? argv[2] : "";
38 
39  std::unique_ptr<FstClass> ifst(FstClass::Read(in_name));
40  if (!ifst) return 1;
41 
42  VectorFstClass ofst(ifst->ArcType());
43 
44  const auto weight_threshold =
45  FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType())
46  : WeightClass(ifst->WeightType(), FLAGS_weight);
47 
48  const s::DisambiguateOptions opts(FLAGS_delta, weight_threshold, FLAGS_nstate,
49  FLAGS_subsequential_label);
50 
51  s::Disambiguate(*ifst, &ofst, opts);
52 
53  return !ofst.Write(out_name);
54 }
void ShowUsage(bool long_usage=true)
Definition: flags.cc:124
DECLARE_string(weight)
int fstdisambiguate_main(int argc, char **argv)
void FailedNewHandler()
Definition: compat.cc:25
#define SET_FLAGS(usage, argc, argv, rmflags)
Definition: flags.h:214
DECLARE_int64(nstate)
void Disambiguate(const Fst< Arc > &ifst, MutableFst< Arc > *ofst, const DisambiguateOptions< Arc > &opts=DisambiguateOptions< Arc >())
Definition: disambiguate.h:555
DECLARE_double(delta)