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

References fst::Factor(), ParseOptions::GetArg(), KALDI_VLOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), ParseOptions::Register(), and fst::WriteFstKaldi().

42  {
43  try {
44  using namespace kaldi;
45  using namespace fst;
46  using kaldi::int32;
47  /*
48  fstfactor in.fst out1.fst out2.fst
49  produces two fsts such that the composition of out1.fst and out2.fst
50  is equivalent to in.fst. It does this by representing linear chains of
51  input symbols in in.fst, as special symbols that will be on the output
52  of out1.fst (and the input of out2.fst).
53 
54  out1.fst has a simple structure with a loop-state that's initial and final,
55  and output symbols leading to linear chains of input symbols that come back
56  to the loop state.
57  */
58 
59  const char *usage =
60  "Factor fst into two parts (by removing linear chains)\n"
61  "\n"
62  "Usage: fstfactor in.fst out1.fst out2.fst\n";
63 
64  ParseOptions po(usage);
65 
66  bool push = false;
67 
68  po.Register("push", &push,
69  "Push output symbols to initial state before factoring");
70 
71  po.Read(argc, argv);
72 
73  if (po.NumArgs() != 3) {
74  po.PrintUsage();
75  exit(1);
76  }
77 
78 
79  std::string fst_in_filename = po.GetArg(1),
80  fst1_out_filename = po.GetArg(2),
81  fst2_out_filename = po.GetArg(3);
82 
83  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
84 
85  if (push) {
86  KALDI_VLOG(1) << "Pushing symbols\n";
87  VectorFst<StdArc> fst_pushed;
88  Push<StdArc, REWEIGHT_TO_INITIAL>(*fst, &fst_pushed, kPushLabels, kDelta);
89  *fst = fst_pushed;
90  KALDI_VLOG(1) << "Factoring\n";
91  }
92 
93  VectorFst<StdArc> fst1, fst2;
94  Factor(*fst, &fst1, &fst2); // int32 is enough for forseeable uses..
95 
96  delete fst;
97 
98  WriteFstKaldi(fst1, fst1_out_filename);
99  WriteFstKaldi(fst2, fst2_out_filename);
100  return 0;
101  } catch(const std::exception &e) {
102  std::cerr << e.what();
103  return -1;
104  }
105 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
void Factor(const Fst< Arc > &fst, MutableFst< Arc > *ofst, vector< vector< I > > *symbols_out)
Factor identifies linear chains of states with an olabel (if any) only on the first arc of the chain...
Definition: factor-inl.h:69
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
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
#define KALDI_VLOG(v)
Definition: kaldi-error.h:136