fstrmepslocal.cc File Reference
#include "base/kaldi-common.h"
#include "util/kaldi-io.h"
#include "util/parse-options.h"
#include "util/text-utils.h"
#include "fst/fstlib.h"
#include "fstext/determinize-star.h"
#include "fstext/fstext-utils.h"
#include "fstext/kaldi-fst-io.h"
Include dependency graph for fstrmepslocal.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 45 of file fstrmepslocal.cc.

References ParseOptions::GetOptArg(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), ParseOptions::Register(), fst::RemoveEpsLocal(), fst::RemoveEpsLocalSpecial(), and fst::WriteFstKaldi().

45  {
46  try {
47  using namespace kaldi;
48  using namespace fst;
49  using kaldi::int32;
50 
51  const char *usage =
52  "Removes some (but not all) epsilons in an algorithm that will always reduce the number of\n"
53  "arcs+states. Option to preserves equivalence in tropical or log semiring, and\n"
54  "if in tropical, stochasticit in either log or tropical.\n"
55  "\n"
56  "Usage: fstrmepslocal [in.fst [out.fst] ]\n";
57 
58  ParseOptions po(usage);
59  bool use_log = false;
60  bool stochastic_in_log = true;
61  po.Register("use-log", &use_log,
62  "Preserve equivalence in log semiring [false->tropical]\n");
63  po.Register("stochastic-in-log", &stochastic_in_log,
64  "Preserve stochasticity in log semiring [false->tropical]\n");
65  po.Read(argc, argv);
66 
67  if (po.NumArgs() > 2) {
68  po.PrintUsage();
69  exit(1);
70  }
71 
72  std::string fst_in_filename = po.GetOptArg(1),
73  fst_out_filename = po.GetOptArg(2);
74 
75  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
76 
77  if (!use_log && stochastic_in_log) {
79  } else if (use_log && !stochastic_in_log) {
80  std::cerr << "fstrmsymbols: invalid combination of flags\n";
81  return 1;
82  } else if (use_log) {
83  VectorFst<LogArc> log_fst;
84  Cast(*fst, &log_fst);
85  delete fst;
86  RemoveEpsLocal(&log_fst);
87  fst = new VectorFst<StdArc>;
88  Cast(log_fst, fst);
89  } else {
90  RemoveEpsLocal(fst);
91  }
92 
93  WriteFstKaldi(*fst, fst_out_filename);
94  delete fst;
95  return 0;
96  } catch(const std::exception &e) {
97  std::cerr << e.what();
98  return -1;
99  }
100 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void RemoveEpsLocal(MutableFst< Arc > *fst)
RemoveEpsLocal remove some (but not necessarily all) epsilons in an FST, using an algorithm that is g...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
void RemoveEpsLocalSpecial(MutableFst< StdArc > *fst)
As RemoveEpsLocal but takes care to preserve stochasticity when cast to LogArc.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)