react-native-executorch 0.10.5 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/README.md +10 -1
  2. package/android/build.gradle.kts +4 -3
  3. package/ios/RnExecutorch.mm +15 -17
  4. package/lib/module/fetcher/fetcher.js +35 -122
  5. package/lib/module/fetcher/fetcher.js.map +1 -1
  6. package/lib/module/fetcher/telemetry.js +1 -1
  7. package/lib/module/index.js +12 -13
  8. package/lib/module/index.js.map +1 -1
  9. package/lib/module/models.js +4 -2
  10. package/lib/module/models.js.map +1 -1
  11. package/lib/typescript/src/fetcher/fetcher.d.ts +3 -7
  12. package/lib/typescript/src/fetcher/fetcher.d.ts.map +1 -1
  13. package/lib/typescript/src/models.d.ts.map +1 -1
  14. package/package.json +9 -7
  15. package/react-native-executorch.podspec +6 -2
  16. package/src/fetcher/fetcher.ts +38 -131
  17. package/src/fetcher/telemetry.ts +1 -1
  18. package/src/models.ts +6 -1
  19. package/third-party/common/phonemis/CMakeLists.txt +70 -14
  20. package/third-party/common/phonemis/README.md +183 -33
  21. package/third-party/common/phonemis/THIRD_PARTY_NOTICES.md +57 -0
  22. package/third-party/common/phonemis/knowledge/code_style.md +642 -0
  23. package/third-party/common/phonemis/licenses/Unicode-3.0.txt +39 -0
  24. package/third-party/common/phonemis/licenses/misaki-Apache-2.0.txt +201 -0
  25. package/third-party/common/phonemis/licenses/nlohmann-json-MIT.txt +21 -0
  26. package/third-party/common/phonemis/licenses/xsimd-BSD-3-Clause.txt +29 -0
  27. package/third-party/common/phonemis/src/phonemis/base/config.h +6 -0
  28. package/third-party/common/phonemis/src/phonemis/base/ipipeline.cpp +75 -0
  29. package/third-party/common/phonemis/src/phonemis/base/ipipeline.h +21 -0
  30. package/third-party/common/phonemis/src/phonemis/base/phonemizer/constants.h +2 -5
  31. package/third-party/common/phonemis/src/phonemis/base/phonemizer/lexicon_phonemizer.cpp +3 -4
  32. package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/neural_phonemizer.cpp +17 -8
  33. package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/neural_phonemizer.h +4 -0
  34. package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/tokenizer.cpp +21 -6
  35. package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/tokenizer.h +13 -4
  36. package/third-party/common/phonemis/src/phonemis/base/pipeline.cpp +8 -0
  37. package/third-party/common/phonemis/src/phonemis/base/pipeline.h +19 -0
  38. package/third-party/common/phonemis/src/phonemis/base/processor/common/conditions.cpp +37 -0
  39. package/third-party/common/phonemis/src/phonemis/base/processor/common/conditions.h +45 -0
  40. package/third-party/common/phonemis/src/phonemis/base/processor/common/constants.h +10 -0
  41. package/third-party/common/phonemis/src/phonemis/base/processor/common/context.cpp +105 -0
  42. package/third-party/common/phonemis/src/phonemis/base/processor/common/context.h +49 -0
  43. package/third-party/common/phonemis/src/phonemis/base/processor/common/document.cpp +173 -0
  44. package/third-party/common/phonemis/src/phonemis/base/processor/common/document.h +67 -0
  45. package/third-party/common/phonemis/src/phonemis/base/processor/common/text.cpp +75 -0
  46. package/third-party/common/phonemis/src/phonemis/base/processor/common/text.h +60 -0
  47. package/third-party/common/phonemis/src/phonemis/base/processor/common/types.h +18 -0
  48. package/third-party/common/phonemis/src/phonemis/base/processor/config.h +53 -0
  49. package/third-party/common/phonemis/src/phonemis/base/processor/layer.h +9 -7
  50. package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/constants.h +20 -0
  51. package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/layer.cpp +89 -0
  52. package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/layer.h +35 -0
  53. package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/types.h +16 -0
  54. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/kind.h +40 -0
  55. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/layer.h +382 -0
  56. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/notation.h +30 -0
  57. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/numerals.cpp +51 -0
  58. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/numerals.h +31 -0
  59. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern.h +30 -0
  60. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern_set.cpp +17 -0
  61. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern_set.h +31 -0
  62. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/patterns.cpp +811 -0
  63. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/patterns.h +285 -0
  64. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/primitives.cpp +64 -0
  65. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/primitives.h +23 -0
  66. package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/types.h +94 -0
  67. package/third-party/common/phonemis/src/phonemis/base/processor/layers/sanitizer/layer.cpp +19 -0
  68. package/third-party/common/phonemis/src/phonemis/base/processor/{sanitizer_layer.h → layers/sanitizer/layer.h} +8 -8
  69. package/third-party/common/phonemis/src/phonemis/base/processor/layers/sym2word/layer.cpp +65 -0
  70. package/third-party/common/phonemis/src/phonemis/base/processor/layers/sym2word/layer.h +29 -0
  71. package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/layer.cpp +170 -0
  72. package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/layer.h +40 -0
  73. package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/types.h +25 -0
  74. package/third-party/common/phonemis/src/phonemis/base/processor/layers/trim/layer.cpp +47 -0
  75. package/third-party/common/phonemis/src/phonemis/base/processor/layers/trim/layer.h +19 -0
  76. package/third-party/common/phonemis/src/phonemis/base/processor/preprocessor.cpp +60 -0
  77. package/third-party/common/phonemis/src/phonemis/base/processor/preprocessor.h +45 -0
  78. package/third-party/common/phonemis/src/phonemis/base/processor/processor.cpp +6 -7
  79. package/third-party/common/phonemis/src/phonemis/base/processor/processor.h +14 -10
  80. package/third-party/common/phonemis/src/phonemis/base/tagger/hmm_tagger.cpp +89 -52
  81. package/third-party/common/phonemis/src/phonemis/base/tagger/hmm_tagger.h +16 -9
  82. package/third-party/common/phonemis/src/phonemis/base/tokenizer/tokenizer.cpp +13 -12
  83. package/third-party/common/phonemis/src/phonemis/lang/de/constants.h +183 -19
  84. package/third-party/common/phonemis/src/phonemis/lang/de/num2word.cpp +355 -309
  85. package/third-party/common/phonemis/src/phonemis/lang/de/num2word.h +42 -17
  86. package/third-party/common/phonemis/src/phonemis/lang/de/patterns.cpp +56 -0
  87. package/third-party/common/phonemis/src/phonemis/lang/de/patterns.h +15 -0
  88. package/third-party/common/phonemis/src/phonemis/lang/de/pipeline.h +3 -3
  89. package/third-party/common/phonemis/src/phonemis/lang/en/constants.h +181 -30
  90. package/third-party/common/phonemis/src/phonemis/lang/en/hmm_tagger.cpp +5 -7
  91. package/third-party/common/phonemis/src/phonemis/lang/en/num2word.cpp +232 -135
  92. package/third-party/common/phonemis/src/phonemis/lang/en/num2word.h +41 -16
  93. package/third-party/common/phonemis/src/phonemis/lang/en/pipeline.h +3 -10
  94. package/third-party/common/phonemis/src/phonemis/lang/es/constants.h +182 -60
  95. package/third-party/common/phonemis/src/phonemis/lang/es/num2word.cpp +247 -212
  96. package/third-party/common/phonemis/src/phonemis/lang/es/num2word.h +38 -18
  97. package/third-party/common/phonemis/src/phonemis/lang/es/patterns.cpp +50 -0
  98. package/third-party/common/phonemis/src/phonemis/lang/es/patterns.h +15 -0
  99. package/third-party/common/phonemis/src/phonemis/lang/es/pipeline.h +3 -3
  100. package/third-party/common/phonemis/src/phonemis/lang/fr/constants.h +152 -26
  101. package/third-party/common/phonemis/src/phonemis/lang/fr/num2word.cpp +252 -179
  102. package/third-party/common/phonemis/src/phonemis/lang/fr/num2word.h +38 -15
  103. package/third-party/common/phonemis/src/phonemis/lang/fr/patterns.cpp +83 -0
  104. package/third-party/common/phonemis/src/phonemis/lang/fr/patterns.h +15 -0
  105. package/third-party/common/phonemis/src/phonemis/lang/fr/pipeline.h +3 -3
  106. package/third-party/common/phonemis/src/phonemis/lang/hi/constants.h +62 -10
  107. package/third-party/common/phonemis/src/phonemis/lang/hi/num2word.cpp +74 -123
  108. package/third-party/common/phonemis/src/phonemis/lang/hi/num2word.h +27 -16
  109. package/third-party/common/phonemis/src/phonemis/lang/hi/pipeline.h +5 -3
  110. package/third-party/common/phonemis/src/phonemis/lang/it/constants.h +122 -42
  111. package/third-party/common/phonemis/src/phonemis/lang/it/num2word.cpp +200 -207
  112. package/third-party/common/phonemis/src/phonemis/lang/it/num2word.h +30 -18
  113. package/third-party/common/phonemis/src/phonemis/lang/it/patterns.cpp +25 -0
  114. package/third-party/common/phonemis/src/phonemis/lang/it/patterns.h +15 -0
  115. package/third-party/common/phonemis/src/phonemis/lang/it/pipeline.h +3 -3
  116. package/third-party/common/phonemis/src/phonemis/lang/pl/constants.h +346 -77
  117. package/third-party/common/phonemis/src/phonemis/lang/pl/num2word.cpp +631 -246
  118. package/third-party/common/phonemis/src/phonemis/lang/pl/num2word.h +47 -15
  119. package/third-party/common/phonemis/src/phonemis/lang/pl/pipeline.h +6 -6
  120. package/third-party/common/phonemis/src/phonemis/lang/pt/constants.h +201 -0
  121. package/third-party/common/phonemis/src/phonemis/lang/pt/num2word.cpp +365 -0
  122. package/third-party/common/phonemis/src/phonemis/lang/pt/num2word.h +53 -0
  123. package/third-party/common/phonemis/src/phonemis/lang/pt/pipeline.h +4 -2
  124. package/third-party/common/phonemis/src/phonemis/main.cpp +42 -11
  125. package/third-party/common/phonemis/src/phonemis/protophone/meta.h +24 -0
  126. package/third-party/common/phonemis/src/phonemis/protophone/numeric.h +26 -0
  127. package/third-party/common/phonemis/src/phonemis/protophone/protophone.cpp +525 -0
  128. package/third-party/common/phonemis/src/phonemis/protophone/protophone.h +80 -0
  129. package/third-party/common/phonemis/src/phonemis/protophone/tensor.h +76 -0
  130. package/third-party/common/phonemis/src/phonemis/protophone/tensor_utils.h +89 -0
  131. package/third-party/common/phonemis/src/phonemis/protophone/tensor_view.h +125 -0
  132. package/third-party/common/phonemis/src/phonemis/protophone/types.h +43 -0
  133. package/third-party/common/phonemis/src/phonemis/utils/strings.h +20 -14
  134. package/third-party/common/phonemis/src/phonemis/utils/unicode.h +15 -1
  135. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_arithmetic.hpp +267 -0
  136. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_bit.hpp +232 -0
  137. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_cast.hpp +43 -0
  138. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_complex.hpp +112 -0
  139. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_details.hpp +386 -0
  140. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_logical.hpp +240 -0
  141. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_math.hpp +2601 -0
  142. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_memory.hpp +1006 -0
  143. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_rounding.hpp +72 -0
  144. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_swizzle.hpp +260 -0
  145. package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_trigo.hpp +996 -0
  146. package/third-party/common/phonemis/src/third-party/xsimd/arch/utils/shifts.hpp +82 -0
  147. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx.hpp +2111 -0
  148. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx2.hpp +1591 -0
  149. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx2_128.hpp +170 -0
  150. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512bw.hpp +724 -0
  151. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512cd.hpp +28 -0
  152. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512dq.hpp +270 -0
  153. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512er.hpp +17 -0
  154. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512f.hpp +2919 -0
  155. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512ifma.hpp +17 -0
  156. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512pf.hpp +17 -0
  157. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vbmi.hpp +76 -0
  158. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vbmi2.hpp +130 -0
  159. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vnni_avx512bw.hpp +17 -0
  160. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vnni_avx512vbmi2.hpp +17 -0
  161. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx_128.hpp +164 -0
  162. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avxvnni.hpp +17 -0
  163. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_common.hpp +26 -0
  164. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_common_fwd.hpp +127 -0
  165. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_constants.hpp +393 -0
  166. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_emulated.hpp +787 -0
  167. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_avx.hpp +93 -0
  168. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_avx2.hpp +46 -0
  169. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_sse.hpp +97 -0
  170. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma4.hpp +92 -0
  171. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_i8mm_neon64.hpp +17 -0
  172. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_isa.hpp +148 -0
  173. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_neon.hpp +3580 -0
  174. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_neon64.hpp +1614 -0
  175. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_rvv.hpp +1515 -0
  176. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_scalar.hpp +1210 -0
  177. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse2.hpp +2333 -0
  178. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse3.hpp +66 -0
  179. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse4_1.hpp +510 -0
  180. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse4_2.hpp +44 -0
  181. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_ssse3.hpp +186 -0
  182. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sve.hpp +1186 -0
  183. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_vsx.hpp +947 -0
  184. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_vxe.hpp +787 -0
  185. package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_wasm.hpp +1819 -0
  186. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_arch.hpp +242 -0
  187. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_config.hpp +633 -0
  188. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features.hpp +50 -0
  189. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_arm.hpp +132 -0
  190. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_ppc.hpp +54 -0
  191. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_riscv.hpp +95 -0
  192. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_s390x.hpp +56 -0
  193. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_x86.hpp +1121 -0
  194. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpuid.hpp +144 -0
  195. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_getauxval.hpp +159 -0
  196. package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_macros.hpp +78 -0
  197. package/third-party/common/phonemis/src/third-party/xsimd/math/xsimd_rem_pio2.hpp +707 -0
  198. package/third-party/common/phonemis/src/third-party/xsimd/memory/xsimd_aligned_allocator.hpp +349 -0
  199. package/third-party/common/phonemis/src/third-party/xsimd/memory/xsimd_alignment.hpp +102 -0
  200. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_all_registers.hpp +57 -0
  201. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_api.hpp +3106 -0
  202. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx2_register.hpp +57 -0
  203. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512bw_register.hpp +51 -0
  204. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512cd_register.hpp +51 -0
  205. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512dq_register.hpp +51 -0
  206. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512er_register.hpp +51 -0
  207. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512f_register.hpp +77 -0
  208. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512ifma_register.hpp +51 -0
  209. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512pf_register.hpp +51 -0
  210. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vbmi2_register.hpp +51 -0
  211. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vbmi_register.hpp +51 -0
  212. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vnni_avx512bw_register.hpp +54 -0
  213. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vnni_avx512vbmi2_register.hpp +53 -0
  214. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx_register.hpp +79 -0
  215. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avxvnni_register.hpp +44 -0
  216. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch.hpp +1666 -0
  217. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch_constant.hpp +572 -0
  218. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch_fwd.hpp +41 -0
  219. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_common_arch.hpp +49 -0
  220. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_emulated_register.hpp +80 -0
  221. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_avx2_register.hpp +50 -0
  222. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_avx_register.hpp +50 -0
  223. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_sse_register.hpp +50 -0
  224. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma4_register.hpp +50 -0
  225. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_i8mm_neon64_register.hpp +55 -0
  226. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_neon64_register.hpp +55 -0
  227. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_neon_register.hpp +130 -0
  228. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_register.hpp +96 -0
  229. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_rvv_register.hpp +491 -0
  230. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse2_register.hpp +59 -0
  231. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse3_register.hpp +49 -0
  232. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse4_1_register.hpp +48 -0
  233. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse4_2_register.hpp +48 -0
  234. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_ssse3_register.hpp +48 -0
  235. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sve_register.hpp +216 -0
  236. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_traits.hpp +409 -0
  237. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_utils.hpp +462 -0
  238. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_vsx_register.hpp +84 -0
  239. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_vxe_register.hpp +86 -0
  240. package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_wasm_register.hpp +59 -0
  241. package/third-party/common/phonemis/src/third-party/xsimd/utils/bits.hpp +122 -0
  242. package/third-party/common/phonemis/src/third-party/xsimd/utils/xsimd_type_traits.hpp +145 -0
  243. package/third-party/common/phonemis/src/third-party/xsimd/xsimd.hpp +43 -0
  244. package/third-party/common/phonemis/src/phonemis/base/processor/constants.h +0 -11
  245. package/third-party/common/phonemis/src/phonemis/base/processor/num2word/config.h +0 -16
  246. package/third-party/common/phonemis/src/phonemis/base/processor/num2word/layer.cpp +0 -271
  247. package/third-party/common/phonemis/src/phonemis/base/processor/num2word/layer.h +0 -45
  248. package/third-party/common/phonemis/src/phonemis/base/processor/num2word/types.h +0 -29
  249. package/third-party/common/phonemis/src/phonemis/base/processor/sanitizer_layer.cpp +0 -22
  250. package/third-party/common/phonemis/src/phonemis/base/processor/trim_layer.cpp +0 -40
  251. package/third-party/common/phonemis/src/phonemis/base/processor/trim_layer.h +0 -22
