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.

72 lines
2.3 KiB

  1. // Copyright 2005-2024 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the 'License');
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an 'AS IS' BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. // See www.openfst.org for extensive documentation on this weighted
  16. // finite-state transducer library.
  17. #ifndef FST_SCRIPT_PUSH_H_
  18. #define FST_SCRIPT_PUSH_H_
  19. #include <cstdint>
  20. #include <tuple>
  21. #include <fst/fst.h>
  22. #include <fst/mutable-fst.h>
  23. #include <fst/push.h>
  24. #include <fst/reweight.h>
  25. #include <fst/shortest-distance.h>
  26. #include <fst/script/fst-class.h>
  27. namespace fst {
  28. namespace script {
  29. using FstPushArgs1 = std::tuple<MutableFstClass *, ReweightType, float, bool>;
  30. template <class Arc>
  31. void Push(FstPushArgs1 *args) {
  32. MutableFst<Arc> *fst = std::get<0>(*args)->GetMutableFst<Arc>();
  33. Push(fst, std::get<1>(*args), std::get<2>(*args), std::get<3>(*args));
  34. }
  35. using FstPushArgs2 = std::tuple<const FstClass &, MutableFstClass *, uint8_t,
  36. ReweightType, float>;
  37. template <class Arc>
  38. void Push(FstPushArgs2 *args) {
  39. const Fst<Arc> &ifst = *std::get<0>(*args).GetFst<Arc>();
  40. MutableFst<Arc> *ofst = std::get<1>(*args)->GetMutableFst<Arc>();
  41. switch (std::get<3>(*args)) {
  42. case REWEIGHT_TO_FINAL: {
  43. Push<Arc, REWEIGHT_TO_FINAL>(ifst, ofst, std::get<2>(*args),
  44. std::get<4>(*args));
  45. return;
  46. }
  47. case REWEIGHT_TO_INITIAL: {
  48. Push<Arc, REWEIGHT_TO_INITIAL>(ifst, ofst, std::get<2>(*args),
  49. std::get<4>(*args));
  50. return;
  51. }
  52. }
  53. }
  54. void Push(MutableFstClass *fst, ReweightType type = REWEIGHT_TO_INITIAL,
  55. float delta = kShortestDelta, bool remove_total_weight = false);
  56. void Push(const FstClass &ifst, MutableFstClass *ofst, uint8_t flags,
  57. ReweightType rew_type, float delta = kShortestDelta);
  58. } // namespace script
  59. } // namespace fst
  60. #endif // FST_SCRIPT_PUSH_H_