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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/***************************************************************************
|
|
2
|
+
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
|
|
3
|
+
* Martin Renou *
|
|
4
|
+
* Copyright (c) QuantStack *
|
|
5
|
+
* Copyright (c) Serge Guelton *
|
|
6
|
+
* *
|
|
7
|
+
* Distributed under the terms of the BSD 3-Clause License. *
|
|
8
|
+
* *
|
|
9
|
+
* The full license is in the file LICENSE, distributed with this software. *
|
|
10
|
+
***************************************************************************/
|
|
11
|
+
|
|
12
|
+
#ifndef XSIMD_CPUID_UTILS_HPP
|
|
13
|
+
#define XSIMD_CPUID_UTILS_HPP
|
|
14
|
+
|
|
15
|
+
#include <cassert>
|
|
16
|
+
#include <type_traits>
|
|
17
|
+
|
|
18
|
+
namespace xsimd
|
|
19
|
+
{
|
|
20
|
+
namespace utils
|
|
21
|
+
{
|
|
22
|
+
template <typename I>
|
|
23
|
+
constexpr I make_bit_mask(I bit)
|
|
24
|
+
{
|
|
25
|
+
static_assert(std::is_unsigned<I>::value, "Bit operations must be done on unsigned integers");
|
|
26
|
+
assert(bit < static_cast<I>(8 * sizeof(I)));
|
|
27
|
+
return static_cast<I>(I { 1 } << bit);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
template <typename I, typename... Args>
|
|
31
|
+
constexpr I make_bit_mask(I bit, Args... bits)
|
|
32
|
+
{
|
|
33
|
+
// TODO(C++17): Use fold expression
|
|
34
|
+
static_assert(std::is_unsigned<I>::value, "Bit operations must be done on unsigned integers");
|
|
35
|
+
return make_bit_mask<I>(bit) | make_bit_mask<I>(static_cast<I>(bits)...);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
template <int... Bits, typename I>
|
|
39
|
+
constexpr bool all_bits_set(I value)
|
|
40
|
+
{
|
|
41
|
+
static_assert(std::is_unsigned<I>::value, "Bit operations must be done on unsigned integers");
|
|
42
|
+
constexpr I mask = make_bit_mask<I>(static_cast<I>(Bits)...);
|
|
43
|
+
return (value & mask) == mask;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
template <int Bit, typename I>
|
|
47
|
+
constexpr I set_bit(I value)
|
|
48
|
+
{
|
|
49
|
+
static_assert(std::is_unsigned<I>::value, "Bit operations must be done on unsigned integers");
|
|
50
|
+
constexpr I mask = make_bit_mask<I>(static_cast<I>(Bit));
|
|
51
|
+
return value | mask;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Return a mask with the `width` lowest bits set.
|
|
56
|
+
*/
|
|
57
|
+
template <typename I>
|
|
58
|
+
constexpr I make_low_mask(I width) noexcept
|
|
59
|
+
{
|
|
60
|
+
static_assert(std::is_unsigned<I>::value, "Bit operations must be done on unsigned integers");
|
|
61
|
+
assert(width <= static_cast<I>(8 * sizeof(I)));
|
|
62
|
+
if (width == static_cast<I>(8 * sizeof(I)))
|
|
63
|
+
{
|
|
64
|
+
return ~I { 0 };
|
|
65
|
+
}
|
|
66
|
+
return (I { 1 } << width) - I { 1 };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* A bitset over an unsigned integer type, indexed by an enum key type. */
|
|
70
|
+
template <typename K, typename U>
|
|
71
|
+
struct uint_bitset
|
|
72
|
+
{
|
|
73
|
+
/* The underlying unsigned integer type storing the bits. */
|
|
74
|
+
using storage_type = U;
|
|
75
|
+
/* The enum type whose values name individual bits. */
|
|
76
|
+
using key_type = K;
|
|
77
|
+
|
|
78
|
+
/* Construct from a raw bit pattern. */
|
|
79
|
+
constexpr explicit uint_bitset(storage_type bitset = {}) noexcept
|
|
80
|
+
: m_bitset(bitset)
|
|
81
|
+
{
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Return true if every bit named by the template arguments is set. */
|
|
85
|
+
template <key_type... bits>
|
|
86
|
+
constexpr bool all_bits_set() const noexcept
|
|
87
|
+
{
|
|
88
|
+
return utils::all_bits_set<static_cast<storage_type>(bits)...>(m_bitset);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Return true if the bit is set. */
|
|
92
|
+
template <key_type bit>
|
|
93
|
+
constexpr bool bit_is_set() const noexcept
|
|
94
|
+
{
|
|
95
|
+
return all_bits_set<bit>();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Set the corresponding bit to true in the bitfield. */
|
|
99
|
+
template <key_type bit>
|
|
100
|
+
constexpr void set_bit() noexcept
|
|
101
|
+
{
|
|
102
|
+
m_bitset = utils::set_bit<static_cast<storage_type>(bit)>(m_bitset);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Extract the bits in [start, end[, shifted down to start at bit 0. */
|
|
106
|
+
template <key_type start, key_type end>
|
|
107
|
+
constexpr storage_type get_range() const noexcept
|
|
108
|
+
{
|
|
109
|
+
constexpr storage_type start_bit = static_cast<storage_type>(start);
|
|
110
|
+
constexpr storage_type end_bit = static_cast<storage_type>(end);
|
|
111
|
+
constexpr storage_type width = end_bit - start_bit;
|
|
112
|
+
constexpr storage_type mask = make_low_mask<storage_type>(width);
|
|
113
|
+
return (m_bitset >> start_bit) & mask;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private:
|
|
117
|
+
storage_type m_bitset = { 0 };
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#endif
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/***************************************************************************
|
|
2
|
+
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
|
|
3
|
+
* Martin Renou *
|
|
4
|
+
* Copyright (c) QuantStack *
|
|
5
|
+
* Copyright (c) Serge Guelton *
|
|
6
|
+
* *
|
|
7
|
+
* Distributed under the terms of the BSD 3-Clause License. *
|
|
8
|
+
* *
|
|
9
|
+
* The full license is in the file LICENSE, distributed with this software. *
|
|
10
|
+
****************************************************************************/
|
|
11
|
+
|
|
12
|
+
#ifndef XSIMD_TYPE_TRAITS_HPP
|
|
13
|
+
#define XSIMD_TYPE_TRAITS_HPP
|
|
14
|
+
|
|
15
|
+
#include <cstddef>
|
|
16
|
+
#include <cstdint>
|
|
17
|
+
#include <type_traits>
|
|
18
|
+
|
|
19
|
+
namespace xsimd
|
|
20
|
+
{
|
|
21
|
+
namespace detail
|
|
22
|
+
{
|
|
23
|
+
template <std::size_t S>
|
|
24
|
+
struct sized_num_types;
|
|
25
|
+
|
|
26
|
+
template <>
|
|
27
|
+
struct sized_num_types<1>
|
|
28
|
+
{
|
|
29
|
+
using signed_type = std::int8_t;
|
|
30
|
+
using unsigned_type = std::uint8_t;
|
|
31
|
+
using floating_point_type = void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
template <>
|
|
35
|
+
struct sized_num_types<2>
|
|
36
|
+
{
|
|
37
|
+
using signed_type = std::int16_t;
|
|
38
|
+
using unsigned_type = std::uint16_t;
|
|
39
|
+
using floating_point_type = void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
template <>
|
|
43
|
+
struct sized_num_types<4>
|
|
44
|
+
{
|
|
45
|
+
using signed_type = std::int32_t;
|
|
46
|
+
using unsigned_type = std::uint32_t;
|
|
47
|
+
using floating_point_type = float;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
template <>
|
|
51
|
+
struct sized_num_types<8>
|
|
52
|
+
{
|
|
53
|
+
using signed_type = std::int64_t;
|
|
54
|
+
using unsigned_type = std::uint64_t;
|
|
55
|
+
using floating_point_type = double;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @ingroup type_traits
|
|
61
|
+
*
|
|
62
|
+
* Signed integer type with exactly @c S bytes (1, 2, 4, or 8).
|
|
63
|
+
*
|
|
64
|
+
* @tparam S size in bytes.
|
|
65
|
+
*/
|
|
66
|
+
template <std::size_t S>
|
|
67
|
+
using sized_int_t = typename detail::sized_num_types<S>::signed_type;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @ingroup type_traits
|
|
71
|
+
*
|
|
72
|
+
* Unsigned integer type with exactly @c S bytes (1, 2, 4, or 8).
|
|
73
|
+
*
|
|
74
|
+
* @tparam S size in bytes.
|
|
75
|
+
*/
|
|
76
|
+
template <std::size_t S>
|
|
77
|
+
using sized_uint_t = typename detail::sized_num_types<S>::unsigned_type;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @ingroup type_traits
|
|
81
|
+
*
|
|
82
|
+
* Floating-point type with exactly @c S bytes (4 for @c float, 8 for @c double).
|
|
83
|
+
* Yields @c void for sizes without a standard floating-point type (1, 2).
|
|
84
|
+
*
|
|
85
|
+
* @tparam S size in bytes.
|
|
86
|
+
*/
|
|
87
|
+
template <std::size_t S>
|
|
88
|
+
using sized_fp_t = typename detail::sized_num_types<S>::floating_point_type;
|
|
89
|
+
|
|
90
|
+
namespace detail
|
|
91
|
+
{
|
|
92
|
+
template <typename T, std::size_t factor, typename = void>
|
|
93
|
+
struct remap_num
|
|
94
|
+
{
|
|
95
|
+
using type = T;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
template <typename T, std::size_t factor>
|
|
99
|
+
struct remap_num<T, factor, std::enable_if_t<std::is_floating_point<T>::value>>
|
|
100
|
+
{
|
|
101
|
+
using type = xsimd::sized_fp_t<sizeof(T) * factor>;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
template <typename T, std::size_t factor>
|
|
105
|
+
struct remap_num<T, factor, std::enable_if_t<!std::is_floating_point<T>::value && std::is_signed<T>::value>>
|
|
106
|
+
{
|
|
107
|
+
using type = xsimd::sized_int_t<sizeof(T) * factor>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
template <typename T, std::size_t factor>
|
|
111
|
+
struct remap_num<T, factor, std::enable_if_t<!std::is_floating_point<T>::value && std::is_unsigned<T>::value>>
|
|
112
|
+
{
|
|
113
|
+
using type = xsimd::sized_uint_t<sizeof(T) * factor>;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @ingroup type_traits
|
|
119
|
+
*
|
|
120
|
+
* Remap numeral types to their fixed sized variant (``[u]int{8,16,32}_t``
|
|
121
|
+
* and pass through other types).
|
|
122
|
+
* Certain platforms have different types (*i.e.* not aliases) between
|
|
123
|
+
* ``char`` and ``int8_t``, or ``long long`` and ``int{32,64}_t``, with SIMD
|
|
124
|
+
* intrinsicts only defined for some of them.
|
|
125
|
+
* Handling them requires to cast to a known predictable type.
|
|
126
|
+
*
|
|
127
|
+
* @tparam T arithmetic type to project from.
|
|
128
|
+
*/
|
|
129
|
+
template <typename T>
|
|
130
|
+
using map_to_sized_type_t = typename detail::remap_num<T, /* factor= */ 1>::type;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @ingroup type_traits
|
|
134
|
+
*
|
|
135
|
+
* The next-wider arithmetic type for @c T: doubles the size while preserving
|
|
136
|
+
* signedness for integers and yielding @c double for @c float.
|
|
137
|
+
* Supported input types: @c [u]int{8,16,32}_t and @c float.
|
|
138
|
+
*
|
|
139
|
+
* @tparam T arithmetic type to widen.
|
|
140
|
+
*/
|
|
141
|
+
template <typename T>
|
|
142
|
+
using widen_t = typename detail::remap_num<T, /* factor= */ 2>::type;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/***************************************************************************
|
|
2
|
+
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
|
|
3
|
+
* Martin Renou *
|
|
4
|
+
* Copyright (c) QuantStack *
|
|
5
|
+
* Copyright (c) Serge Guelton *
|
|
6
|
+
* *
|
|
7
|
+
* Distributed under the terms of the BSD 3-Clause License. *
|
|
8
|
+
* *
|
|
9
|
+
* The full license is in the file LICENSE, distributed with this software. *
|
|
10
|
+
****************************************************************************/
|
|
11
|
+
|
|
12
|
+
#ifndef XSIMD_HPP
|
|
13
|
+
#define XSIMD_HPP
|
|
14
|
+
|
|
15
|
+
#include "config/xsimd_config.hpp"
|
|
16
|
+
#include "config/xsimd_macros.hpp"
|
|
17
|
+
|
|
18
|
+
#include "arch/xsimd_scalar.hpp"
|
|
19
|
+
#include "memory/xsimd_aligned_allocator.hpp"
|
|
20
|
+
#include "types/xsimd_batch_fwd.hpp"
|
|
21
|
+
|
|
22
|
+
#if defined(XSIMD_NO_SUPPORTED_ARCHITECTURE)
|
|
23
|
+
namespace xsimd
|
|
24
|
+
{
|
|
25
|
+
// no type definition or anything apart from scalar definition and aligned allocator
|
|
26
|
+
template <class T, class A>
|
|
27
|
+
class batch
|
|
28
|
+
{
|
|
29
|
+
static constexpr bool supported_architecture = sizeof(A*) == 0; // type-dependant but always false
|
|
30
|
+
static_assert(supported_architecture, "No SIMD architecture detected, cannot instantiate a batch");
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#else
|
|
35
|
+
#include "types/xsimd_batch.hpp"
|
|
36
|
+
#include "types/xsimd_batch_constant.hpp"
|
|
37
|
+
#include "types/xsimd_traits.hpp"
|
|
38
|
+
|
|
39
|
+
// This include must come last
|
|
40
|
+
#include "types/xsimd_api.hpp"
|
|
41
|
+
#endif // XSIMD_NO_SUPPORTED_ARCHITECTURE
|
|
42
|
+
|
|
43
|
+
#endif
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <unordered_set>
|
|
4
|
-
|
|
5
|
-
namespace phonemis::processor::num2word {
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A basic num2word configuration.
|
|
9
|
-
*
|
|
10
|
-
* @param allow_general_ord_notation when set to true, considers notations such as `2.` as ordinal number notations.
|
|
11
|
-
*/
|
|
12
|
-
struct Config {
|
|
13
|
-
bool allow_general_ord_notation = true;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
} // namespace phonemis::processor::num2word
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
#include "layer.h"
|
|
2
|
-
#include "../constants.h"
|
|
3
|
-
#include <phonemis/utils/unicode.h>
|
|
4
|
-
#include <phonemis/utils/conversions.h>
|
|
5
|
-
|
|
6
|
-
#include <algorithm>
|
|
7
|
-
#include <optional>
|
|
8
|
-
#include <stdexcept>
|
|
9
|
-
|
|
10
|
-
namespace phonemis::processor::num2word {
|
|
11
|
-
|
|
12
|
-
namespace {
|
|
13
|
-
// Checks if a character serves as a word boundary.
|
|
14
|
-
// In other words, it's either white space or special character.
|
|
15
|
-
bool is_boundary(char32_t c) {
|
|
16
|
-
return !utils::unicode::isalnum(c) && c != U'_';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Counts and returns the number of consecutive digits from the start index
|
|
20
|
-
size_t count_digits(std::u32string_view input, size_t start) {
|
|
21
|
-
auto it = std::find_if(
|
|
22
|
-
input.begin() + start, input.end(),
|
|
23
|
-
[](char32_t c) { return !utils::unicode::isdigit(c); });
|
|
24
|
-
return static_cast<size_t>(it - (input.begin() + start));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Checks if a character is a known currency symbol.
|
|
28
|
-
bool is_currency(char32_t c) {
|
|
29
|
-
for (auto sym : constants::kCurrencies) {
|
|
30
|
-
if (c == sym) return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
} // namespace
|
|
35
|
-
|
|
36
|
-
std::u32string Num2WordLayer::transform(std::u32string_view input) const {
|
|
37
|
-
// Normalize this language's decimal separator to U'.' between digits, so the
|
|
38
|
-
// scanning logic below can treat the dot as the canonical float/date separator.
|
|
39
|
-
// For languages whose separator already is U'.' (e.g. English) this is a no-op
|
|
40
|
-
// and we parse the original string in-place.
|
|
41
|
-
char32_t dec_sep = decimal_separator();
|
|
42
|
-
std::u32string owned;
|
|
43
|
-
std::u32string_view work = input;
|
|
44
|
-
if (dec_sep != U'.') {
|
|
45
|
-
owned.reserve(input.size());
|
|
46
|
-
for (size_t i = 0; i < input.size(); ++i) {
|
|
47
|
-
if (input[i] == dec_sep && i > 0 && i + 1 < input.size() &&
|
|
48
|
-
utils::unicode::isdigit(input[i - 1]) && utils::unicode::isdigit(input[i + 1])) {
|
|
49
|
-
owned.push_back(U'.');
|
|
50
|
-
} else {
|
|
51
|
-
owned.push_back(input[i]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
work = owned;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
std::u32string result;
|
|
58
|
-
result.reserve(work.size());
|
|
59
|
-
|
|
60
|
-
size_t last_pos = 0;
|
|
61
|
-
for (size_t i = 0; i < work.size(); ++i) {
|
|
62
|
-
// Look for the start of a number, ensuring it's at a word boundary
|
|
63
|
-
if (!utils::unicode::isdigit(work[i])) continue;
|
|
64
|
-
if (i > 0 && !is_boundary(work[i - 1])) continue;
|
|
65
|
-
|
|
66
|
-
size_t start = i;
|
|
67
|
-
size_t len = 0;
|
|
68
|
-
Mode mode = Mode::CARDINAL;
|
|
69
|
-
|
|
70
|
-
// Parse the first group of digits
|
|
71
|
-
size_t p1 = count_digits(work, start);
|
|
72
|
-
size_t curr = start + p1;
|
|
73
|
-
|
|
74
|
-
// Check for compound numbers like dates, floats, fractions, or dot-ordinals
|
|
75
|
-
if (curr < work.size() && (work[curr] == U'.' || work[curr] == U'-' || work[curr] == U'/')) {
|
|
76
|
-
char32_t sep = work[curr];
|
|
77
|
-
size_t p2 = count_digits(work, curr + 1);
|
|
78
|
-
|
|
79
|
-
if (p2 > 0) {
|
|
80
|
-
size_t next_curr = curr + 1 + p2;
|
|
81
|
-
|
|
82
|
-
// Try to match a DATE pattern (e.g., DD.MM.YYYY, YYYY-MM-DD)
|
|
83
|
-
if (next_curr < work.size() && work[next_curr] == sep && (sep == U'.' || sep == U'-')) {
|
|
84
|
-
size_t p3 = count_digits(work, next_curr + 1);
|
|
85
|
-
// Ensure the date ends at a boundary and parts have reasonable lengths
|
|
86
|
-
if (p3 > 0 && (next_curr + 1 + p3 == work.size() || is_boundary(work[next_curr + 1 + p3]))) {
|
|
87
|
-
if (p1 <= 4 && p2 <= 2 && p3 <= 4) {
|
|
88
|
-
len = next_curr + 1 + p3 - start;
|
|
89
|
-
mode = Mode::DATE;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If it's not a date, evaluate for FLOAT or FRACTION
|
|
95
|
-
if (len == 0 && (curr + 1 + p2 == work.size() || is_boundary(work[curr + 1 + p2]))) {
|
|
96
|
-
len = curr + 1 + p2 - start;
|
|
97
|
-
size_t after = start + len;
|
|
98
|
-
if (sep != U'/' && after < work.size() && is_currency(work[after]) &&
|
|
99
|
-
(after + 1 == work.size() || is_boundary(work[after + 1]))) {
|
|
100
|
-
len++;
|
|
101
|
-
mode = Mode::CURRENCY;
|
|
102
|
-
} else {
|
|
103
|
-
mode = (sep == U'/') ? Mode::FRACTION : Mode::CARDINAL;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} else if (sep == U'.') {
|
|
107
|
-
// No second digit part found, might be an ORDINAL ending with a dot (e.g. '1.')
|
|
108
|
-
len = p1 + 1;
|
|
109
|
-
mode = Mode::ORDINAL;
|
|
110
|
-
|
|
111
|
-
// Check the trailing context for ordinal notation validation (typically expects a lowercase word next)
|
|
112
|
-
size_t next_pos = start + len;
|
|
113
|
-
while (next_pos < work.size() && utils::unicode::isspace(work[next_pos])) {
|
|
114
|
-
next_pos++;
|
|
115
|
-
}
|
|
116
|
-
if (!config_.allow_general_ord_notation || next_pos >= work.size() || !utils::unicode::islower(work[next_pos])) {
|
|
117
|
-
// Revert to plain Cardinal if context does not match ordinal expectations
|
|
118
|
-
mode = Mode::CARDINAL;
|
|
119
|
-
len--; // Exclude the trailing dot
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// If no compound pattern was successfully identified
|
|
125
|
-
if (len == 0) {
|
|
126
|
-
// Check for CURRENCY (number followed by single currency symbol)
|
|
127
|
-
if (curr < work.size() && is_currency(work[curr]) &&
|
|
128
|
-
(curr + 1 == work.size() || is_boundary(work[curr + 1]))) {
|
|
129
|
-
len = p1 + 1;
|
|
130
|
-
mode = Mode::CURRENCY;
|
|
131
|
-
} else {
|
|
132
|
-
// Unicode-aware scan so language suffixes with non-ASCII letters
|
|
133
|
-
// (e.g. French "ème", Spanish "º") are captured in full.
|
|
134
|
-
size_t alpha = 0;
|
|
135
|
-
while (curr + alpha < work.size() && utils::unicode::isalpha(work[curr + alpha])) {
|
|
136
|
-
alpha++;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Check for POTENTIALLY ORDINAL values (numbers directly followed by letters, e.g., '1st', '2nd')
|
|
140
|
-
if (alpha > 0 && (curr + alpha == work.size() || is_boundary(work[curr + alpha]))) {
|
|
141
|
-
len = p1 + alpha;
|
|
142
|
-
mode = Mode::POTENTIALLY_ORDINAL;
|
|
143
|
-
}
|
|
144
|
-
// Otherwise, assume it's a standard integer CARDINAL
|
|
145
|
-
else if (curr == work.size() || is_boundary(work[curr])) {
|
|
146
|
-
len = p1;
|
|
147
|
-
mode = Mode::CARDINAL;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Apply translation if a valid numeric chunk was found
|
|
153
|
-
if (len > 0) {
|
|
154
|
-
result.append(work.substr(last_pos, start - last_pos)); // Append preceding text
|
|
155
|
-
result.append(verbalize({work.substr(start, len), mode})); // Append converted number
|
|
156
|
-
last_pos = start + len;
|
|
157
|
-
// Fast-forward the loop index to avoid re-processing the characters in the current numeric chunk.
|
|
158
|
-
i = start + len - 1;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
result.append(work.substr(last_pos));
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
std::u32string Num2WordLayer::verbalize(const StringifiedNumber& number) const {
|
|
167
|
-
switch (number.conversionMode) {
|
|
168
|
-
case Mode::CARDINAL: {
|
|
169
|
-
if (number.text.find(U'.') != std::u32string_view::npos) {
|
|
170
|
-
auto val = as_float(number.text);
|
|
171
|
-
if (!val) return U"";
|
|
172
|
-
return to_cardinal_float(*val, number.text);
|
|
173
|
-
} else {
|
|
174
|
-
auto val = as_int(number.text);
|
|
175
|
-
if (!val) return U"";
|
|
176
|
-
return to_cardinal_int(*val);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
case Mode::POTENTIALLY_ORDINAL: {
|
|
180
|
-
size_t i = 0;
|
|
181
|
-
while (i < number.text.size() && utils::unicode::isdigit(number.text[i])) i++;
|
|
182
|
-
std::u32string_view num_part = number.text.substr(0, i);
|
|
183
|
-
std::u32string_view suffix = number.text.substr(i);
|
|
184
|
-
auto val = as_int(num_part);
|
|
185
|
-
if (!val) return U"";
|
|
186
|
-
if (is_ordinal_suffix(suffix)) {
|
|
187
|
-
return to_ordinal_int(*val, suffix);
|
|
188
|
-
} else {
|
|
189
|
-
return to_ordinal_int(*val) + std::u32string(suffix);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
case Mode::ORDINAL: {
|
|
193
|
-
std::u32string_view num_part = number.text.substr(0, number.text.size() - 1);
|
|
194
|
-
auto val = as_int(num_part);
|
|
195
|
-
if (!val) return U"";
|
|
196
|
-
return to_ordinal_int(*val);
|
|
197
|
-
}
|
|
198
|
-
case Mode::FRACTION: {
|
|
199
|
-
size_t pos = number.text.find(U'/');
|
|
200
|
-
auto num = as_int(number.text.substr(0, pos));
|
|
201
|
-
auto den = as_int(number.text.substr(pos + 1));
|
|
202
|
-
if (!num || !den) return U"";
|
|
203
|
-
return to_fraction(*num, *den);
|
|
204
|
-
}
|
|
205
|
-
case Mode::CURRENCY: {
|
|
206
|
-
char32_t currency = number.text.back();
|
|
207
|
-
std::u32string_view num_part = number.text.substr(0, number.text.size() - 1);
|
|
208
|
-
if (num_part.find(U'.') != std::u32string_view::npos) {
|
|
209
|
-
auto val = as_float(num_part);
|
|
210
|
-
if (!val) return U"";
|
|
211
|
-
return to_cardinal_float(*val, num_part) + U" " + to_currency(currency, *val);
|
|
212
|
-
} else {
|
|
213
|
-
auto val = as_int(num_part);
|
|
214
|
-
if (!val) return U"";
|
|
215
|
-
return to_cardinal_int(*val) + U" " + to_currency(currency, *val);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
case Mode::DATE: {
|
|
219
|
-
char32_t sep = (number.text.find(U'.') != std::u32string_view::npos) ? U'.' : U'-';
|
|
220
|
-
size_t first_sep = number.text.find(sep);
|
|
221
|
-
size_t second_sep = number.text.find(sep, first_sep + 1);
|
|
222
|
-
|
|
223
|
-
std::u32string_view p1 = number.text.substr(0, first_sep);
|
|
224
|
-
std::u32string_view p2 = number.text.substr(first_sep + 1, second_sep - first_sep - 1);
|
|
225
|
-
std::u32string_view p3 = number.text.substr(second_sep + 1);
|
|
226
|
-
|
|
227
|
-
auto val1 = as_int(p1);
|
|
228
|
-
auto val2 = as_int(p2);
|
|
229
|
-
auto val3 = as_int(p3);
|
|
230
|
-
|
|
231
|
-
if (!val1 || !val2 || !val3) return U"";
|
|
232
|
-
|
|
233
|
-
// ISO format: YYYY-MM-DD
|
|
234
|
-
if (p1.size() == 4) {
|
|
235
|
-
return to_day(static_cast<uint32_t>(*val3)) + U" " + to_month(*val2) + U" " + to_year(*val1);
|
|
236
|
-
}
|
|
237
|
-
// Common format: DD.MM.YYYY (or similar)
|
|
238
|
-
return to_day(static_cast<uint32_t>(*val1)) + U" " + to_month(*val2) + U" " + to_year(*val3);
|
|
239
|
-
}
|
|
240
|
-
case Mode::MONTH: {
|
|
241
|
-
auto m = as_int(number.text);
|
|
242
|
-
if (!m) return U"";
|
|
243
|
-
return (*m >= 1 && *m <= 12) ? to_month(*m) : to_cardinal_int(*m);
|
|
244
|
-
}
|
|
245
|
-
case Mode::YEAR: {
|
|
246
|
-
auto y = as_int(number.text);
|
|
247
|
-
if (!y) return U"";
|
|
248
|
-
return to_year(*y);
|
|
249
|
-
}
|
|
250
|
-
default:
|
|
251
|
-
return std::u32string(number.text);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
std::optional<int32_t> Num2WordLayer::as_int(std::u32string_view s) const {
|
|
256
|
-
try {
|
|
257
|
-
return std::stoi(utils::conversions::u32_to_utf8(s));
|
|
258
|
-
} catch (const std::exception& e) {
|
|
259
|
-
throw std::runtime_error("Error converting to int: " + std::string(e.what()));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
std::optional<float> Num2WordLayer::as_float(std::u32string_view s) const {
|
|
264
|
-
try {
|
|
265
|
-
return std::stof(utils::conversions::u32_to_utf8(s));
|
|
266
|
-
} catch (const std::exception& e) {
|
|
267
|
-
throw std::runtime_error("Error converting to float: " + std::string(e.what()));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
} // namespace phonemis::processor::num2word
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "config.h"
|
|
4
|
-
#include "types.h"
|
|
5
|
-
#include "../layer.h"
|
|
6
|
-
|
|
7
|
-
#include <concepts>
|
|
8
|
-
#include <cstdint>
|
|
9
|
-
#include <variant>
|
|
10
|
-
|
|
11
|
-
namespace phonemis::processor::num2word {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A skeleton for all numeric verbalizations inside the package.
|
|
15
|
-
*/
|
|
16
|
-
class Num2WordLayer : public Layer {
|
|
17
|
-
public:
|
|
18
|
-
Num2WordLayer() = default;
|
|
19
|
-
explicit Num2WordLayer(const Config& config) : config_(config) {}
|
|
20
|
-
|
|
21
|
-
// Utilizes template method pattern with abstract convertion (`convert()`) mechanism
|
|
22
|
-
std::u32string transform(std::u32string_view input) const override;
|
|
23
|
-
|
|
24
|
-
virtual char32_t decimal_separator() const = 0;
|
|
25
|
-
virtual std::u32string to_cardinal_int(int32_t number) const = 0;
|
|
26
|
-
virtual std::u32string to_cardinal_float(float number, std::u32string_view repr) const = 0;
|
|
27
|
-
virtual std::u32string to_ordinal_int(int32_t number, std::u32string_view suffix = U"") const = 0;
|
|
28
|
-
virtual std::u32string to_currency(char32_t currency, std::variant<int32_t, float> number) const = 0;
|
|
29
|
-
virtual std::u32string to_fraction(int32_t numerator, int32_t denominator) const = 0;
|
|
30
|
-
virtual std::u32string to_day(uint32_t day) const = 0;
|
|
31
|
-
virtual std::u32string to_month(uint32_t month) const = 0;
|
|
32
|
-
virtual std::u32string to_year(uint32_t year) const = 0;
|
|
33
|
-
virtual bool is_ordinal_suffix(std::u32string_view suffix) const = 0;
|
|
34
|
-
|
|
35
|
-
protected:
|
|
36
|
-
virtual std::u32string verbalize(const StringifiedNumber& number) const;
|
|
37
|
-
|
|
38
|
-
// Conversion wrappers, with extra logic & verbose behavior on errors.
|
|
39
|
-
std::optional<int32_t> as_int(std::u32string_view s) const;
|
|
40
|
-
std::optional<float> as_float(std::u32string_view s) const;
|
|
41
|
-
|
|
42
|
-
Config config_;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
} // namespace phonemis::processor::num2word
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <string_view>
|
|
5
|
-
|
|
6
|
-
namespace phonemis::processor::num2word {
|
|
7
|
-
|
|
8
|
-
// Specializes the behavior of `convert()` method.
|
|
9
|
-
enum class Mode {
|
|
10
|
-
CARDINAL = 0,
|
|
11
|
-
|
|
12
|
-
POTENTIALLY_ORDINAL,
|
|
13
|
-
ORDINAL,
|
|
14
|
-
|
|
15
|
-
FRACTION,
|
|
16
|
-
CURRENCY,
|
|
17
|
-
|
|
18
|
-
MONTH,
|
|
19
|
-
YEAR,
|
|
20
|
-
DATE
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// Conversion input - text representation + mode
|
|
24
|
-
struct StringifiedNumber {
|
|
25
|
-
std::u32string_view text;
|
|
26
|
-
Mode conversionMode = Mode::CARDINAL;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
} // namespace phonemis::processor::num2word
|