@@ -1,268 +1,261 @@
1
- #include "num2word.h"
2
1
  #include "constants.h"
3
- #include <phonemis/utils/conversions.h>
4
- #include <algorithm>
5
- #include <cmath>
6
- #include <cstdlib>
2
+ #include "num2word.h"
3
+ #include "patterns.h"
4
+ #include <phonemis/base/processor/layers/num2word/numerals.h>
5
+ #include <phonemis/base/processor/layers/num2word/patterns.h>
6
+ #include <phonemis/base/processor/layers/num2word/primitives.h>
7
+ #include <phonemis/utils/strings.h>
7
8
 
8
9
  namespace phonemis::it {
9
10
 
10
- using namespace constants;
11
- using namespace phonemis::utils;
11
+ using namespace constants::num2word;
12
+ using namespace processor;
13
+ using namespace processor::num2word;
14
+ using namespace utils;
12
15
 
13
16
  namespace {
14
-
15
- // Apocopates a trailing cardinal "uno" to "un" (e.g. "uno" → "un",
16
- // "ventuno" → "ventun"). Used before singular masculine nouns such as
17
- // currency units and fraction denominators.
18
- std::u32string apocopate(std::u32string word) {
19
- constexpr std::u32string_view kUno = U"uno";
20
- if (word.size() >= kUno.size() &&
21
- std::u32string_view(word).substr(word.size() - kUno.size()) == kUno) {
22
- size_t pre = word.size() - kUno.size();
23
- // Only apocopate when "uno" is a standalone suffix (start of word or
24
- // preceded by a boundary), to avoid trimming unrelated words ending in
25
- // "uno".
26
- if (pre == 0 || word[pre - 1] == U' ' || word[pre - 1] == U'-') {
27
- word.replace(pre, kUno.size(), U"un");
28
- }
29
- }
30
- return word;
17
+ uint64_t value(const Number& number) {
18
+ return value_of(number.integer).value_or(0);
31
19
  }
32
20
 
33
- // Composes an ordinal from a cardinal word by stripping its final vowel and
34
- // appending "esimo". Cardinals ending in "tré" drop the accent but keep the
35
- // 'e' (e.g. "ventitré" → "ventitreesimo").
36
- std::u32string cardinal_to_ordinal(std::u32string word) {
37
- constexpr std::u32string_view kTre = U"tré";
38
- if (word.size() >= kTre.size() &&
39
- std::u32string_view(word).substr(word.size() - kTre.size()) == kTre) {
40
- word.replace(word.size() - kTre.size(), kTre.size(), U"tre");
41
- return word + U"esimo";
42
- }
43
- if (!word.empty()) {
44
- word.pop_back();
45
- }
46
- return word + U"esimo";
21
+ // The number "1" as written, which counts a singular noun
22
+ bool is_one(const Number& number) {
23
+ return number.integer == U"1" && number.fraction.empty();
47
24
  }
48
25
 
49
- } // namespace
26
+ // ------------------------
27
+ // ----- Number words -----
28
+ // ------------------------
50
29
 
51
- std::u32string Num2Word::to_cardinal_int(int32_t value) const {
52
- if (value < 0) {
53
- return U"meno " + to_cardinal_int(std::abs(value));
30
+ // ventuno, ventotto: a ten drops its vowel before uno and otto
31
+ std::u32string below_hundred(uint64_t n) {
32
+ if (n < 20) {
33
+ return std::u32string(kOnes[n]);
54
34
  }
55
-
56
- if (auto it = num2word::kCardinals.find(value); it != num2word::kCardinals.end()) {
57
- return it->second;
35
+ std::u32string tens(kTens[n / 10]);
36
+ uint64_t unit = n % 10;
37
+ if (unit == 1 || unit == 8) {
38
+ tens.pop_back();
58
39
  }
40
+ return tens + (unit ? std::u32string(kOnes[unit]) : U"");
41
+ }
59
42
 
60
- if (value < 100) {
61
- // Italian fuses tens and units into a single word. The tens' final vowel
62
- // elides before "uno" (1) and "otto" (8); "tre" takes an accent as a
63
- // suffix ("ventitré", "trentatré", ...).
64
- int32_t tens = (value / 10) * 10;
65
- int32_t units = value % 10;
66
- std::u32string tens_word = num2word::kCardinals.at(tens);
67
- std::u32string units_word = (units == 3) ? U"tré" : num2word::kCardinals.at(units);
68
- if (units == 1 || units == 8) {
69
- tens_word.pop_back();
70
- }
71
- return tens_word + units_word;
43
+ // centotto, novecentottanta: a hundred drops its vowel before otto and ottanta
44
+ std::u32string below_thousand(uint64_t n) {
45
+ uint64_t h = n / 100, r = n % 100;
46
+ std::u32string head = h == 0 ? U"" : (h == 1 ? U"cento" : std::u32string(kOnes[h]) + U"cento");
47
+ if (!head.empty() && (r == 8 || (r >= 80 && r <= 89))) {
48
+ head.pop_back();
72
49
  }
50
+ return head + (r || head.empty() ? below_hundred(r) : U"");
51
+ }
73
52
 
74
- // Large-scale decomposition (cento, mille, milione, miliardo) in descending
75
- // order.
76
- for (auto it = num2word::kLargeCardinals.rbegin(); it != num2word::kLargeCardinals.rend(); ++it) {
77
- int64_t base = it->first;
78
- if (static_cast<int64_t>(value) < base) continue;
79
-
80
- int32_t high = value / static_cast<int32_t>(base);
81
- int32_t low = value % static_cast<int32_t>(base);
82
-
83
- // Base 100/1000 fuse with the multiplier and the remainder into a single
84
- // word ("duecento", "duemilaventisei"), dropping "uno" at the multiplier
85
- // position ("cento", "mille"). Base 10^6 and above take a space and
86
- // require an explicit "un" for a multiplier of 1 ("un milione",
87
- // "due milioni").
88
- std::u32string head;
89
- std::u32string scale;
90
- bool space_before_low = false;
91
-
92
- if (base == 100LL) {
93
- head = (high == 1) ? U"" : to_cardinal_int(high);
94
- scale = U"cento";
95
- } else if (base == 1000LL) {
96
- head = (high == 1) ? U"" : to_cardinal_int(high);
97
- scale = (high == 1) ? U"mille" : U"mila";
98
- } else {
99
- head = (high == 1) ? U"un " : to_cardinal_int(high) + U" ";
100
- scale = (high == 1) ? it->second : num2word::kLargeCardinalsPlural.at(base);
101
- space_before_low = true;
53
+ // ventitré, centotré, milletré: a compound ending in tre takes the accent
54
+ std::u32string accented(std::u32string_view words) {
55
+ std::vector<std::u32string> out;
56
+ for (auto word : strings::split(words, U' ')) {
57
+ std::u32string w(word);
58
+ if (w.size() > 3 && w.ends_with(U"tre")) {
59
+ w.replace(w.size() - 3, 3, U"tré");
102
60
  }
61
+ out.push_back(w);
62
+ }
63
+ return join(out);
64
+ }
103
65
 
104
- std::u32string res = head + scale;
105
- if (low > 0) {
106
- res += (space_before_low ? U" " : U"") + to_cardinal_int(low);
66
+ // One word below a million (duemilaventidue), then un milione duecentomila
67
+ std::u32string cardinal(uint64_t n) {
68
+ std::vector<std::u32string> words;
69
+ for (auto [scale, one, many] :
70
+ {std::tuple{1000000000ULL, U"un miliardo", U"miliardi"}, std::tuple{1000000ULL, U"un milione", U"milioni"}}) {
71
+ if (uint64_t q = n / scale) {
72
+ words.push_back(q == 1 ? std::u32string(one) : cardinal(q) + U" " + many);
107
73
  }
108
- return res;
74
+ n %= scale;
109
75
  }
110
76
 
111
- return conversions::utf8_to_u32(std::to_string(value));
77
+ uint64_t thousands = n / 1000;
78
+ n %= 1000;
79
+ std::u32string head = thousands == 0 ? U"" : (thousands == 1 ? U"mille" : below_thousand(thousands) + U"mila");
80
+ if (!head.empty() || n || words.empty()) {
81
+ words.push_back(head + (n || head.empty() ? below_thousand(n) : U""));
82
+ }
83
+ return accented(join(words));
112
84
  }
113
85
 
114
- std::u32string Num2Word::to_cardinal_float(float value, std::u32string_view repr) const {
115
- if (value < 0.0f) {
116
- return U"meno " + to_cardinal_float(std::abs(value), repr);
86
+ // primo ... decimo, then the cardinal with -esimo: undicesimo, ventitreesimo, millesimo
87
+ std::u32string ordinal(uint64_t n, char32_t ending) {
88
+ if (n <= 10) {
89
+ std::u32string word(kOrdinals[n]);
90
+ word.back() = ending;
91
+ return word;
117
92
  }
118
93
 
119
- // The base transform normalizes the decimal separator to '.', but also
120
- // accept ',' when this method is invoked directly with a raw representation.
121
- std::string value_str = conversions::u32_to_utf8(repr);
122
- std::replace(value_str.begin(), value_str.end(), ',', '.');
123
-
124
- // Trim trailing zeros and any dangling decimal point.
125
- auto rit = std::find_if(value_str.rbegin(), value_str.rend(),
126
- [](char c) { return c != '0'; });
127
- value_str = std::string(value_str.begin(), rit.base());
128
- if (!value_str.empty() && value_str.back() == '.') {
129
- value_str.pop_back();
94
+ std::u32string words = cardinal(n);
95
+ if (words.ends_with(U"tré")) {
96
+ words.back() = U'e';
97
+ }
98
+ if (words.ends_with(U"tre") || words.ends_with(U"sei")) {
99
+ return words + U"esim" + ending;
130
100
  }
101
+ if (words.ends_with(U"mila")) {
102
+ return words.substr(0, words.size() - 4) + U"millesim" + ending;
103
+ }
104
+ return words.substr(0, words.size() - 1) + U"esim" + ending;
105
+ }
131
106
 
132
- size_t dot_pos = value_str.find('.');
133
- if (dot_pos == std::string::npos) {
134
- return to_cardinal_int(value_str.empty() ? 0 : std::stoi(value_str));
107
+ std::u32string digits(std::u32string_view text) {
108
+ std::vector<std::u32string> words;
109
+ for (char32_t c : text) {
110
+ words.emplace_back(kOnes[c - U'0']);
135
111
  }
112
+ return join(words);
113
+ }
114
+ } // namespace
136
115
 
137
- std::string integer_part_str = value_str.substr(0, dot_pos);
138
- std::string fractional_part_str = value_str.substr(dot_pos + 1);
139
- int32_t integer_part = integer_part_str.empty() ? 0 : std::stoi(integer_part_str);
140
-
141
- // Leading zeros in the fractional part are spoken as "zero" words; the
142
- // remaining digits verbalize as a single cardinal (e.g. 0,05 → "zero virgola
143
- // zero cinque", 123,45 → "... virgola quarantacinque").
144
- std::u32string frac_words;
145
- size_t pos = 0;
146
- while (pos < fractional_part_str.size() && fractional_part_str[pos] == '0') {
147
- if (!frac_words.empty()) frac_words += U" ";
148
- frac_words += U"zero";
149
- pos++;
116
+ Num2Word::Num2Word() : Num2WordLayer(kNotation, kJoiners) {
117
+ add_pattern(std::make_unique<DatePattern>(kDateFormat));
118
+ for (const auto& format : kPhoneFormats) {
119
+ add_pattern(std::make_unique<PhonePattern>(format));
150
120
  }
151
- if (pos < fractional_part_str.size()) {
152
- if (!frac_words.empty()) frac_words += U" ";
153
- frac_words += to_cardinal_int(std::stoi(fractional_part_str.substr(pos)));
121
+ add_pattern(std::make_unique<SuffixPattern>(Kind::ORDINAL, kOrdinalSigns, kOrdinalSignFormat));
122
+ add_pattern(std::make_unique<SuffixPattern>(Kind::ORDINAL, kOrdinalSuffixes));
123
+ add_pattern(std::make_unique<DecadePattern>());
124
+ }
125
+
126
+ // ----------------------
127
+ // ----- Resolution -----
128
+ // ----------------------
129
+
130
+ bool Num2Word::accept(const Match& match, const Context& context) const {
131
+ switch (match.kind) {
132
+ case Kind::FRACTION:
133
+ return kFractions.contains({value(match.numbers[0]), value(match.numbers[1])});
134
+ case Kind::TIME: {
135
+ // With a dot, a time comes after "alle" or from 13 on: alle 9.30, 21.30, but versione 2.79
136
+ uint64_t hours = value(match.numbers[0]);
137
+ bool decimal = match.separator == U'.' && !kTimeWords.contains(context.before()) && (hours < 13 || hours > 23);
138
+ return hours <= 24 && value(match.numbers[1]) <= 59 && !decimal;
139
+ }
140
+ case Kind::SCALE:
141
+ // 4K: a resolution
142
+ return (match.scale != U"k" && match.scale != U"K") || value(match.numbers.back()) >= 10;
143
+ case Kind::ORDINAL:
144
+ return value(match.numbers[0]) > 0;
145
+ default:
146
+ return true;
154
147
  }
148
+ }
155
149
 
156
- return to_cardinal_int(integer_part) + U" virgola " + frac_words;
150
+ NumberReading Num2Word::resolve(const Match& match, const Context& context) const {
151
+ return {.month = std::ranges::find(kMonths, strings::to_lower(context.after())) != kMonths.end()};
157
152
  }
158
153
 
159
- std::u32string Num2Word::to_ordinal_int(int32_t value, std::u32string_view suffix) const {
160
- // The suffix disambiguates gender/number; the default (no suffix, e.g. from
161
- // a "1." token) is masculine singular.
162
- bool feminine = (suffix == U"ª" || suffix == U"ªs");
163
- bool plural = (suffix == U"ºs" || suffix == U"ªs");
154
+ // --------------------
155
+ // ----- Readings -----
156
+ // --------------------
164
157
 
165
- auto inflect = [&](std::u32string word) {
166
- if (feminine && !word.empty() && word.back() == U'o') {
167
- word.back() = U'a';
158
+ std::u32string Num2Word::read_number(const Number& number, const NumberReading& reading) const {
159
+ if (number.fraction.empty()) {
160
+ auto n = value_of(number.integer);
161
+ if (!n || spoken_digits(number, 7)) {
162
+ return digits(number.integer);
168
163
  }
169
- if (plural && !word.empty()) {
170
- // Italian plural for masculine nouns: -o → -i; for feminine: -a → -e.
171
- if (word.back() == U'o') word.back() = U'i';
172
- else if (word.back() == U'a') word.back() = U'e';
173
- }
174
- return word;
175
- };
176
-
177
- if (auto it = num2word::kOrdinals.find(value); it != num2word::kOrdinals.end()) {
178
- return inflect(it->second);
164
+ return *n == 1 && reading.month ? U"primo" : cardinal(*n);
179
165
  }
180
166
 
181
- // Values without a dedicated ordinal entry derive the form from the cardinal
182
- // by stripping its final vowel and appending "esimo".
183
- return inflect(cardinal_to_ordinal(to_cardinal_int(value)));
167
+ // The separator is read as written: due virgola cinque, due punto cinque
168
+ std::vector<std::u32string> fraction;
169
+ size_t zeros = number.fraction.find_first_not_of(U'0');
170
+ fraction.insert(fraction.end(), std::min(zeros, number.fraction.size()), U"zero");
171
+ if (zeros != std::u32string::npos) {
172
+ fraction.push_back(cardinal(value_of(number.fraction).value_or(0)));
173
+ }
174
+ std::u32string head = number.integer.empty() ? U"" : cardinal(value(number)) + U" ";
175
+ return head + (number.decimal_mark == U',' ? U"virgola " : U"punto ") + join(fraction);
184
176
  }
185
177
 
186
- std::u32string Num2Word::to_currency(char32_t currency, std::variant<int32_t, float> number) const {
187
- auto it = num2word::kCurrencies.find(currency);
188
- if (it == num2word::kCurrencies.end()) {
189
- return std::u32string(1, currency);
178
+ std::u32string Num2Word::read_code_digits(std::u32string_view text) const {
179
+ auto n = value_of(text);
180
+ if ((text.size() > 1 && text[0] == U'0') || text.size() >= 7 || !n) {
181
+ return digits(text);
190
182
  }
183
+ return cardinal(*n);
184
+ }
191
185
 
192
- // Singular only for amounts that round to exactly 1.
193
- bool is_singular = std::visit([](auto&& arg) -> bool {
194
- using T = std::decay_t<decltype(arg)>;
195
- if constexpr (std::is_same_v<T, int32_t>) {
196
- return arg == 1;
197
- } else {
198
- return std::abs(arg - 1.0F) < 1e-6F;
199
- }
200
- }, number);
201
-
202
- return is_singular ? it->second : num2word::kCurrenciesPlural.at(currency);
186
+ std::u32string Num2Word::read_date(const Match& match, const NumberReading& reading) const {
187
+ uint64_t day = value(match.numbers[0]);
188
+ return (day == 1 ? U"primo" : cardinal(day)) + U" " + kMonths[value(match.numbers[1]) - 1] + U" " +
189
+ cardinal(value(match.numbers[2]));
203
190
  }
204
191
 
205
- std::u32string Num2Word::to_fraction(int32_t numerator, int32_t denominator) const {
206
- // Numerator apocopates "uno" because it precedes a masculine noun
207
- // ("un mezzo", "un terzo", "un quarto", "un decimo").
208
- std::u32string num_word = apocopate(to_cardinal_int(numerator));
209
- bool plural = std::abs(numerator) > 1;
210
-
211
- auto with_plural = [&](std::u32string_view base) -> std::u32string {
212
- std::u32string w(base);
213
- if (plural && !w.empty() && w.back() == U'o') w.back() = U'i';
214
- return num_word + U" " + w;
215
- };
216
-
217
- // Dedicated nouns for denominators 2/3/4; other denominators fall back to
218
- // the ordinal form, agreeing in number.
219
- if (denominator == 2) return with_plural(U"mezzo");
220
- if (denominator == 3) return with_plural(U"terzo");
221
- if (denominator == 4) return with_plural(U"quarto");
222
-
223
- std::u32string ord = to_ordinal_int(denominator);
224
- if (plural && !ord.empty() && ord.back() == U'o') ord.back() = U'i';
225
- return num_word + U" " + ord;
192
+ std::u32string Num2Word::read_phone(const Match& match, const NumberReading& reading) const {
193
+ // Digit by digit: tre tre tre, uno due tre ...
194
+ std::vector<std::u32string> groups;
195
+ for (const auto& group : match.numbers) {
196
+ groups.push_back(digits(group.integer));
197
+ }
198
+ return join(groups);
226
199
  }
227
200
 
228
- std::u32string Num2Word::to_day(uint32_t day) const {
229
- return to_cardinal_int(static_cast<int32_t>(day));
201
+ std::u32string Num2Word::read_fraction(const Match& match, const NumberReading& reading) const {
202
+ return kFractions.at({value(match.numbers[0]), value(match.numbers[1])});
230
203
  }
231
204
 
232
- std::u32string Num2Word::to_month(uint32_t month) const {
233
- if (month >= 1 && month <= 12) {
234
- return num2word::kMonths[month];
235
- }
236
- return U"";
205
+ std::u32string Num2Word::read_time(const Match& match, const NumberReading& reading) const {
206
+ // alle 21.30: ventuno e trenta
207
+ uint64_t hours = value(match.numbers[0]), minutes = value(match.numbers[1]);
208
+ std::u32string hour = hours == 1 ? U"una" : cardinal(hours);
209
+ return minutes ? hour + U" e " + cardinal(minutes) : hour;
237
210
  }
238
211
 
239
- std::u32string Num2Word::to_year(uint32_t year) const {
240
- // Italian reads years as plain cardinals (e.g. 2026 → "duemilaventisei").
241
- return to_cardinal_int(static_cast<int32_t>(year));
212
+ std::u32string Num2Word::read_ordinal(const Match& match, const NumberReading& reading) const {
213
+ char32_t ending = match.suffix == U"ª" ? U'a' : (match.suffix == U"º" ? U'o' : match.suffix.back());
214
+ return ordinal(value(match.numbers[0]), ending);
242
215
  }
243
216
 
244
- bool Num2Word::is_ordinal_suffix(std::u32string_view suffix) const {
245
- return num2word::kOrdinalSuffixes.contains(std::u32string(suffix));
217
+ std::u32string Num2Word::read_decade(const Match& match, const NumberReading& reading) const {
218
+ return cardinal(value(match.numbers[0])); // gli anni '80: gli anni ottanta
246
219
  }
247
220
 
248
- std::u32string Num2Word::verbalize(const processor::num2word::StringifiedNumber& number) const {
249
- using Mode = processor::num2word::Mode;
221
+ std::u32string Num2Word::read_money(const Number& number, const Match& match, const NumberReading& reading) const {
222
+ const Forms& currency = kCurrencies.at(std::u32string(match.unit));
250
223
 
251
- std::u32string result = Num2WordLayer::verbalize(number);
224
+ // 3 mln €: tre milioni di euro, but 10 mila €: diecimila euro
225
+ if (!match.scale.empty()) {
226
+ bool thousands = kScales.at(std::u32string(match.scale)).one == U"mila";
227
+ return read_scale(number, match, reading) + (thousands ? U" " : U" di ") + currency.many;
228
+ }
252
229
 
253
- // The base produces "<cardinal> <currency>"; apocopate the cardinal half so
254
- // amounts of 1 (or ending in "uno") read as "un <noun>" instead of "uno
255
- // <noun>".
256
- if (number.conversionMode == Mode::CURRENCY) {
257
- size_t last_space = result.rfind(U' ');
258
- if (last_space != std::u32string::npos) {
259
- std::u32string head = result.substr(0, last_space);
260
- std::u32string tail = result.substr(last_space);
261
- result = apocopate(std::move(head)) + tail;
262
- }
230
+ // 10,50 €: dieci euro e cinquanta
231
+ if (number.fraction.size() == 2 && number.decimal_mark == U',') {
232
+ Number whole{.integer = number.integer.empty() ? U"0" : number.integer, .grouped = number.grouped};
233
+ uint64_t cents = value_of(number.fraction).value_or(0);
234
+ return read_number(whole, reading) + U" " + (number.integer == U"1" ? currency.one : currency.many) +
235
+ (cents ? U" e " + cardinal(cents) : U"");
236
+ }
237
+ return read_number(number, reading) + U" " + (is_one(number) ? currency.one : currency.many);
238
+ }
239
+
240
+ std::u32string Num2Word::read_scale(const Number& number, const Match& match, const NumberReading& reading) const {
241
+ const Forms& scale = kScales.at(std::u32string(match.scale));
242
+
243
+ // 74 mila: settantaquattromila
244
+ if (scale.one == U"mila" && number.fraction.empty()) {
245
+ return cardinal(value(number) * 1000);
263
246
  }
247
+ bool singular = value(number) < 2 && number.fraction.empty();
248
+ return read_number(number, reading) + U" " + (singular ? scale.one : scale.many);
249
+ }
250
+
251
+ std::u32string Num2Word::read_percent(const Number& number, const Match& match, const NumberReading& reading) const {
252
+ std::u32string suffix = match.suffix.empty() ? U"" : U" " + std::u32string(match.suffix);
253
+ return read_number(number, reading) + U" per cento" + suffix;
254
+ }
264
255
 
265
- return result;
256
+ std::u32string Num2Word::read_unit(const Number& number, const Match& match, const NumberReading& reading) const {
257
+ const Forms& unit = kUnits.at(std::u32string(match.unit));
258
+ return read_number(number, reading) + U" " + (is_one(number) ? unit.one : unit.many);
266
259
  }
267
260
 
268
261
  } // namespace phonemis::it
@@ -1,30 +1,42 @@
1
1
  #pragma once
2
2
 
3
- #include <phonemis/base/processor/num2word/layer.h>
3
+ #include <phonemis/base/processor/layers/num2word/layer.h>
4
+
4
5
  #include <string>
5
- #include <variant>
6
6
 
7
7
  namespace phonemis::it {
8
8
 
9
- class Num2Word : public processor::num2word::Num2WordLayer {
9
+ // How an Italian number is read, from the words around it.
10
+ struct NumberReading {
11
+ bool month = false; // 1 maggio: "1" before a month is "primo"
12
+ };
13
+
14
+ class Num2Word : public processor::num2word::Num2WordLayer<NumberReading> {
10
15
  public:
11
- using Num2WordLayer::Num2WordLayer;
12
-
13
- char32_t decimal_separator() const override { return U','; }
14
- std::u32string to_cardinal_int(int32_t number) const override;
15
- std::u32string to_cardinal_float(float number, std::u32string_view repr) const override;
16
- std::u32string to_ordinal_int(int32_t number, std::u32string_view suffix = U"") const override;
17
- std::u32string to_currency(char32_t currency, std::variant<int32_t, float> number) const override;
18
- std::u32string to_fraction(int32_t numerator, int32_t denominator) const override;
19
- std::u32string to_day(uint32_t day) const override;
20
- std::u32string to_month(uint32_t month) const override;
21
- std::u32string to_year(uint32_t year) const override;
22
- bool is_ordinal_suffix(std::u32string_view suffix) const override;
16
+ Num2Word();
23
17
 
24
18
  protected:
25
- // Overridden so we can apocopate the final "uno" before a currency noun
26
- // ("uno dollaro" → "un dollaro", "uno euro" → "un euro").
27
- std::u32string verbalize(const processor::num2word::StringifiedNumber& number) const override;
19
+ using Context = processor::Context;
20
+ using Match = processor::num2word::Match;
21
+ using Number = processor::num2word::Number;
22
+
23
+ // Resolution
24
+ bool accept(const Match& match, const Context& context) const override;
25
+ NumberReading resolve(const Match& match, const Context& context) const override;
26
+
27
+ // Readings
28
+ std::u32string read_number(const Number& number, const NumberReading& reading) const override;
29
+ std::u32string read_code_digits(std::u32string_view digits) const override;
30
+ std::u32string read_date(const Match& match, const NumberReading& reading) const override;
31
+ std::u32string read_phone(const Match& match, const NumberReading& reading) const override;
32
+ std::u32string read_fraction(const Match& match, const NumberReading& reading) const override;
33
+ std::u32string read_time(const Match& match, const NumberReading& reading) const override;
34
+ std::u32string read_ordinal(const Match& match, const NumberReading& reading) const override;
35
+ std::u32string read_decade(const Match& match, const NumberReading& reading) const override;
36
+ std::u32string read_money(const Number& number, const Match& match, const NumberReading& reading) const override;
37
+ std::u32string read_scale(const Number& number, const Match& match, const NumberReading& reading) const override;
38
+ std::u32string read_percent(const Number& number, const Match& match, const NumberReading& reading) const override;
39
+ std::u32string read_unit(const Number& number, const Match& match, const NumberReading& reading) const override;
28
40
  };
29
41
 
30
42
  } // namespace phonemis::it
@@ -0,0 +1,25 @@
1
+ #include "patterns.h"
2
+ #include <phonemis/base/processor/layers/num2word/primitives.h>
3
+
4
+ #include <optional>
5
+
6
+ namespace phonemis::it {
7
+
8
+ using namespace processor;
9
+ using namespace processor::num2word;
10
+
11
+ std::optional<Match> DecadePattern::match(std::u32string_view text, size_t position) const {
12
+ if (!is_clear_before(text, position) || text[position] != U'\'') {
13
+ return std::nullopt;
14
+ }
15
+
16
+ // Two digits: a ten other than 00
17
+ Number decade = digits_at(text, position + 1);
18
+ if (decade.integer.size() != 2 || decade.integer[0] == U'0' || decade.integer[1] != U'0' ||
19
+ !is_clear_after(text, decade.span.end)) {
20
+ return std::nullopt;
21
+ }
22
+ return Match{.kind = Kind::DECADE, .span = {position, decade.span.end}, .numbers = {decade}};
23
+ }
24
+
25
+ } // namespace phonemis::it
@@ -0,0 +1,15 @@
1
+ #pragma once
2
+
3
+ #include <phonemis/base/processor/layers/num2word/pattern.h>
4
+
5
+ namespace phonemis::it {
6
+
7
+ // '80: a decade written as its two digits after an apostrophe (gli anni '80).
8
+ class DecadePattern : public processor::num2word::Pattern {
9
+ public:
10
+ DecadePattern() : Pattern(processor::num2word::Kind::DECADE) {}
11
+
12
+ std::optional<processor::num2word::Match> match(std::u32string_view text, size_t position) const override;
13
+ };
14
+
15
+ } // namespace phonemis::it
@@ -7,8 +7,8 @@
7
7
  #include <phonemis/base/ipipeline.h>
8
8
  #include <phonemis/base/phonemizer/hybrid_phonemizer.h>
9
9
  #include <phonemis/base/phonemizer/lexicon_phonemizer.h>
10
+ #include <phonemis/base/processor/preprocessor.h>
10
11
  #include <phonemis/base/processor/processor.h>
11
- #include <phonemis/base/processor/trim_layer.h>
12
12
  #include <phonemis/base/tokenizer/tokenizer.h>
13
13
  #include <phonemis/utils/conversions.h>
14
14
 
@@ -24,8 +24,8 @@ public:
24
24
  phonemizer_(config.phonemizer) {
25
25
 
26
26
  // 1. Setup Preprocessing layers
27
- preprocessor_.add_layer(std::make_unique<processor::TrimLayer>());
28
- preprocessor_.add_layer(std::make_unique<Num2Word>());
27
+ preprocessor_ = processor::make_preprocessor<Num2Word>(
28
+ config.preprocessor, {.terms = &constants::term2word::kTerms, .symbols = &constants::sym2word::kSymbols});
29
29
  }
30
30
 
31
31
  // Performs a preprocessing stage of the pipeline.