react-native-executorch 0.10.6 → 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/lib/module/fetcher/telemetry.js +1 -1
- package/package.json +1 -1
- package/react-native-executorch.podspec +2 -0
- package/src/fetcher/telemetry.ts +1 -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,285 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "notation.h"
|
|
4
|
+
#include "pattern.h"
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Patterns of numeric expressions
|
|
12
|
+
*
|
|
13
|
+
* Generic patterns are added for every language and read its Notation.
|
|
14
|
+
* Configurable patterns (dates, phones, suffixes) are added by each language with its own format.
|
|
15
|
+
*/
|
|
16
|
+
namespace phonemis::processor::num2word {
|
|
17
|
+
|
|
18
|
+
// ----------------------------
|
|
19
|
+
// ----- Generic patterns -----
|
|
20
|
+
// ----------------------------
|
|
21
|
+
|
|
22
|
+
// The generic patterns of a language.
|
|
23
|
+
std::vector<std::unique_ptr<Pattern>> generic_patterns(const Notation& notation);
|
|
24
|
+
|
|
25
|
+
// 2024-05-12: an ISO date. Its numbers are ordered as day, month, year.
|
|
26
|
+
class IsoDatePattern : public Pattern {
|
|
27
|
+
public:
|
|
28
|
+
IsoDatePattern() : Pattern(Kind::DATE) {}
|
|
29
|
+
|
|
30
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 3.8.10, 10.0.0.51; a chain of thousands groups (1.000.000) is left to numbers.
|
|
34
|
+
class VersionPattern : public Pattern {
|
|
35
|
+
public:
|
|
36
|
+
explicit VersionPattern(const Notation& notation);
|
|
37
|
+
|
|
38
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
std::u32string group_;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// The " - " of 5 - 3.
|
|
45
|
+
class DifferencePattern : public Pattern {
|
|
46
|
+
public:
|
|
47
|
+
DifferencePattern() : Pattern(Kind::DIFFERENCE) {}
|
|
48
|
+
|
|
49
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// The "+" of 2 + 2 or 90+6, with the spaces around it.
|
|
53
|
+
class SumPattern : public Pattern {
|
|
54
|
+
public:
|
|
55
|
+
SumPattern() : Pattern(Kind::SUM) {}
|
|
56
|
+
|
|
57
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// The "-" of 10-15 and 2020-2022. Its numbers are the digits on both sides.
|
|
61
|
+
class RangePattern : public Pattern {
|
|
62
|
+
public:
|
|
63
|
+
RangePattern() : Pattern(Kind::RANGE) {}
|
|
64
|
+
|
|
65
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// The "x" of 1920x1080, or of 3 m x 4 m (the units are left to UnitPattern).
|
|
69
|
+
class DimensionPattern : public Pattern {
|
|
70
|
+
public:
|
|
71
|
+
explicit DimensionPattern(const Notation& notation);
|
|
72
|
+
|
|
73
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
74
|
+
|
|
75
|
+
private:
|
|
76
|
+
Keys units_;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// 3/4
|
|
80
|
+
class FractionPattern : public Pattern {
|
|
81
|
+
public:
|
|
82
|
+
FractionPattern() : Pattern(Kind::FRACTION) {}
|
|
83
|
+
|
|
84
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// The minus of -5.
|
|
88
|
+
class SignPattern : public Pattern {
|
|
89
|
+
public:
|
|
90
|
+
SignPattern() : Pattern(Kind::SIGN) {}
|
|
91
|
+
|
|
92
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// 18:30, 10.30 pm, 21h30: hours and minutes, with an optional suffix.
|
|
96
|
+
class TimePattern : public Pattern {
|
|
97
|
+
public:
|
|
98
|
+
explicit TimePattern(const Notation& notation);
|
|
99
|
+
|
|
100
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
101
|
+
|
|
102
|
+
private:
|
|
103
|
+
// Whether a time may end at a position: not a longer number, nor a measure (1.30 min)
|
|
104
|
+
bool ends_at(std::u32string_view text, size_t position) const;
|
|
105
|
+
|
|
106
|
+
std::u32string separators_;
|
|
107
|
+
Keys suffixes_;
|
|
108
|
+
Keys measures_;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// 7pm, 18 Uhr, 21h: an hour marked by its suffix.
|
|
112
|
+
class HourPattern : public Pattern {
|
|
113
|
+
public:
|
|
114
|
+
explicit HourPattern(const Notation& notation);
|
|
115
|
+
|
|
116
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
117
|
+
|
|
118
|
+
private:
|
|
119
|
+
Keys suffixes_;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// The ":" of 2:1.
|
|
123
|
+
class ScorePattern : public Pattern {
|
|
124
|
+
public:
|
|
125
|
+
ScorePattern() : Pattern(Kind::SCORE) {}
|
|
126
|
+
|
|
127
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// $5, € 1,5 million: a currency symbol before an amount.
|
|
131
|
+
class PrefixedMoneyPattern : public Pattern {
|
|
132
|
+
public:
|
|
133
|
+
explicit PrefixedMoneyPattern(const Notation& notation);
|
|
134
|
+
|
|
135
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
136
|
+
|
|
137
|
+
private:
|
|
138
|
+
Notation notation_;
|
|
139
|
+
Keys currencies_; // Only the ones which are not words
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// 50$, 12,99 zł, 10-15 €, 3 mln zł: an amount, possibly a range, followed by its currency.
|
|
143
|
+
class MoneyPattern : public Pattern {
|
|
144
|
+
public:
|
|
145
|
+
explicit MoneyPattern(const Notation& notation);
|
|
146
|
+
|
|
147
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
148
|
+
|
|
149
|
+
private:
|
|
150
|
+
Notation notation_;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// 3 mln, 500k, 1.5 million
|
|
154
|
+
class ScalePattern : public Pattern {
|
|
155
|
+
public:
|
|
156
|
+
explicit ScalePattern(const Notation& notation);
|
|
157
|
+
|
|
158
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
159
|
+
|
|
160
|
+
private:
|
|
161
|
+
Notation notation_;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// 20%, 10-15 %, 8%ige
|
|
165
|
+
class PercentPattern : public Pattern {
|
|
166
|
+
public:
|
|
167
|
+
explicit PercentPattern(const Notation& notation);
|
|
168
|
+
|
|
169
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
170
|
+
|
|
171
|
+
private:
|
|
172
|
+
Notation notation_;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// 5 kg, 10-15 km, 230 V; a unit of a single capital letter only after a space.
|
|
176
|
+
class UnitPattern : public Pattern {
|
|
177
|
+
public:
|
|
178
|
+
explicit UnitPattern(const Notation& notation);
|
|
179
|
+
|
|
180
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
181
|
+
|
|
182
|
+
private:
|
|
183
|
+
Notation notation_;
|
|
184
|
+
Keys letters_; // Units of a single capital letter (W, V)
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// 21-year-old, 45-metrowe: a number joined to a word by a hyphen.
|
|
188
|
+
class CompoundPattern : public Pattern {
|
|
189
|
+
public:
|
|
190
|
+
explicit CompoundPattern(const Notation& notation);
|
|
191
|
+
|
|
192
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
193
|
+
|
|
194
|
+
private:
|
|
195
|
+
Notation notation_;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// MP3, A380, COVID-19, H.264: a token mixing letters and digits.
|
|
199
|
+
class CodePattern : public Pattern {
|
|
200
|
+
public:
|
|
201
|
+
CodePattern() : Pattern(Kind::CODE) {}
|
|
202
|
+
|
|
203
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// 42, 1 000,5, .5: any other number.
|
|
207
|
+
class NumberPattern : public Pattern {
|
|
208
|
+
public:
|
|
209
|
+
explicit NumberPattern(const Notation& notation);
|
|
210
|
+
|
|
211
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
212
|
+
|
|
213
|
+
private:
|
|
214
|
+
Notation notation_;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// ---------------------------------
|
|
218
|
+
// ----- Configurable patterns -----
|
|
219
|
+
// ---------------------------------
|
|
220
|
+
|
|
221
|
+
// A numeric date. Its numbers are ordered as day, month and year (if written).
|
|
222
|
+
class DatePattern : public Pattern {
|
|
223
|
+
public:
|
|
224
|
+
explicit DatePattern(DateFormat format);
|
|
225
|
+
|
|
226
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
227
|
+
|
|
228
|
+
private:
|
|
229
|
+
// The date without (zero) or with its year, if it ends at a valid position
|
|
230
|
+
std::optional<Match> complete(std::u32string_view text, Match date, size_t position) const;
|
|
231
|
+
|
|
232
|
+
DateFormat format_;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// +48 600 123 456, +1 (555) 123-4567: a phone number with a country code. Its numbers are the code, then the groups.
|
|
236
|
+
class InternationalPhonePattern : public Pattern {
|
|
237
|
+
public:
|
|
238
|
+
InternationalPhonePattern() : Pattern(Kind::INTERNATIONAL_PHONE) {}
|
|
239
|
+
|
|
240
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// A phone number. Its numbers are its groups of digits.
|
|
244
|
+
class PhonePattern : public Pattern {
|
|
245
|
+
public:
|
|
246
|
+
explicit PhonePattern(PhoneFormat format);
|
|
247
|
+
|
|
248
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
249
|
+
|
|
250
|
+
private:
|
|
251
|
+
// The phone number starting with its first group at a position
|
|
252
|
+
std::optional<Match> groups_at(std::u32string_view text, size_t start, size_t position) const;
|
|
253
|
+
|
|
254
|
+
PhoneFormat format_;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// Digits followed by a suffix from a table.
|
|
258
|
+
class SuffixPattern : public Pattern {
|
|
259
|
+
public:
|
|
260
|
+
SuffixPattern(Kind kind, Keys suffixes, SuffixFormat format = {});
|
|
261
|
+
|
|
262
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
263
|
+
|
|
264
|
+
private:
|
|
265
|
+
Keys suffixes_;
|
|
266
|
+
SuffixFormat format_;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// 3. Platz, 55. sesję: an ordinal written as digits with a dot, followed by a word.
|
|
270
|
+
class DotOrdinalPattern : public Pattern {
|
|
271
|
+
public:
|
|
272
|
+
/**
|
|
273
|
+
* @param before_punctuation also before a comma or at the end of the text: lat 70., Punkt 3.
|
|
274
|
+
* @param sentence_dot leaves the dot to a sentence it also closes.
|
|
275
|
+
*/
|
|
276
|
+
explicit DotOrdinalPattern(bool before_punctuation = false, bool sentence_dot = false);
|
|
277
|
+
|
|
278
|
+
std::optional<Match> match(std::u32string_view text, size_t position) const override;
|
|
279
|
+
|
|
280
|
+
private:
|
|
281
|
+
bool before_punctuation_;
|
|
282
|
+
bool sentence_dot_;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
} // namespace phonemis::processor::num2word
|
package/third-party/common/phonemis/src/phonemis/base/processor/layers/num2word/primitives.cpp
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#include "../../common/text.h"
|
|
2
|
+
#include "primitives.h"
|
|
3
|
+
#include <phonemis/utils/strings.h>
|
|
4
|
+
#include <phonemis/utils/unicode.h>
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
|
|
8
|
+
namespace phonemis::processor::num2word {
|
|
9
|
+
|
|
10
|
+
using namespace utils;
|
|
11
|
+
|
|
12
|
+
Number digits_at(std::u32string_view text, size_t position) {
|
|
13
|
+
size_t end = digits_end(text, position);
|
|
14
|
+
return {.span = {position, end}, .integer = std::u32string(text.substr(position, end - position))};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
std::vector<Number> numbers_at(std::u32string_view text, size_t position, std::u32string_view group,
|
|
18
|
+
std::u32string_view decimal) {
|
|
19
|
+
size_t run = digits_end(text, position) - position;
|
|
20
|
+
if (run == 0) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Integer parts: 1-3 digits followed by whole groups (1 000 000), then a plain run of digits
|
|
25
|
+
std::vector<Number> integers;
|
|
26
|
+
if (run <= 3) {
|
|
27
|
+
size_t end = position + run;
|
|
28
|
+
while (end + 3 < text.size() && strings::contains(group, text[end]) && digits_end(text, end + 1) >= end + 4) {
|
|
29
|
+
end += 4;
|
|
30
|
+
}
|
|
31
|
+
// A group may not be followed by a digit, nor by a separator and a digit
|
|
32
|
+
bool complete = end > position + run && !is_digit_after(text, end) &&
|
|
33
|
+
!(end < text.size() && strings::contains(group, text[end]) && is_digit_after(text, end + 1));
|
|
34
|
+
if (complete) {
|
|
35
|
+
std::u32string digits;
|
|
36
|
+
std::ranges::copy_if(text.substr(position, end - position), std::back_inserter(digits), unicode::isdigit);
|
|
37
|
+
integers.push_back({.span = {position, end}, .integer = digits, .grouped = true});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
integers.push_back(digits_at(text, position));
|
|
41
|
+
|
|
42
|
+
// Each with its fraction first, then without it
|
|
43
|
+
std::vector<Number> numbers;
|
|
44
|
+
for (const Number& integer : integers) {
|
|
45
|
+
size_t end = integer.span.end;
|
|
46
|
+
if (end < text.size() && strings::contains(decimal, text[end]) && is_digit_after(text, end + 1)) {
|
|
47
|
+
Number number = integer;
|
|
48
|
+
number.span.end = digits_end(text, end + 1);
|
|
49
|
+
number.fraction = text.substr(end + 1, number.span.end - end - 1);
|
|
50
|
+
number.decimal_mark = text[end];
|
|
51
|
+
|
|
52
|
+
// A fraction shaped like a group is one: the 1.980 of 1.980,6
|
|
53
|
+
if (!integer.grouped && integer.integer.size() <= 3 && number.fraction.size() == 3 &&
|
|
54
|
+
strings::contains(group, number.decimal_mark)) {
|
|
55
|
+
number = {.span = number.span, .integer = integer.integer + number.fraction, .grouped = true};
|
|
56
|
+
}
|
|
57
|
+
numbers.push_back(number);
|
|
58
|
+
}
|
|
59
|
+
numbers.push_back(integer);
|
|
60
|
+
}
|
|
61
|
+
return numbers;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
} // namespace phonemis::processor::num2word
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../common/text.h"
|
|
4
|
+
#include "types.h"
|
|
5
|
+
|
|
6
|
+
#include <string_view>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
// Scanning primitives of written numbers, on top of the shared ones (../text.h).
|
|
10
|
+
namespace phonemis::processor::num2word {
|
|
11
|
+
|
|
12
|
+
// The digits starting at a position, as a number.
|
|
13
|
+
Number digits_at(std::u32string_view text, size_t position);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A written number at a position: 1,000.5 or 1 000,5 or 15.
|
|
17
|
+
* @returns its possible readings, in the order a regex would try them: grouped first,
|
|
18
|
+
* each with and then without its fraction. Empty if no number starts there.
|
|
19
|
+
*/
|
|
20
|
+
std::vector<Number> numbers_at(std::u32string_view text, size_t position, std::u32string_view group,
|
|
21
|
+
std::u32string_view decimal);
|
|
22
|
+
|
|
23
|
+
} // namespace phonemis::processor::num2word
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../common/types.h"
|
|
4
|
+
#include "kind.h"
|
|
5
|
+
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <string_view>
|
|
8
|
+
#include <utility>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
namespace phonemis::processor::num2word {
|
|
12
|
+
|
|
13
|
+
using processor::Keys;
|
|
14
|
+
|
|
15
|
+
// A number as written: "1 000,5" -> integer "1000", fraction "5".
|
|
16
|
+
struct Number {
|
|
17
|
+
Span span; // Where it is written
|
|
18
|
+
std::u32string integer; // Digits without group separators; empty in ".5"
|
|
19
|
+
std::u32string fraction; // Digits after the decimal mark; empty if none
|
|
20
|
+
char32_t decimal_mark = 0; // The decimal mark as written, if any
|
|
21
|
+
bool grouped = false; // Written with group separators: 1 000, 1,000
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// A numeric expression found in a text: its structure only, with no decision on how to read it.
|
|
25
|
+
struct Match {
|
|
26
|
+
Kind kind = Kind::NUMBER;
|
|
27
|
+
Span span;
|
|
28
|
+
std::u32string_view text; // As written
|
|
29
|
+
std::vector<Number> numbers; // In written order: one for most kinds, two for ranges, three for dates
|
|
30
|
+
std::u32string_view unit; // A unit or currency key ("km", "zł"), or a law word of a DATE ("Ley")
|
|
31
|
+
std::u32string_view scale; // A scale key ("mln", "million")
|
|
32
|
+
std::u32string_view suffix; // Marks after the number: "st", "er", "." (ordinals), "ige" (8%ige), "pm", "r."
|
|
33
|
+
char32_t separator = 0; // The symbol between numbers: '-', ':', '.', '/', 'h', 'x'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Words read in place of the symbols between numbers.
|
|
37
|
+
struct Joiners {
|
|
38
|
+
std::u32string point; // 3.8.10: three point eight point ten
|
|
39
|
+
std::u32string dot; // 10.0.0.51 (four parts): ten dot zero dot zero dot fifty-one
|
|
40
|
+
std::u32string range; // 10-15, with its own spaces: " to ", " bis ", "-"
|
|
41
|
+
std::u32string by; // 1920x1080
|
|
42
|
+
std::u32string score; // 2:1, with its own spaces: " to "
|
|
43
|
+
std::u32string minus; // -5 and 5 - 3
|
|
44
|
+
std::u32string plus; // 2 + 2
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The forms of a noun after a number: one dollar, two dollars.
|
|
48
|
+
struct Forms {
|
|
49
|
+
std::u32string one;
|
|
50
|
+
std::u32string many;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Vocabulary of readings: languages build their own readings out of these
|
|
54
|
+
enum class Form { CARDINAL = 0, ORDINAL, YEAR, DIGITS };
|
|
55
|
+
enum class Case { NOMINATIVE = 0, GENITIVE, DATIVE, ACCUSATIVE, INSTRUMENTAL, LOCATIVE };
|
|
56
|
+
enum class Gender { MASCULINE = 0, FEMININE, NEUTER };
|
|
57
|
+
|
|
58
|
+
// ---------------------------------------------
|
|
59
|
+
// ----- Formats of configurable patterns -----
|
|
60
|
+
// ---------------------------------------------
|
|
61
|
+
|
|
62
|
+
// How a numeric date is written in a language: 12.05.2024, 12/05/24, 1. 5.
|
|
63
|
+
struct DateFormat {
|
|
64
|
+
std::u32string separators = U"/"; // Between its parts: the same one twice in a date
|
|
65
|
+
std::u32string boundaries = U".,/"; // Besides letters, what may not precede it (or a digit after it)
|
|
66
|
+
bool year_required = true;
|
|
67
|
+
bool short_year = true; // Two-digit years: 12/05/24
|
|
68
|
+
bool closing_separator = false; // A separator also closes the month: 1.5. and 1.5.2024
|
|
69
|
+
bool spaced = false; // An optional space after the day: 12. 5.
|
|
70
|
+
Keys suffixes; // Abbreviations after the year: 2024 r.
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// How a phone number is written: its groups of digits and what separates them.
|
|
74
|
+
struct PhoneFormat {
|
|
75
|
+
std::vector<std::pair<size_t, size_t>> groups; // Length range of each group of digits
|
|
76
|
+
std::u32string separators = U"-";
|
|
77
|
+
bool optional_separators = false; // 0612345678 as well as 06 12 34 56 78
|
|
78
|
+
std::u32string prefix; // An optional literal start: "1-"
|
|
79
|
+
bool parenthesized = false; // The first group in parentheses, then an optional space: (555) 123-4567
|
|
80
|
+
bool leading_zero = false;
|
|
81
|
+
std::u32string boundaries = U"-"; // Besides letters, what may not stand right before it
|
|
82
|
+
std::u32string closing = U"-"; // Besides letters, what may not stand right after it
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// How a suffix marks a number: 21st, 1 º, 90's, 2020 r.
|
|
86
|
+
struct SuffixFormat {
|
|
87
|
+
bool space = false; // An optional space before the suffix
|
|
88
|
+
bool word_end = true; // No word character may follow the suffix
|
|
89
|
+
bool apostrophes = false; // '90s, 90's: optional apostrophes before the number and the suffix
|
|
90
|
+
std::u32string boundaries = U".,"; // Besides letters, what may not stand right before the number
|
|
91
|
+
bool sentence_dot = false; // A dot closing the suffix is left to a sentence it also closes
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
} // namespace phonemis::processor::num2word
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "layer.h"
|
|
2
|
+
|
|
3
|
+
namespace phonemis::processor::sanitizer {
|
|
4
|
+
|
|
5
|
+
SanitizerLayer::SanitizerLayer(Filter filter, Mapper mapper) : filter_(std::move(filter)), mapper_(std::move(mapper)) {}
|
|
6
|
+
|
|
7
|
+
void SanitizerLayer::apply(Document& document) const {
|
|
8
|
+
std::u32string_view text = document.text();
|
|
9
|
+
|
|
10
|
+
for (size_t i = 0; i < text.size(); ++i) {
|
|
11
|
+
if (!filter_(text[i])) {
|
|
12
|
+
document.replace({i, i + 1}, U"");
|
|
13
|
+
} else if (char32_t c = mapper_(text[i]); c != text[i]) {
|
|
14
|
+
document.replace({i, i + 1}, std::u32string(1, c));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace phonemis::processor::sanitizer
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include "layer.h"
|
|
3
|
+
#include "../../layer.h"
|
|
4
4
|
|
|
5
5
|
#include <functional>
|
|
6
|
-
#include <string>
|
|
7
6
|
|
|
8
|
-
namespace phonemis::processor {
|
|
7
|
+
namespace phonemis::processor::sanitizer {
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Sanitizer layer is responsible for filtering out (and/or replacing) unrecognizable
|
|
12
11
|
* or undesirable characters in given language.
|
|
12
|
+
*
|
|
13
|
+
* It is controlled by a filter function (boolean check) and a mapping function (replacement).
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
+
* IMPORTANT: Should only be applied after Num2Word and Sym2Word layers.
|
|
15
16
|
*/
|
|
16
17
|
class SanitizerLayer : public Layer {
|
|
17
18
|
public:
|
|
18
19
|
using Filter = std::function<bool(char32_t)>;
|
|
19
20
|
using Mapper = std::function<char32_t(char32_t)>;
|
|
20
21
|
|
|
21
|
-
SanitizerLayer(Filter filter = [](char32_t c) { return true; },
|
|
22
|
-
Mapper mapper = [](char32_t c) { return c; });
|
|
22
|
+
SanitizerLayer(Filter filter = [](char32_t c) { return true; }, Mapper mapper = [](char32_t c) { return c; });
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
void apply(Document& document) const override;
|
|
25
25
|
|
|
26
26
|
private:
|
|
27
27
|
Filter filter_;
|
|
28
28
|
Mapper mapper_;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
} // namespace phonemis::processor
|
|
31
|
+
} // namespace phonemis::processor::sanitizer
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#include "../../common/constants.h"
|
|
2
|
+
#include "../../common/text.h"
|
|
3
|
+
#include "layer.h"
|
|
4
|
+
#include <phonemis/utils/strings.h>
|
|
5
|
+
#include <phonemis/utils/unicode.h>
|
|
6
|
+
|
|
7
|
+
namespace phonemis::processor::sym2word {
|
|
8
|
+
|
|
9
|
+
using namespace utils;
|
|
10
|
+
|
|
11
|
+
Sym2WordLayer::Sym2WordLayer(Symbols symbols) : symbols_(std::move(symbols)) {
|
|
12
|
+
for (const auto& [symbol, readings] : symbols_) {
|
|
13
|
+
keys_.push_back(symbol);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void Sym2WordLayer::apply(Document& document) const {
|
|
18
|
+
std::u32string_view text = document.text();
|
|
19
|
+
|
|
20
|
+
for (size_t start = 0; start < text.size();) {
|
|
21
|
+
// 1. A run of symbols, with the whitespaces around it: " & ", "++"
|
|
22
|
+
size_t symbol = start;
|
|
23
|
+
while (symbol < text.size() && unicode::isspace(text[symbol])) {
|
|
24
|
+
symbol++;
|
|
25
|
+
}
|
|
26
|
+
std::vector<std::u32string_view> symbols;
|
|
27
|
+
size_t end = symbol;
|
|
28
|
+
for (auto keys = keys_at(text, end, keys_); !keys.empty(); keys = keys_at(text, end, keys_)) {
|
|
29
|
+
symbols.push_back(keys.front());
|
|
30
|
+
end += keys.front().size();
|
|
31
|
+
}
|
|
32
|
+
if (symbols.empty()) {
|
|
33
|
+
start = symbol > start ? symbol : start + 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
while (end < text.size() && unicode::isspace(text[end])) {
|
|
37
|
+
end++;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 2. The words of each symbol in the context of the run
|
|
41
|
+
Context context(text, {start, end});
|
|
42
|
+
std::vector<std::u32string> words;
|
|
43
|
+
for (auto s : symbols) {
|
|
44
|
+
auto reading = read(symbols_.at(std::u32string(s)), context);
|
|
45
|
+
if (std::u32string word = reading.value_or(std::u32string(s)); !word.empty()) {
|
|
46
|
+
words.push_back(word);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 3. The words, separated from the text around by single spaces (none before punctuation).
|
|
51
|
+
// A run right after another one already has its space: "™ &" -> "trademark and"
|
|
52
|
+
bool left = start > 0 && !unicode::isspace(text[start - 1]);
|
|
53
|
+
std::u32string replacement;
|
|
54
|
+
if (words.empty()) {
|
|
55
|
+
replacement = left && end < text.size() ? U" " : U"";
|
|
56
|
+
} else {
|
|
57
|
+
bool right = end < text.size() && !strings::contains(constants::kPunctuation, text[end]);
|
|
58
|
+
replacement = (left ? U" " : U"") + join(words) + (right ? U" " : U"");
|
|
59
|
+
}
|
|
60
|
+
document.replace({start, end}, replacement);
|
|
61
|
+
start = end;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
} // namespace phonemis::processor::sym2word
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "../../common/conditions.h"
|
|
4
|
+
#include "../../layer.h"
|
|
5
|
+
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace phonemis::processor::sym2word {
|
|
10
|
+
|
|
11
|
+
// Symbols with their readings: & -> and; + -> plus after a name (Google+), más otherwise.
|
|
12
|
+
using Symbols = Readings;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reads the symbols left in a text as words, after numbers are read.
|
|
16
|
+
* A symbol whose readings all have unmet conditions stays as written.
|
|
17
|
+
*/
|
|
18
|
+
class Sym2WordLayer : public Layer {
|
|
19
|
+
public:
|
|
20
|
+
explicit Sym2WordLayer(Symbols symbols);
|
|
21
|
+
|
|
22
|
+
void apply(Document& document) const override;
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
Symbols symbols_;
|
|
26
|
+
Keys keys_;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
} // namespace phonemis::processor::sym2word
|