1 // fstbin/fstminimizeencoded.cc
3 // Copyright 2009-2011 Microsoft Corporation
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.
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/determinize-star.h"
27 #include "fstext/fstext-utils.h"
28 #include "fstext/kaldi-fst-io.h"
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 */
35 int main(int argc, char *argv[]) {
36 try {
37 using namespace kaldi;
38 using namespace fst;
39 using kaldi::int32;
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";
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);
51 if (po.NumArgs() > 2) {
52 po.PrintUsage();
53 exit(1);
54 }
56 std::string fst_in_filename = po.GetOptArg(1),
57 fst_out_filename = po.GetOptArg(2);
59 VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
61 MinimizeEncoded(fst, delta);
63 WriteFstKaldi(*fst, fst_out_filename);
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 }