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.

63 lines
1.8 KiB

  1. // lm/arpa-lm-compiler.h
  2. // Copyright 2009-2011 Gilles Boulianne
  3. // Copyright 2016 Smart Action LLC (kkm)
  4. // See ../../COPYING for clarification regarding multiple authors
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License");
  7. // you may not use this file except in compliance with the License.
  8. // You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  14. // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  15. // MERCHANTABLITY OR NON-INFRINGEMENT.
  16. // See the Apache 2 License for the specific language governing permissions and
  17. // limitations under the License.
  18. #ifndef KALDI_LM_ARPA_LM_COMPILER_H_
  19. #define KALDI_LM_ARPA_LM_COMPILER_H_
  20. #include <fst/fstlib.h>
  21. #include "lm/arpa-file-parser.h"
  22. namespace kaldi {
  23. class ArpaLmCompilerImplInterface;
  24. class ArpaLmCompiler : public ArpaFileParser {
  25. public:
  26. ArpaLmCompiler(const ArpaParseOptions& options, int sub_eps,
  27. fst::SymbolTable* symbols)
  28. : ArpaFileParser(options, symbols), sub_eps_(sub_eps), impl_(NULL) {}
  29. ~ArpaLmCompiler();
  30. const fst::StdVectorFst& Fst() const { return fst_; }
  31. fst::StdVectorFst* MutableFst() { return &fst_; }
  32. protected:
  33. // ArpaFileParser overrides.
  34. virtual void HeaderAvailable();
  35. virtual void ConsumeNGram(const NGram& ngram);
  36. virtual void ReadComplete();
  37. private:
  38. // this function removes states that only have a backoff arc coming
  39. // out of them.
  40. void RemoveRedundantStates();
  41. void Check() const;
  42. int sub_eps_;
  43. ArpaLmCompilerImplInterface* impl_; // Owned.
  44. fst::StdVectorFst fst_;
  45. template <class HistKey>
  46. friend class ArpaLmCompilerImpl;
  47. };
  48. } // namespace kaldi
  49. #endif // KALDI_LM_ARPA_LM_COMPILER_H_