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.

97 lines
3.5 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. //
  18. // Getters for converting command-line arguments into the appropriate enums
  19. // or bitmasks, with the simplest ones defined as inline.
  20. #ifndef FST_SCRIPT_GETTERS_H_
  21. #define FST_SCRIPT_GETTERS_H_
  22. #include <cstdint>
  23. #include <limits>
  24. #include <string>
  25. #include <fst/log.h>
  26. #include <fst/compose.h> // For ComposeFilter.
  27. #include <fst/determinize.h> // For DeterminizeType.
  28. #include <fst/encode.h> // For kEncodeLabels (etc.).
  29. #include <fst/epsnormalize.h> // For EpsNormalizeType.
  30. #include <fst/project.h> // For ProjectType.
  31. #include <fst/push.h> // For kPushWeights (etc.).
  32. #include <fst/queue.h> // For QueueType.
  33. #include <fst/rational.h> // For ClosureType.
  34. #include <fst/replace-util.h>
  35. #include <fst/reweight.h>
  36. #include <fst/string.h> // For TokenType.
  37. #include <fst/script/arcfilter-impl.h> // For ArcFilterType.
  38. #include <fst/script/arcsort.h> // For ArcSortType.
  39. #include <fst/script/map.h> // For MapType.
  40. #include <fst/script/script-impl.h> // For RandArcSelection.
  41. #include <string_view>
  42. namespace fst {
  43. namespace script {
  44. inline constexpr uint64_t kDefaultSeed = std::numeric_limits<uint64_t>::max();
  45. bool GetArcFilterType(std::string_view str, ArcFilterType *arc_filter_type);
  46. bool GetArcSortType(std::string_view str, ArcSortType *sort_type);
  47. bool GetClosureType(std::string_view str, ClosureType *closure_type);
  48. bool GetComposeFilter(std::string_view str, ComposeFilter *compose_filter);
  49. bool GetDeterminizeType(std::string_view str, DeterminizeType *det_type);
  50. inline uint8_t GetEncodeFlags(bool encode_labels, bool encode_weights) {
  51. return (encode_labels ? kEncodeLabels : 0) |
  52. (encode_weights ? kEncodeWeights : 0);
  53. }
  54. bool GetEpsNormalizeType(std::string_view str,
  55. EpsNormalizeType *eps_norm_type);
  56. bool GetMapType(std::string_view str, MapType *map_type);
  57. bool GetProjectType(std::string_view str, ProjectType *project_type);
  58. inline uint8_t GetPushFlags(bool push_weights, bool push_labels,
  59. bool remove_total_weight,
  60. bool remove_common_affix) {
  61. return ((push_weights ? kPushWeights : 0) | (push_labels ? kPushLabels : 0) |
  62. (remove_total_weight ? kPushRemoveTotalWeight : 0) |
  63. (remove_common_affix ? kPushRemoveCommonAffix : 0));
  64. }
  65. bool GetQueueType(std::string_view str, QueueType *queue_type);
  66. bool GetRandArcSelection(std::string_view str, RandArcSelection *ras);
  67. bool GetReplaceLabelType(std::string_view str, bool epsilon_on_replace,
  68. ReplaceLabelType *rlt);
  69. bool GetReweightType(std::string_view str, ReweightType *reweight_type);
  70. uint64_t GetSeed(uint64_t seed);
  71. bool GetTokenType(std::string_view str, TokenType *token_type);
  72. } // namespace script
  73. } // namespace fst
  74. #endif // FST_SCRIPT_GETTERS_H_