fstpushspecial.cc
Go to the documentation of this file.
1 // fstbin/fstpushspecial.cc
2 
3 // Copyright 2012 Daniel Povey
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/kaldi-io.h"
23 #include "util/parse-options.h"
24 #include "util/text-utils.h"
25 #include "fst/fstlib.h"
26 #include "fstext/fstext-utils.h"
27 #include "fstext/push-special.h"
28 #include "fstext/kaldi-fst-io.h"
29 
30 int main(int argc, char *argv[]) {
31  try {
32  using namespace kaldi;
33  using namespace fst;
34  using kaldi::int32;
35 
36  const char *usage =
37  "Pushes weights in an FST such that all the states\n"
38  "in the FST have arcs and final-probs with weights that\n"
39  "sum to the same amount (viewed as being in the log semiring).\n"
40  "Thus, the \"extra weight\" is distributed throughout the FST.\n"
41  "Tolerance parameter --delta controls how exact this is, and the\n"
42  "speed.\n"
43  "\n"
44  "Usage: fstpushspecial [options] [in.fst [out.fst] ]\n";
45 
46  BaseFloat delta = kDelta;
47  ParseOptions po(usage);
48  po.Register("delta", &delta, "Delta cost: after pushing, all states will "
49  "have a total weight that differs from the average by no more "
50  "than this.");
51  po.Read(argc, argv);
52 
53  if (po.NumArgs() > 2) {
54  po.PrintUsage();
55  exit(1);
56  }
57 
58  std::string fst_in_filename = po.GetOptArg(1),
59  fst_out_filename = po.GetOptArg(2);
60 
61  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
62 
63  PushSpecial(fst, delta);
64 
65  WriteFstKaldi(*fst, fst_out_filename);
66  delete fst;
67  return 0;
68  } catch(const std::exception &e) {
69  std::cerr << e.what();
70  return -1;
71  }
72 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void PushSpecial(VectorFst< StdArc > *fst, float delta)
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
std::string GetOptArg(int param) const