All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fstpropfinal.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-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 fstpropfinal.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 42 of file fstpropfinal.cc.

References kaldi::ConvertStringToInteger(), ParseOptions::GetOptArg(), KALDI_ERR, KALDI_WARN, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), fst::PropagateFinal(), ParseOptions::Read(), fst::ReadFstKaldi(), and fst::WriteFstKaldi().

42  {
43  try {
44  using namespace kaldi;
45  using namespace fst;
46  using kaldi::int32;
47 
48  const char *usage =
49  "Propagates final-states through phi transitions\n"
50  "\n"
51  "Usage: fstpropfinal phi-label [in.fst [out.fst] ]\n";
52 
53  ParseOptions po(usage);
54 
55  po.Read(argc, argv);
56 
57  if (po.NumArgs() > 2) {
58  po.PrintUsage();
59  exit(1);
60  }
61 
62  std::string phi_str = po.GetOptArg(1),
63  fst_in_str = po.GetOptArg(2),
64  fst_out_str = po.GetOptArg(3);
65 
66 
67  int32 phi_label;
68  if (!ConvertStringToInteger(phi_str, &phi_label)
69  || phi_label < 0)
70  KALDI_ERR << "Bad phi label " << phi_label;
71  if (phi_label == 0)
72  KALDI_WARN << "Phi_label == 0, may not be a good idea.";
73 
74 
75  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_str);
76 
77  PropagateFinal(phi_label, fst);
78 
79  WriteFstKaldi(*fst, fst_out_str);
80  delete fst;
81  return 0;
82  } catch(const std::exception &e) {
83  std::cerr << e.what();
84  return -1;
85  }
86 }
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
void PropagateFinal(typename Arc::Label phi_label, MutableFst< Arc > *fst)
Definition: graph.dox:21
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
#define KALDI_WARN
Definition: kaldi-error.h:130
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)