You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.1 KiB

  1. // fstbin/fstminimizeencoded.cc
  2. // Copyright 2009-2011 Microsoft Corporation
  3. // See ../../COPYING for clarification regarding multiple authors
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. // MERCHANTABLITY OR NON-INFRINGEMENT.
  15. // See the Apache 2 License for the specific language governing permissions and
  16. // limitations under the License.
  17. #include "base/kaldi-common.h"
  18. #include "fst/fstlib.h"
  19. #include "fstext/determinize-star.h"
  20. #include "fstext/fstext-utils.h"
  21. #include "fstext/kaldi-fst-io.h"
  22. #include "util/kaldi-io.h"
  23. #include "util/parse-options.h"
  24. #include "util/text-utils.h"
  25. /* some test examples:
  26. ( echo "0 0 0 0"; echo "0 0" ) | fstcompile | fstminimizeencoded | fstprint
  27. ( echo "0 1 0 0"; echo " 0 2 0 0"; echo "1 0"; echo "2 0"; ) | fstcompile |
  28. fstminimizeencoded | fstprint
  29. */
  30. int main(int argc, char* argv[]) {
  31. try {
  32. using namespace kaldi; // NOLINT
  33. using namespace fst; // NOLINT
  34. using kaldi::int32;
  35. const char* usage =
  36. "Minimizes FST after encoding [similar to fstminimize, but no "
  37. "weight-pushing]\n"
  38. "\n"
  39. "Usage: fstminimizeencoded [in.fst [out.fst] ]\n";
  40. float delta = kDelta;
  41. ParseOptions po(usage);
  42. po.Register("delta", &delta,
  43. "Delta likelihood used for quantization of weights");
  44. po.Read(argc, argv);
  45. if (po.NumArgs() > 2) {
  46. po.PrintUsage();
  47. exit(1);
  48. }
  49. std::string fst_in_filename = po.GetOptArg(1),
  50. fst_out_filename = po.GetOptArg(2);
  51. VectorFst<StdArc>* fst = ReadFstKaldi(fst_in_filename);
  52. MinimizeEncoded(fst, delta);
  53. WriteFstKaldi(*fst, fst_out_filename);
  54. delete fst;
  55. return 0;
  56. } catch (const std::exception& e) {
  57. std::cerr << e.what();
  58. return -1;
  59. }
  60. return 0;
  61. }