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
|
@@ -59,6 +59,14 @@ std::u32string Pipeline::operator()(std::u32string_view text, bool preprocess,
|
|
|
59
59
|
return (*impl_)(text, preprocess, postprocess);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
PhonemizedText Pipeline::phonemize_words(std::string_view text) {
|
|
63
|
+
return impl_->phonemize_words(text);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
PhonemizedText Pipeline::phonemize_words(std::u32string_view text) {
|
|
67
|
+
return impl_->phonemize_words(text);
|
|
68
|
+
}
|
|
69
|
+
|
|
62
70
|
std::u32string Pipeline::preprocess(const std::u32string& input) {
|
|
63
71
|
return impl_->preprocess(input);
|
|
64
72
|
}
|
|
@@ -35,6 +35,25 @@ public:
|
|
|
35
35
|
bool preprocess = true,
|
|
36
36
|
bool postprocess = true) override;
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Performs a complete G2P processing and locates each word of the input in
|
|
40
|
+
* the result. Every word maps onto its own space-separated phoneme group,
|
|
41
|
+
* except for numbers, which take as many groups as they were spelled out into.
|
|
42
|
+
* @param text an input text (utf-8) to be processed.
|
|
43
|
+
* @returns phonemization of given input text, with its words located in it.
|
|
44
|
+
* Word offsets count code points of the input converted to u32.
|
|
45
|
+
*/
|
|
46
|
+
PhonemizedText phonemize_words(std::string_view text) override;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Performs a complete G2P processing and locates each word of the input in
|
|
50
|
+
* the result. Every word maps onto its own space-separated phoneme group,
|
|
51
|
+
* except for numbers, which take as many groups as they were spelled out into.
|
|
52
|
+
* @param text an input text (u32string_view) to be processed.
|
|
53
|
+
* @returns phonemization of given input text, with its words located in it.
|
|
54
|
+
*/
|
|
55
|
+
PhonemizedText phonemize_words(std::u32string_view text) override;
|
|
56
|
+
|
|
38
57
|
// Performs a preprocessing stage of the pipeline.
|
|
39
58
|
std::u32string preprocess(const std::u32string& input) override;
|
|
40
59
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include "conditions.h"
|
|
2
|
+
#include "text.h"
|
|
3
|
+
#include <phonemis/utils/unicode.h>
|
|
4
|
+
|
|
5
|
+
namespace phonemis::processor {
|
|
6
|
+
|
|
7
|
+
using namespace utils;
|
|
8
|
+
|
|
9
|
+
std::optional<std::u32string> read(const std::vector<Reading>& readings, const Context& context) {
|
|
10
|
+
for (const auto& reading : readings) {
|
|
11
|
+
if (!reading.when || reading.when(context)) {
|
|
12
|
+
return reading.words;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return std::nullopt;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
bool after_name(const Context& context) {
|
|
19
|
+
std::u32string_view head = context.head();
|
|
20
|
+
return head.size() >= 2 && unicode::isalpha(head[head.size() - 1]) && unicode::isalpha(head[head.size() - 2]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
bool before_number(const Context& context) {
|
|
24
|
+
std::u32string_view tail = context.tail();
|
|
25
|
+
return is_digit_after(tail, skip_space(tail, 0));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bool before_name(const Context& context) {
|
|
29
|
+
std::u32string word = context.after();
|
|
30
|
+
return !word.empty() && unicode::isupper(word[0]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Condition after_any(std::unordered_set<std::u32string> words) {
|
|
34
|
+
return [words = std::move(words)](const Context& context) { return words.contains(context.before()); };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "context.h"
|
|
4
|
+
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <optional>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <unordered_set>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace phonemis::processor {
|
|
13
|
+
|
|
14
|
+
// A condition on the context of a written phrase, which decides between its readings.
|
|
15
|
+
using Condition = std::function<bool(const Context&)>;
|
|
16
|
+
|
|
17
|
+
// A way of saying a written phrase (a symbol, an abbreviation), when its condition holds.
|
|
18
|
+
struct Reading {
|
|
19
|
+
Reading(const char32_t* words, Condition when = nullptr) : words(words), when(std::move(when)) {}
|
|
20
|
+
|
|
21
|
+
std::u32string words; // Empty words drop the phrase
|
|
22
|
+
Condition when; // Always, if none
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Written phrases with their readings: the first one whose condition holds is used.
|
|
26
|
+
using Readings = std::unordered_map<std::u32string, std::vector<Reading>>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The words of a phrase in its context.
|
|
30
|
+
* @returns the words of its first reading whose condition holds, or std::nullopt if there is none.
|
|
31
|
+
*/
|
|
32
|
+
std::optional<std::u32string> read(const std::vector<Reading>& readings, const Context& context);
|
|
33
|
+
|
|
34
|
+
// -----------------------
|
|
35
|
+
// ----- Conditions -----
|
|
36
|
+
// -----------------------
|
|
37
|
+
|
|
38
|
+
bool after_name(const Context& context); // Two letters right before: Google+
|
|
39
|
+
bool before_number(const Context& context); // A digit right after, possibly after a space: nr 5, nr5
|
|
40
|
+
bool before_name(const Context& context); // A capitalized word after: St. Louis
|
|
41
|
+
|
|
42
|
+
// The word before is one of given words: im § 5
|
|
43
|
+
Condition after_any(std::unordered_set<std::u32string> words);
|
|
44
|
+
|
|
45
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string_view>
|
|
4
|
+
|
|
5
|
+
namespace phonemis::processor::constants {
|
|
6
|
+
|
|
7
|
+
// Punctuation stripped from the words around a match
|
|
8
|
+
inline constexpr std::u32string_view kPunctuation = U".,;:!?\"'()[]«»„“”…";
|
|
9
|
+
|
|
10
|
+
} // namespace phonemis::processor::constants
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#include "constants.h"
|
|
2
|
+
#include "context.h"
|
|
3
|
+
#include <phonemis/utils/strings.h>
|
|
4
|
+
#include <phonemis/utils/unicode.h>
|
|
5
|
+
|
|
6
|
+
namespace phonemis::processor {
|
|
7
|
+
|
|
8
|
+
using namespace utils;
|
|
9
|
+
|
|
10
|
+
Context::Context(std::u32string_view text, Span span) : text_(text), span_(span) {}
|
|
11
|
+
|
|
12
|
+
std::u32string Context::before(size_t k) const {
|
|
13
|
+
// Walk back over k words of the head
|
|
14
|
+
std::u32string_view head = this->head();
|
|
15
|
+
size_t end = head.size();
|
|
16
|
+
for (; k > 0; --k) {
|
|
17
|
+
while (end > 0 && unicode::isspace(head[end - 1])) {
|
|
18
|
+
end--;
|
|
19
|
+
}
|
|
20
|
+
if (end == 0) {
|
|
21
|
+
return U"";
|
|
22
|
+
}
|
|
23
|
+
size_t begin = end;
|
|
24
|
+
while (begin > 0 && !unicode::isspace(head[begin - 1])) {
|
|
25
|
+
begin--;
|
|
26
|
+
}
|
|
27
|
+
if (k == 1) {
|
|
28
|
+
return strings::to_lower(stripped(head.substr(begin, end - begin)));
|
|
29
|
+
}
|
|
30
|
+
end = begin;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return U"";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
std::u32string Context::after(size_t k) const {
|
|
37
|
+
std::u32string_view tail = this->tail();
|
|
38
|
+
if (!tail.empty() && strings::contains(constants::kPunctuation, tail[0])) {
|
|
39
|
+
return U"";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Walk forward over k words of the tail
|
|
43
|
+
size_t begin = 0;
|
|
44
|
+
for (; k > 0; --k) {
|
|
45
|
+
while (begin < tail.size() && unicode::isspace(tail[begin])) {
|
|
46
|
+
begin++;
|
|
47
|
+
}
|
|
48
|
+
if (begin == tail.size()) {
|
|
49
|
+
return U"";
|
|
50
|
+
}
|
|
51
|
+
size_t end = begin;
|
|
52
|
+
while (end < tail.size() && !unicode::isspace(tail[end])) {
|
|
53
|
+
end++;
|
|
54
|
+
}
|
|
55
|
+
if (k == 1) {
|
|
56
|
+
return std::u32string(stripped(tail.substr(begin, end - begin)));
|
|
57
|
+
}
|
|
58
|
+
begin = end;
|
|
59
|
+
}
|
|
60
|
+
return U"";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
std::u32string_view Context::head() const {
|
|
64
|
+
return text_.substr(0, span_.begin);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
std::u32string_view Context::tail() const {
|
|
68
|
+
return text_.substr(span_.end);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
std::u32string_view Context::text() const {
|
|
72
|
+
return text_.substr(span_.begin, span_.end - span_.begin);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
std::vector<std::u32string_view> words_of(std::u32string_view text) {
|
|
76
|
+
std::vector<std::u32string_view> words;
|
|
77
|
+
|
|
78
|
+
for (size_t i = 0; i < text.size();) {
|
|
79
|
+
if (unicode::isspace(text[i])) {
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
size_t end = i;
|
|
84
|
+
while (end < text.size() && !unicode::isspace(text[end])) {
|
|
85
|
+
end++;
|
|
86
|
+
}
|
|
87
|
+
words.push_back(text.substr(i, end - i));
|
|
88
|
+
i = end;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return words;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
std::u32string_view stripped(std::u32string_view word) {
|
|
95
|
+
size_t begin = word.find_first_not_of(constants::kPunctuation);
|
|
96
|
+
if (begin == std::u32string_view::npos) {
|
|
97
|
+
return U"";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
size_t end = word.find_last_not_of(constants::kPunctuation);
|
|
101
|
+
|
|
102
|
+
return word.substr(begin, end - begin + 1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.h"
|
|
4
|
+
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <string_view>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace phonemis::processor {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The surroundings of a span of a text: the words before and after it.
|
|
13
|
+
*
|
|
14
|
+
* A word the span starts or ends inside of counts with its part outside the span.
|
|
15
|
+
*/
|
|
16
|
+
class Context {
|
|
17
|
+
public:
|
|
18
|
+
Context(std::u32string_view text, Span span);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The k-th word before the span, lowercased and without surrounding punctuation.
|
|
22
|
+
* Empty if there is no such word.
|
|
23
|
+
*/
|
|
24
|
+
std::u32string before(size_t k = 1) const;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The k-th word after the span, case kept, without surrounding punctuation.
|
|
28
|
+
* Empty if there is no such word, or if a punctuation mark directly follows the span.
|
|
29
|
+
*/
|
|
30
|
+
std::u32string after(size_t k = 1) const;
|
|
31
|
+
|
|
32
|
+
std::u32string_view head() const; // The text before the span
|
|
33
|
+
std::u32string_view tail() const; // The text after the span
|
|
34
|
+
std::u32string_view text() const; // The span itself
|
|
35
|
+
|
|
36
|
+
Span span() const { return span_; }
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
std::u32string_view text_;
|
|
40
|
+
Span span_;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Whitespace-separated words of a text, like Python's str.split().
|
|
44
|
+
std::vector<std::u32string_view> words_of(std::u32string_view text);
|
|
45
|
+
|
|
46
|
+
// A word without the punctuation around it.
|
|
47
|
+
std::u32string_view stripped(std::u32string_view word);
|
|
48
|
+
|
|
49
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#include "document.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
|
|
6
|
+
namespace phonemis::processor {
|
|
7
|
+
|
|
8
|
+
Document::Document(std::u32string_view text) : text_(text), original_size_(text.size()) {
|
|
9
|
+
// At first, the whole text is a single copied piece
|
|
10
|
+
if (!text.empty()) {
|
|
11
|
+
pieces_.push_back({.original = {0, text.size()}, .size = text.size()});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void Document::replace(Span span, std::u32string replacement) {
|
|
16
|
+
if (span.begin > span.end || span.end > text_.size()) {
|
|
17
|
+
throw std::invalid_argument("Document: edit span out of range");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Keep the edits sorted, so that commit() applies them in a single pass
|
|
21
|
+
auto it = std::ranges::upper_bound(edits_, span.begin, {}, [](const Edit& edit) { return edit.span.begin; });
|
|
22
|
+
bool overlaps_previous = it != edits_.begin() && std::prev(it)->span.end > span.begin;
|
|
23
|
+
bool overlaps_next = it != edits_.end() && it->span.begin < span.end;
|
|
24
|
+
if (overlaps_previous || overlaps_next) {
|
|
25
|
+
throw std::invalid_argument("Document: overlapping edits");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
edits_.insert(it, {span, std::move(replacement)});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void Document::commit() {
|
|
32
|
+
if (edits_.empty()) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Where each piece starts in the current text
|
|
37
|
+
std::vector<size_t> starts;
|
|
38
|
+
for (size_t start = 0; const auto& piece : pieces_) {
|
|
39
|
+
starts.push_back(start);
|
|
40
|
+
start += piece.size;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 1. Group the edits into the spans they really change.
|
|
44
|
+
// An edit inside an earlier replacement replaces all of it ("ten" -> "Ten" changes the whole "ten" of "10"),
|
|
45
|
+
// and edits whose widened spans meet are merged: each group (an edit itself) becomes one replaced piece.
|
|
46
|
+
std::vector<Edit> groups;
|
|
47
|
+
for (size_t i = 0; i < edits_.size();) {
|
|
48
|
+
// Extend the group while the next widened edit starts inside it
|
|
49
|
+
Edit group{.span = widen(edits_[i].span, starts)};
|
|
50
|
+
size_t last = i;
|
|
51
|
+
while (last + 1 < edits_.size() && widen(edits_[last + 1].span, starts).begin < group.span.end) {
|
|
52
|
+
group.span.end = std::max(group.span.end, widen(edits_[++last].span, starts).end);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Its text: the current text of the span, with each edit's text in place of its range
|
|
56
|
+
size_t position = group.span.begin;
|
|
57
|
+
for (; i <= last; ++i) {
|
|
58
|
+
group.text.append(text_, position, edits_[i].span.begin - position);
|
|
59
|
+
group.text.append(edits_[i].text);
|
|
60
|
+
position = edits_[i].span.end;
|
|
61
|
+
}
|
|
62
|
+
group.text.append(text_, position, group.span.end - position);
|
|
63
|
+
groups.push_back(std::move(group));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 2. Rebuild the text and its pieces, walking the groups and the old pieces side by side.
|
|
67
|
+
// Pieces before a group are kept, pieces it touches are merged into one replaced piece.
|
|
68
|
+
std::u32string text;
|
|
69
|
+
std::vector<Piece> pieces;
|
|
70
|
+
std::vector<Piece> old = pieces_;
|
|
71
|
+
size_t next = 0; // The first old piece not handled yet
|
|
72
|
+
size_t position = 0; // The end of the current text copied so far
|
|
73
|
+
|
|
74
|
+
for (const auto& [span, replacement] : groups) {
|
|
75
|
+
// An empty piece (a deletion) counts as touched when it lies at the group's edge, so it merges into the group
|
|
76
|
+
auto end_of = [&](size_t i) { return starts[i] + old[i].size; };
|
|
77
|
+
auto before = [&](size_t i) { return old[i].size > 0 ? end_of(i) <= span.begin : starts[i] < span.begin; };
|
|
78
|
+
auto touched = [&](size_t i) {
|
|
79
|
+
return old[i].size > 0 ? starts[i] < span.end && span.begin < end_of(i) :
|
|
80
|
+
span.begin <= starts[i] && starts[i] <= span.end;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// 2.1. The pieces before the group stay as they are
|
|
84
|
+
while (next < old.size() && before(next)) {
|
|
85
|
+
pieces.push_back(old[next++]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 2.2. The original span behind the group: from its first touched piece to its last one.
|
|
89
|
+
// An insertion between pieces touches none, and has an empty original span.
|
|
90
|
+
size_t original_begin = next < old.size() ? old[next].original.begin : original_size_;
|
|
91
|
+
size_t original_end = original_begin;
|
|
92
|
+
if (next < old.size() && touched(next)) {
|
|
93
|
+
// A copied piece starting before the group keeps its head: "I have 2 cats" -> "I have " stays copied
|
|
94
|
+
if (!old[next].replaced && starts[next] < span.begin) {
|
|
95
|
+
size_t cut = span.begin - starts[next];
|
|
96
|
+
pieces.push_back({.original = {original_begin, original_begin + cut}, .size = cut});
|
|
97
|
+
original_begin += cut;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
size_t last = next;
|
|
101
|
+
while (next < old.size() && touched(next)) {
|
|
102
|
+
last = next++;
|
|
103
|
+
}
|
|
104
|
+
original_end = old[last].original.end;
|
|
105
|
+
|
|
106
|
+
// A copied piece ending after the group keeps its tail as an old piece: the next group may cut it again
|
|
107
|
+
if (!old[last].replaced && end_of(last) > span.end) {
|
|
108
|
+
size_t cut = span.end - starts[last];
|
|
109
|
+
original_end = old[last].original.begin + cut;
|
|
110
|
+
old[last].original.begin += cut;
|
|
111
|
+
old[last].size -= cut;
|
|
112
|
+
starts[last] = span.end;
|
|
113
|
+
next = last;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 2.3. The text up to the group, then the group's replacement as one replaced piece
|
|
118
|
+
text.append(text_, position, span.begin - position);
|
|
119
|
+
text.append(replacement);
|
|
120
|
+
pieces.push_back({.original = {original_begin, original_end}, .size = replacement.size(), .replaced = true});
|
|
121
|
+
position = span.end;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 3. The rest of the text after the last group, and its pieces
|
|
125
|
+
text.append(text_, position);
|
|
126
|
+
pieces.insert(pieces.end(), old.begin() + next, old.end());
|
|
127
|
+
|
|
128
|
+
text_ = std::move(text);
|
|
129
|
+
pieces_ = std::move(pieces);
|
|
130
|
+
edits_.clear();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
std::vector<Document::Edit> Document::changes() const {
|
|
134
|
+
std::vector<Edit> changes;
|
|
135
|
+
|
|
136
|
+
// Walk the pieces with their position in the current text; only the replaced ones are changes
|
|
137
|
+
size_t position = 0;
|
|
138
|
+
bool previous_replaced = false;
|
|
139
|
+
for (const auto& piece : pieces_) {
|
|
140
|
+
if (piece.replaced) {
|
|
141
|
+
// Adjacent replaced pieces form a single change
|
|
142
|
+
if (previous_replaced) {
|
|
143
|
+
changes.back().span.end = piece.original.end;
|
|
144
|
+
changes.back().text.append(text_, position, piece.size);
|
|
145
|
+
} else {
|
|
146
|
+
changes.push_back({piece.original, text_.substr(position, piece.size)});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
previous_replaced = piece.replaced;
|
|
150
|
+
position += piece.size;
|
|
151
|
+
}
|
|
152
|
+
return changes;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
Span Document::widen(Span span, std::span<const size_t> starts) const {
|
|
156
|
+
// An edge falling strictly inside a replaced piece moves to that piece's edge
|
|
157
|
+
for (size_t i = 0; i < pieces_.size(); ++i) {
|
|
158
|
+
size_t begin = starts[i], end = begin + pieces_[i].size;
|
|
159
|
+
if (!pieces_[i].replaced) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (begin < span.begin && span.begin < end) {
|
|
163
|
+
span.begin = begin;
|
|
164
|
+
}
|
|
165
|
+
if (begin < span.end && span.end < end) {
|
|
166
|
+
span.end = end;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return span;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.h"
|
|
4
|
+
|
|
5
|
+
#include <span>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <string_view>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace phonemis::processor {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The text being preprocessed, with lazy edits.
|
|
14
|
+
*
|
|
15
|
+
* Provides an abstraction which allows algorithms like Num2Word patterns operate freely, without
|
|
16
|
+
* risking that some previous edit affects the future one or the algorithm.
|
|
17
|
+
*/
|
|
18
|
+
class Document {
|
|
19
|
+
public:
|
|
20
|
+
// A span of a text, with the text in its place.
|
|
21
|
+
struct Edit {
|
|
22
|
+
Span span;
|
|
23
|
+
std::u32string text;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// A piece of the current text: a copy of a span of the original text, or the text which replaced it.
|
|
27
|
+
// A replaced piece maps to its original span only as a whole.
|
|
28
|
+
struct Piece {
|
|
29
|
+
Span original;
|
|
30
|
+
size_t size = 0; // In the current text
|
|
31
|
+
bool replaced = false;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
explicit Document(std::u32string_view text);
|
|
35
|
+
|
|
36
|
+
std::u32string_view text() const { return text_; }
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Queues a replacement of a span of the current text.
|
|
40
|
+
* @param span a range of the text as it was when the current layer started.
|
|
41
|
+
* @param replacement the new content of that range.
|
|
42
|
+
* @throws std::invalid_argument if the span is out of range or overlaps an already queued edit.
|
|
43
|
+
*/
|
|
44
|
+
void replace(Span span, std::u32string replacement);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Applies all queued edits at once.
|
|
48
|
+
*/
|
|
49
|
+
void commit();
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The committed changes of the original text, in order: each replaced span of the original text with
|
|
53
|
+
* the current text in its place.
|
|
54
|
+
*/
|
|
55
|
+
std::vector<Edit> changes() const;
|
|
56
|
+
|
|
57
|
+
private:
|
|
58
|
+
// The span of the current text an edit really changes: widened to whole replaced pieces it touches.
|
|
59
|
+
Span widen(Span span, std::span<const size_t> starts) const;
|
|
60
|
+
|
|
61
|
+
std::u32string text_;
|
|
62
|
+
std::vector<Edit> edits_; // Sorted by position
|
|
63
|
+
std::vector<Piece> pieces_;
|
|
64
|
+
size_t original_size_;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#include "text.h"
|
|
2
|
+
#include <phonemis/utils/strings.h>
|
|
3
|
+
#include <phonemis/utils/unicode.h>
|
|
4
|
+
|
|
5
|
+
#include <algorithm>
|
|
6
|
+
|
|
7
|
+
namespace phonemis::processor {
|
|
8
|
+
|
|
9
|
+
using namespace utils;
|
|
10
|
+
|
|
11
|
+
bool is_clear_before(std::u32string_view text, size_t position, std::u32string_view also) {
|
|
12
|
+
return position == 0 || (!unicode::isword(text[position - 1]) && !strings::contains(also, text[position - 1]));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
bool is_clear_after(std::u32string_view text, size_t position, std::u32string_view also) {
|
|
16
|
+
return position >= text.size() || (!unicode::isword(text[position]) && !strings::contains(also, text[position]));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
bool is_digit_after(std::u32string_view text, size_t position, std::u32string_view marks) {
|
|
20
|
+
if (position < text.size() && strings::contains(marks, text[position])) {
|
|
21
|
+
position++;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return position < text.size() && unicode::isdigit(text[position]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
bool is_sentence_end(std::u32string_view text, size_t position, bool capital) {
|
|
28
|
+
while (position < text.size() && unicode::isspace(text[position])) {
|
|
29
|
+
position++;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return position == text.size() || (capital && unicode::isupper(text[position]));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
size_t digits_end(std::u32string_view text, size_t position) {
|
|
36
|
+
while (position < text.size() && unicode::isdigit(text[position])) {
|
|
37
|
+
position++;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return position;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
size_t skip_space(std::u32string_view text, size_t position) {
|
|
44
|
+
return position < text.size() && unicode::isspace(text[position]) ? position + 1 : position;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
std::vector<std::u32string_view> keys_at(std::u32string_view text, size_t position, const Keys& keys) {
|
|
48
|
+
std::vector<std::u32string_view> found;
|
|
49
|
+
for (const auto& key : keys) {
|
|
50
|
+
if (text.substr(position).starts_with(key)) {
|
|
51
|
+
found.push_back(key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
std::ranges::sort(found, [](auto a, auto b) { return a.size() > b.size(); });
|
|
56
|
+
|
|
57
|
+
return found;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
std::u32string join(std::span<const std::u32string> words, std::u32string_view separator) {
|
|
61
|
+
std::u32string result;
|
|
62
|
+
for (const auto& word : words) {
|
|
63
|
+
if (word.empty()) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!result.empty()) {
|
|
67
|
+
result += separator;
|
|
68
|
+
}
|
|
69
|
+
result += word;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "types.h"
|
|
4
|
+
|
|
5
|
+
#include <span>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <string_view>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Scanning primitives shared by the layers: lookarounds and table keys at a position of a text.
|
|
12
|
+
* Character classes come from utils/unicode.h.
|
|
13
|
+
*/
|
|
14
|
+
namespace phonemis::processor {
|
|
15
|
+
|
|
16
|
+
// -----------------------
|
|
17
|
+
// ----- Lookarounds -----
|
|
18
|
+
// -----------------------
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a position starts a word: no word character stands right before it.
|
|
22
|
+
* @param also other characters which may not stand there, e.g. "." to reject the "g" of "e.g".
|
|
23
|
+
*/
|
|
24
|
+
bool is_clear_before(std::u32string_view text, size_t position, std::u32string_view also = U"");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a position ends a word: no word character stands at it, or the text ends there.
|
|
28
|
+
* @param also other characters which may not stand there.
|
|
29
|
+
*/
|
|
30
|
+
bool is_clear_after(std::u32string_view text, size_t position, std::u32string_view also = U"");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a digit stands at a position, possibly after one of given marks: "5", ".5".
|
|
34
|
+
* @param marks characters which may stand between the position and the digit.
|
|
35
|
+
*/
|
|
36
|
+
bool is_digit_after(std::u32string_view text, size_t position, std::u32string_view marks = U"");
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a sentence ends at a position: only whitespaces follow it.
|
|
40
|
+
* @param capital whether a capital letter after the whitespaces also starts a new sentence: "2020 r. Potem".
|
|
41
|
+
*/
|
|
42
|
+
bool is_sentence_end(std::u32string_view text, size_t position, bool capital = false);
|
|
43
|
+
|
|
44
|
+
// ---------------------------
|
|
45
|
+
// ----- Runs and keys -----
|
|
46
|
+
// ---------------------------
|
|
47
|
+
|
|
48
|
+
// End of the run of digits starting at a position.
|
|
49
|
+
size_t digits_end(std::u32string_view text, size_t position);
|
|
50
|
+
|
|
51
|
+
// Position after an optional whitespace.
|
|
52
|
+
size_t skip_space(std::u32string_view text, size_t position);
|
|
53
|
+
|
|
54
|
+
// The keys starting at a position, longest first.
|
|
55
|
+
std::vector<std::u32string_view> keys_at(std::u32string_view text, size_t position, const Keys& keys);
|
|
56
|
+
|
|
57
|
+
// The non-empty words, joined with a separator.
|
|
58
|
+
std::u32string join(std::span<const std::u32string> words, std::u32string_view separator = U" ");
|
|
59
|
+
|
|
60
|
+
} // namespace phonemis::processor
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace phonemis::processor {
|
|
8
|
+
|
|
9
|
+
// A half-open range [begin, end) of characters in a document's text.
|
|
10
|
+
struct Span {
|
|
11
|
+
size_t begin = 0;
|
|
12
|
+
size_t end = 0;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// Keys of a table matched in text (units, currencies, abbreviations); the longest matching one wins.
|
|
16
|
+
using Keys = std::vector<std::u32string>;
|
|
17
|
+
|
|
18
|
+
} // namespace phonemis::processor
|