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.

165 lines
6.8 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. // The FST script interface permits users to interact with FSTs without knowing
  19. // their arc type. It does this by mapping compile-time polymorphism (in the
  20. // form of a arc-templated FST types) onto a shared virtual interface. It also
  21. // supports arc extension via a DSO interface. Due to the overhead of virtual
  22. // dispatch and registered function lookups, the script API is somewhat slower
  23. // then library API provided by types like StdVectorFst, but has the advantage
  24. // that it is designed not to crash (and to provide useful debugging
  25. // information) upon common user errors like passing invalid indices or
  26. // attempting comparison of incompatible FSTs. It is used both by the FST
  27. // binaries and the Python extension.
  28. //
  29. // This header includes all of the FST script functionality.
  30. #ifndef FST_SCRIPT_FSTSCRIPT_H_
  31. #define FST_SCRIPT_FSTSCRIPT_H_
  32. // Major classes
  33. #include <fst/script/arciterator-class.h>
  34. // Operations.
  35. #include <fst/script/arcsort.h>
  36. #include <fst/script/closure.h>
  37. #include <fst/script/compile.h>
  38. #include <fst/script/compose.h>
  39. #include <fst/script/concat.h>
  40. #include <fst/script/connect.h>
  41. #include <fst/script/convert.h>
  42. #include <fst/script/decode.h>
  43. #include <fst/script/determinize.h>
  44. #include <fst/script/difference.h>
  45. #include <fst/script/disambiguate.h>
  46. #include <fst/script/draw.h>
  47. #include <fst/script/encode.h>
  48. #include <fst/script/encodemapper-class.h>
  49. #include <fst/script/epsnormalize.h>
  50. #include <fst/script/equal.h>
  51. #include <fst/script/equivalent.h>
  52. #include <fst/script/fst-class.h>
  53. // Flag-to-enum parsers.
  54. #include <fst/script/getters.h>
  55. #include <fst/script/info.h>
  56. #include <fst/script/intersect.h>
  57. #include <fst/script/invert.h>
  58. #include <fst/script/isomorphic.h>
  59. #include <fst/script/map.h>
  60. #include <fst/script/minimize.h>
  61. #include <fst/script/print.h>
  62. #include <fst/script/project.h>
  63. #include <fst/script/prune.h>
  64. #include <fst/script/push.h>
  65. #include <fst/script/randequivalent.h>
  66. #include <fst/script/randgen.h>
  67. #include <fst/script/relabel.h>
  68. #include <fst/script/replace.h>
  69. #include <fst/script/reverse.h>
  70. #include <fst/script/reweight.h>
  71. #include <fst/script/rmepsilon.h>
  72. // Templates like Operation<> and Apply<>.
  73. #include <fst/script/script-impl.h>
  74. #include <fst/script/shortest-distance.h>
  75. #include <fst/script/shortest-path.h>
  76. #include <fst/script/stateiterator-class.h>
  77. #include <fst/script/synchronize.h>
  78. #include <fst/script/text-io.h>
  79. #include <fst/script/topsort.h>
  80. #include <fst/script/union.h>
  81. #include <fst/script/verify.h>
  82. #include <fst/script/weight-class.h>
  83. // This class is necessary because registering each of the operations
  84. // separately overfills the stack, as there's so many of them.
  85. namespace fst {
  86. namespace script {
  87. template <class Arc>
  88. class AllFstOperationsRegisterer {
  89. public:
  90. AllFstOperationsRegisterer() {
  91. RegisterBatch1();
  92. RegisterBatch2();
  93. }
  94. private:
  95. void RegisterBatch1() {
  96. REGISTER_FST_OPERATION(ArcSort, Arc, FstArcSortArgs);
  97. REGISTER_FST_OPERATION(Closure, Arc, FstClosureArgs);
  98. REGISTER_FST_OPERATION(CompileInternal, Arc, FstCompileArgs);
  99. REGISTER_FST_OPERATION(Compose, Arc, FstComposeArgs);
  100. REGISTER_FST_OPERATION(Concat, Arc, FstConcatArgs1);
  101. REGISTER_FST_OPERATION(Concat, Arc, FstConcatArgs2);
  102. REGISTER_FST_OPERATION(Concat, Arc, FstConcatArgs3);
  103. REGISTER_FST_OPERATION(Connect, Arc, MutableFstClass);
  104. REGISTER_FST_OPERATION(Convert, Arc, FstConvertArgs);
  105. REGISTER_FST_OPERATION(Decode, Arc, FstDecodeArgs);
  106. REGISTER_FST_OPERATION(Determinize, Arc, FstDeterminizeArgs);
  107. REGISTER_FST_OPERATION(Difference, Arc, FstDifferenceArgs);
  108. REGISTER_FST_OPERATION(Disambiguate, Arc, FstDisambiguateArgs);
  109. REGISTER_FST_OPERATION(Draw, Arc, FstDrawArgs);
  110. REGISTER_FST_OPERATION(Encode, Arc, FstEncodeArgs);
  111. REGISTER_FST_OPERATION(EpsNormalize, Arc, FstEpsNormalizeArgs);
  112. REGISTER_FST_OPERATION(Equal, Arc, FstEqualArgs);
  113. REGISTER_FST_OPERATION(Equivalent, Arc, FstEquivalentArgs);
  114. REGISTER_FST_OPERATION(Info, Arc, FstInfoArgs);
  115. REGISTER_FST_OPERATION(InitArcIteratorClass, Arc, InitArcIteratorClassArgs);
  116. REGISTER_FST_OPERATION(InitMutableArcIteratorClass, Arc,
  117. InitMutableArcIteratorClassArgs);
  118. REGISTER_FST_OPERATION(InitStateIteratorClass, Arc,
  119. InitStateIteratorClassArgs);
  120. REGISTER_FST_OPERATION(Intersect, Arc, FstIntersectArgs);
  121. REGISTER_FST_OPERATION(Invert, Arc, MutableFstClass);
  122. REGISTER_FST_OPERATION(Isomorphic, Arc, FstIsomorphicArgs);
  123. }
  124. void RegisterBatch2() {
  125. REGISTER_FST_OPERATION(Map, Arc, FstMapArgs);
  126. REGISTER_FST_OPERATION(Minimize, Arc, FstMinimizeArgs);
  127. REGISTER_FST_OPERATION(Print, Arc, FstPrintArgs);
  128. REGISTER_FST_OPERATION(Project, Arc, FstProjectArgs);
  129. REGISTER_FST_OPERATION(Prune, Arc, FstPruneArgs1);
  130. REGISTER_FST_OPERATION(Prune, Arc, FstPruneArgs2);
  131. REGISTER_FST_OPERATION(Push, Arc, FstPushArgs1);
  132. REGISTER_FST_OPERATION(Push, Arc, FstPushArgs2);
  133. REGISTER_FST_OPERATION(RandEquivalent, Arc, FstRandEquivalentArgs);
  134. REGISTER_FST_OPERATION(RandGen, Arc, FstRandGenArgs);
  135. REGISTER_FST_OPERATION(Relabel, Arc, FstRelabelArgs1);
  136. REGISTER_FST_OPERATION(Relabel, Arc, FstRelabelArgs2);
  137. REGISTER_FST_OPERATION(Replace, Arc, FstReplaceArgs);
  138. REGISTER_FST_OPERATION(Reverse, Arc, FstReverseArgs);
  139. REGISTER_FST_OPERATION(Reweight, Arc, FstReweightArgs);
  140. REGISTER_FST_OPERATION(RmEpsilon, Arc, FstRmEpsilonArgs);
  141. REGISTER_FST_OPERATION(ShortestDistance, Arc, FstShortestDistanceArgs1);
  142. REGISTER_FST_OPERATION(ShortestDistance, Arc, FstShortestDistanceArgs2);
  143. REGISTER_FST_OPERATION(ShortestDistance, Arc, FstShortestDistanceArgs3);
  144. REGISTER_FST_OPERATION(ShortestPath, Arc, FstShortestPathArgs);
  145. REGISTER_FST_OPERATION(Synchronize, Arc, FstSynchronizeArgs);
  146. REGISTER_FST_OPERATION(TopSort, Arc, FstTopSortArgs);
  147. REGISTER_FST_OPERATION(Union, Arc, FstUnionArgs1);
  148. REGISTER_FST_OPERATION(Union, Arc, FstUnionArgs2);
  149. REGISTER_FST_OPERATION(Verify, Arc, FstVerifyArgs);
  150. }
  151. };
  152. } // namespace script
  153. } // namespace fst
  154. #define REGISTER_FST_OPERATIONS(Arc) \
  155. AllFstOperationsRegisterer<Arc> register_all_fst_operations##Arc;
  156. #endif // FST_SCRIPT_FSTSCRIPT_H_