All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fstaddsubsequentialloop.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/fstext-utils.h"
#include "fstext/context-fst.h"
#include "fstext/kaldi-fst-io.h"
Include dependency graph for fstaddsubsequentialloop.cc:

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 37 of file fstaddsubsequentialloop.cc.

References fst::AddSubsequentialLoop(), kaldi::ConvertStringToInteger(), ParseOptions::GetArg(), ParseOptions::GetOptArg(), fst::HighestNumberedInputSymbol(), KALDI_ERR, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), ParseOptions::Register(), and fst::WriteFstKaldi().

37  {
38  try {
39  using namespace kaldi;
40  using namespace fst;
41  using kaldi::int32;
42 
43  const char *usage =
44  "Minimizes FST after encoding [this algorithm applicable to all FSTs in tropical semiring]\n"
45  "\n"
46  "Usage: fstaddsubsequentialloop subseq_sym [in.fst [out.fst] ]\n"
47  "E.g.: fstaddsubsequentialloop 52 < LG.fst > LG_sub.fst\n";
48 
49  float delta = kDelta;
50  ParseOptions po(usage);
51  po.Register("delta", &delta,
52  "Delta likelihood used for quantization of weights");
53  po.Read(argc, argv);
54 
55  if (po.NumArgs() < 1 || po.NumArgs() > 3) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  int32 subseq_sym;
61  if (!ConvertStringToInteger(po.GetArg(1), &subseq_sym))
62  KALDI_ERR << "Invalid subsequential symbol "<<po.GetArg(1);
63 
64  std::string fst_in_filename = po.GetOptArg(2);
65 
66  std::string fst_out_filename = po.GetOptArg(3);
67 
68  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
69 
70  int32 h = HighestNumberedInputSymbol(*fst);
71  if (subseq_sym <= h) {
72  std::cerr << "fstaddsubsequentialloop.cc: subseq symbol does not seem right, "<<subseq_sym<<" <= "<<h<<'\n';
73  }
74 
75  AddSubsequentialLoop(subseq_sym, fst);
76 
77  WriteFstKaldi(*fst, fst_out_filename);
78  delete fst;
79  return 0;
80  } catch(const std::exception &e) {
81  std::cerr << e.what();
82  return -1;
83  }
84 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
Definition: text-utils.h:118
Definition: graph.dox:21
void AddSubsequentialLoop(typename Arc::Label subseq_symbol, MutableFst< Arc > *fst)
Modifies an FST so that it transuces the same paths, but the input side of the paths can all have the...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:127
Arc::Label HighestNumberedInputSymbol(const Fst< Arc > &fst)
Returns the highest numbered input symbol id of the FST (or zero for an empty FST.
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)