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.
- package/README.md +10 -1
- package/android/build.gradle.kts +4 -3
- package/ios/RnExecutorch.mm +15 -17
- package/lib/module/fetcher/fetcher.js +35 -122
- package/lib/module/fetcher/fetcher.js.map +1 -1
- package/lib/module/fetcher/telemetry.js +1 -1
- package/lib/module/index.js +12 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/models.js +4 -2
- package/lib/module/models.js.map +1 -1
- package/lib/typescript/src/fetcher/fetcher.d.ts +3 -7
- package/lib/typescript/src/fetcher/fetcher.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts.map +1 -1
- package/package.json +9 -7
- package/react-native-executorch.podspec +6 -2
- package/src/fetcher/fetcher.ts +38 -131
- package/src/fetcher/telemetry.ts +1 -1
- package/src/models.ts +6 -1
- package/third-party/common/phonemis/CMakeLists.txt +70 -14
- package/third-party/common/phonemis/README.md +183 -33
- package/third-party/common/phonemis/THIRD_PARTY_NOTICES.md +57 -0
- package/third-party/common/phonemis/knowledge/code_style.md +642 -0
- package/third-party/common/phonemis/licenses/Unicode-3.0.txt +39 -0
- package/third-party/common/phonemis/licenses/misaki-Apache-2.0.txt +201 -0
- package/third-party/common/phonemis/licenses/nlohmann-json-MIT.txt +21 -0
- package/third-party/common/phonemis/licenses/xsimd-BSD-3-Clause.txt +29 -0
- package/third-party/common/phonemis/src/phonemis/base/config.h +6 -0
- package/third-party/common/phonemis/src/phonemis/base/ipipeline.cpp +75 -0
- package/third-party/common/phonemis/src/phonemis/base/ipipeline.h +21 -0
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/constants.h +2 -5
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/lexicon_phonemizer.cpp +3 -4
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/neural_phonemizer.cpp +17 -8
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/neural_phonemizer.h +4 -0
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/tokenizer.cpp +21 -6
- package/third-party/common/phonemis/src/phonemis/base/phonemizer/nn/tokenizer.h +13 -4
- package/third-party/common/phonemis/src/phonemis/base/pipeline.cpp +8 -0
- package/third-party/common/phonemis/src/phonemis/base/pipeline.h +19 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/conditions.cpp +37 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/conditions.h +45 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/constants.h +10 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/context.cpp +105 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/context.h +49 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/document.cpp +173 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/document.h +67 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/text.cpp +75 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/text.h +60 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/common/types.h +18 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/config.h +53 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layer.h +9 -7
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/constants.h +20 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/layer.cpp +89 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/layer.h +35 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/normalize/types.h +16 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/kind.h +40 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/layer.h +382 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/notation.h +30 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/numerals.cpp +51 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/numerals.h +31 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern.h +30 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern_set.cpp +17 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/pattern_set.h +31 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/patterns.cpp +811 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/patterns.h +285 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/primitives.cpp +64 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/primitives.h +23 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/types.h +94 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/sanitizer/layer.cpp +19 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/{sanitizer_layer.h → layers/sanitizer/layer.h} +8 -8
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/sym2word/layer.cpp +65 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/sym2word/layer.h +29 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/layer.cpp +170 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/layer.h +40 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/term2word/types.h +25 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/trim/layer.cpp +47 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/layers/trim/layer.h +19 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/preprocessor.cpp +60 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/preprocessor.h +45 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/processor.cpp +6 -7
- package/third-party/common/phonemis/src/phonemis/base/processor/processor.h +14 -10
- package/third-party/common/phonemis/src/phonemis/base/tagger/hmm_tagger.cpp +89 -52
- package/third-party/common/phonemis/src/phonemis/base/tagger/hmm_tagger.h +16 -9
- package/third-party/common/phonemis/src/phonemis/base/tokenizer/tokenizer.cpp +13 -12
- package/third-party/common/phonemis/src/phonemis/lang/de/constants.h +183 -19
- package/third-party/common/phonemis/src/phonemis/lang/de/num2word.cpp +355 -309
- package/third-party/common/phonemis/src/phonemis/lang/de/num2word.h +42 -17
- package/third-party/common/phonemis/src/phonemis/lang/de/patterns.cpp +56 -0
- package/third-party/common/phonemis/src/phonemis/lang/de/patterns.h +15 -0
- package/third-party/common/phonemis/src/phonemis/lang/de/pipeline.h +3 -3
- package/third-party/common/phonemis/src/phonemis/lang/en/constants.h +181 -30
- package/third-party/common/phonemis/src/phonemis/lang/en/hmm_tagger.cpp +5 -7
- package/third-party/common/phonemis/src/phonemis/lang/en/num2word.cpp +232 -135
- package/third-party/common/phonemis/src/phonemis/lang/en/num2word.h +41 -16
- package/third-party/common/phonemis/src/phonemis/lang/en/pipeline.h +3 -10
- package/third-party/common/phonemis/src/phonemis/lang/es/constants.h +182 -60
- package/third-party/common/phonemis/src/phonemis/lang/es/num2word.cpp +247 -212
- package/third-party/common/phonemis/src/phonemis/lang/es/num2word.h +38 -18
- package/third-party/common/phonemis/src/phonemis/lang/es/patterns.cpp +50 -0
- package/third-party/common/phonemis/src/phonemis/lang/es/patterns.h +15 -0
- package/third-party/common/phonemis/src/phonemis/lang/es/pipeline.h +3 -3
- package/third-party/common/phonemis/src/phonemis/lang/fr/constants.h +152 -26
- package/third-party/common/phonemis/src/phonemis/lang/fr/num2word.cpp +252 -179
- package/third-party/common/phonemis/src/phonemis/lang/fr/num2word.h +38 -15
- package/third-party/common/phonemis/src/phonemis/lang/fr/patterns.cpp +83 -0
- package/third-party/common/phonemis/src/phonemis/lang/fr/patterns.h +15 -0
- package/third-party/common/phonemis/src/phonemis/lang/fr/pipeline.h +3 -3
- package/third-party/common/phonemis/src/phonemis/lang/hi/constants.h +62 -10
- package/third-party/common/phonemis/src/phonemis/lang/hi/num2word.cpp +74 -123
- package/third-party/common/phonemis/src/phonemis/lang/hi/num2word.h +27 -16
- package/third-party/common/phonemis/src/phonemis/lang/hi/pipeline.h +5 -3
- package/third-party/common/phonemis/src/phonemis/lang/it/constants.h +122 -42
- package/third-party/common/phonemis/src/phonemis/lang/it/num2word.cpp +200 -207
- package/third-party/common/phonemis/src/phonemis/lang/it/num2word.h +30 -18
- package/third-party/common/phonemis/src/phonemis/lang/it/patterns.cpp +25 -0
- package/third-party/common/phonemis/src/phonemis/lang/it/patterns.h +15 -0
- package/third-party/common/phonemis/src/phonemis/lang/it/pipeline.h +3 -3
- package/third-party/common/phonemis/src/phonemis/lang/pl/constants.h +346 -77
- package/third-party/common/phonemis/src/phonemis/lang/pl/num2word.cpp +631 -246
- package/third-party/common/phonemis/src/phonemis/lang/pl/num2word.h +47 -15
- package/third-party/common/phonemis/src/phonemis/lang/pl/pipeline.h +6 -6
- package/third-party/common/phonemis/src/phonemis/lang/pt/constants.h +201 -0
- package/third-party/common/phonemis/src/phonemis/lang/pt/num2word.cpp +365 -0
- package/third-party/common/phonemis/src/phonemis/lang/pt/num2word.h +53 -0
- package/third-party/common/phonemis/src/phonemis/lang/pt/pipeline.h +4 -2
- package/third-party/common/phonemis/src/phonemis/main.cpp +42 -11
- package/third-party/common/phonemis/src/phonemis/protophone/meta.h +24 -0
- package/third-party/common/phonemis/src/phonemis/protophone/numeric.h +26 -0
- package/third-party/common/phonemis/src/phonemis/protophone/protophone.cpp +525 -0
- package/third-party/common/phonemis/src/phonemis/protophone/protophone.h +80 -0
- package/third-party/common/phonemis/src/phonemis/protophone/tensor.h +76 -0
- package/third-party/common/phonemis/src/phonemis/protophone/tensor_utils.h +89 -0
- package/third-party/common/phonemis/src/phonemis/protophone/tensor_view.h +125 -0
- package/third-party/common/phonemis/src/phonemis/protophone/types.h +43 -0
- package/third-party/common/phonemis/src/phonemis/utils/strings.h +20 -14
- package/third-party/common/phonemis/src/phonemis/utils/unicode.h +15 -1
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_arithmetic.hpp +267 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_bit.hpp +232 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_cast.hpp +43 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_complex.hpp +112 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_details.hpp +386 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_logical.hpp +240 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_math.hpp +2601 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_memory.hpp +1006 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_rounding.hpp +72 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_swizzle.hpp +260 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/common/xsimd_common_trigo.hpp +996 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/utils/shifts.hpp +82 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx.hpp +2111 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx2.hpp +1591 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx2_128.hpp +170 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512bw.hpp +724 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512cd.hpp +28 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512dq.hpp +270 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512er.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512f.hpp +2919 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512ifma.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512pf.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vbmi.hpp +76 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vbmi2.hpp +130 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vnni_avx512bw.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx512vnni_avx512vbmi2.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avx_128.hpp +164 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_avxvnni.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_common.hpp +26 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_common_fwd.hpp +127 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_constants.hpp +393 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_emulated.hpp +787 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_avx.hpp +93 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_avx2.hpp +46 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma3_sse.hpp +97 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_fma4.hpp +92 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_i8mm_neon64.hpp +17 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_isa.hpp +148 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_neon.hpp +3580 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_neon64.hpp +1614 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_rvv.hpp +1515 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_scalar.hpp +1210 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse2.hpp +2333 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse3.hpp +66 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse4_1.hpp +510 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sse4_2.hpp +44 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_ssse3.hpp +186 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_sve.hpp +1186 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_vsx.hpp +947 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_vxe.hpp +787 -0
- package/third-party/common/phonemis/src/third-party/xsimd/arch/xsimd_wasm.hpp +1819 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_arch.hpp +242 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_config.hpp +633 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features.hpp +50 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_arm.hpp +132 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_ppc.hpp +54 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_riscv.hpp +95 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_s390x.hpp +56 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpu_features_x86.hpp +1121 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_cpuid.hpp +144 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_getauxval.hpp +159 -0
- package/third-party/common/phonemis/src/third-party/xsimd/config/xsimd_macros.hpp +78 -0
- package/third-party/common/phonemis/src/third-party/xsimd/math/xsimd_rem_pio2.hpp +707 -0
- package/third-party/common/phonemis/src/third-party/xsimd/memory/xsimd_aligned_allocator.hpp +349 -0
- package/third-party/common/phonemis/src/third-party/xsimd/memory/xsimd_alignment.hpp +102 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_all_registers.hpp +57 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_api.hpp +3106 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx2_register.hpp +57 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512bw_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512cd_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512dq_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512er_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512f_register.hpp +77 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512ifma_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512pf_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vbmi2_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vbmi_register.hpp +51 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vnni_avx512bw_register.hpp +54 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx512vnni_avx512vbmi2_register.hpp +53 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avx_register.hpp +79 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_avxvnni_register.hpp +44 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch.hpp +1666 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch_constant.hpp +572 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_batch_fwd.hpp +41 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_common_arch.hpp +49 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_emulated_register.hpp +80 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_avx2_register.hpp +50 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_avx_register.hpp +50 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma3_sse_register.hpp +50 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_fma4_register.hpp +50 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_i8mm_neon64_register.hpp +55 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_neon64_register.hpp +55 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_neon_register.hpp +130 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_register.hpp +96 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_rvv_register.hpp +491 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse2_register.hpp +59 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse3_register.hpp +49 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse4_1_register.hpp +48 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sse4_2_register.hpp +48 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_ssse3_register.hpp +48 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_sve_register.hpp +216 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_traits.hpp +409 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_utils.hpp +462 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_vsx_register.hpp +84 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_vxe_register.hpp +86 -0
- package/third-party/common/phonemis/src/third-party/xsimd/types/xsimd_wasm_register.hpp +59 -0
- package/third-party/common/phonemis/src/third-party/xsimd/utils/bits.hpp +122 -0
- package/third-party/common/phonemis/src/third-party/xsimd/utils/xsimd_type_traits.hpp +145 -0
- package/third-party/common/phonemis/src/third-party/xsimd/xsimd.hpp +43 -0
- package/third-party/common/phonemis/src/phonemis/base/processor/constants.h +0 -11
- package/third-party/common/phonemis/src/phonemis/base/processor/num2word/config.h +0 -16
- package/third-party/common/phonemis/src/phonemis/base/processor/num2word/layer.cpp +0 -271
- package/third-party/common/phonemis/src/phonemis/base/processor/num2word/layer.h +0 -45
- package/third-party/common/phonemis/src/phonemis/base/processor/num2word/types.h +0 -29
- package/third-party/common/phonemis/src/phonemis/base/processor/sanitizer_layer.cpp +0 -22
- package/third-party/common/phonemis/src/phonemis/base/processor/trim_layer.cpp +0 -40
- 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
|
|
4
|
-
#include
|
|
5
|
-
#include <
|
|
6
|
-
#include <
|
|
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
|
|
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
|
-
|
|
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
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
26
|
+
// ------------------------
|
|
27
|
+
// ----- Number words -----
|
|
28
|
+
// ------------------------
|
|
50
29
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
74
|
+
n %= scale;
|
|
109
75
|
}
|
|
110
76
|
|
|
111
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
std::
|
|
139
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
bool feminine = (suffix == U"ª" || suffix == U"ªs");
|
|
163
|
-
bool plural = (suffix == U"ºs" || suffix == U"ªs");
|
|
154
|
+
// --------------------
|
|
155
|
+
// ----- Readings -----
|
|
156
|
+
// --------------------
|
|
164
157
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
182
|
-
|
|
183
|
-
|
|
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::
|
|
187
|
-
auto
|
|
188
|
-
if (
|
|
189
|
-
return
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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::
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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::
|
|
229
|
-
return
|
|
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::
|
|
233
|
-
|
|
234
|
-
|
|
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::
|
|
240
|
-
|
|
241
|
-
return
|
|
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
|
-
|
|
245
|
-
return
|
|
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::
|
|
249
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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_
|
|
28
|
-
|
|
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.
|