fstminimizeencoded.cc
Go to the documentation of this file.
1 // fstbin/fstminimizeencoded.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
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"
27 #include "fstext/fstext-utils.h"
28 #include "fstext/kaldi-fst-io.h"
29 
30 /* some test examples:
31  ( echo "0 0 0 0"; echo "0 0" ) | fstcompile | fstminimizeencoded | fstprint
32  ( echo "0 1 0 0"; echo " 0 2 0 0"; echo "1 0"; echo "2 0"; ) | fstcompile | fstminimizeencoded | fstprint
33 */
34 
35 int main(int argc, char *argv[]) {
36  try {
37  using namespace kaldi;
38  using namespace fst;
39  using kaldi::int32;
40 
41  const char *usage =
42  "Minimizes FST after encoding [similar to fstminimize, but no weight-pushing]\n"
43  "\n"
44  "Usage: fstminimizeencoded [in.fst [out.fst] ]\n";
45 
46  float delta = kDelta;
47  ParseOptions po(usage);
48  po.Register("delta", &delta, "Delta likelihood used for quantization of weights");
49  po.Read(argc, argv);
50 
51  if (po.NumArgs() > 2) {
52  po.PrintUsage();
53  exit(1);
54  }
55 
56  std::string fst_in_filename = po.GetOptArg(1),
57  fst_out_filename = po.GetOptArg(2);
58 
59  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
60 
61  MinimizeEncoded(fst, delta);
62 
63  WriteFstKaldi(*fst, fst_out_filename);
64 
65  delete fst;
66  return 0;
67  } catch(const std::exception &e) {
68  std::cerr << e.what();
69  return -1;
70  }
71  return 0;
72 }
73 
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].
void MinimizeEncoded(VectorFst< Arc > *fst, float delta=kDelta)
Definition: fstext-utils.h:114
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
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 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