react-native-jieba 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/Jieba.podspec +30 -0
  2. package/LICENSE +20 -0
  3. package/README.md +103 -0
  4. package/android/CMakeLists.txt +29 -0
  5. package/android/build.gradle +60 -0
  6. package/android/generated/java/com/jieba/NativeJiebaAndroidHelperSpec.java +38 -0
  7. package/android/generated/java/com/jieba/NativeJiebaSpec.java +74 -0
  8. package/android/generated/jni/CMakeLists.txt +28 -0
  9. package/android/generated/jni/JiebaSpec-generated.cpp +98 -0
  10. package/android/generated/jni/JiebaSpec.h +39 -0
  11. package/android/generated/jni/react/renderer/components/JiebaSpec/JiebaSpecJSI.h +144 -0
  12. package/android/src/main/AndroidManifest.xml +2 -0
  13. package/android/src/main/java/com/jieba/JiebaAndroidHelperModule.kt +48 -0
  14. package/android/src/main/java/com/jieba/JiebaPackage.kt +32 -0
  15. package/cpp/JiebaImpl.cpp +154 -0
  16. package/cpp/JiebaImpl.h +37 -0
  17. package/cpp/cppjieba/LICENSE +20 -0
  18. package/cpp/cppjieba/deps/limonp/LICENSE +20 -0
  19. package/cpp/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
  20. package/cpp/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
  21. package/cpp/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
  22. package/cpp/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
  23. package/cpp/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
  24. package/cpp/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
  25. package/cpp/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
  26. package/cpp/cppjieba/deps/limonp/include/limonp/Logging.hpp +92 -0
  27. package/cpp/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
  28. package/cpp/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
  29. package/cpp/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
  30. package/cpp/cppjieba/dict/hmm_model.utf8 +34 -0
  31. package/cpp/cppjieba/dict/idf.utf8 +258826 -0
  32. package/cpp/cppjieba/dict/jieba.dict.utf8 +348982 -0
  33. package/cpp/cppjieba/dict/stop_words.utf8 +1534 -0
  34. package/cpp/cppjieba/dict/user.dict.utf8 +3 -0
  35. package/cpp/cppjieba/include/cppjieba/DictTrie.hpp +322 -0
  36. package/cpp/cppjieba/include/cppjieba/FullSegment.hpp +94 -0
  37. package/cpp/cppjieba/include/cppjieba/HMMModel.hpp +131 -0
  38. package/cpp/cppjieba/include/cppjieba/HMMSegment.hpp +211 -0
  39. package/cpp/cppjieba/include/cppjieba/Jieba.hpp +169 -0
  40. package/cpp/cppjieba/include/cppjieba/KeywordExtractor.hpp +152 -0
  41. package/cpp/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
  42. package/cpp/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
  43. package/cpp/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
  44. package/cpp/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
  45. package/cpp/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
  46. package/cpp/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
  47. package/cpp/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
  48. package/cpp/cppjieba/include/cppjieba/TextRankExtractor.hpp +192 -0
  49. package/cpp/cppjieba/include/cppjieba/Trie.hpp +200 -0
  50. package/cpp/cppjieba/include/cppjieba/Unicode.hpp +231 -0
  51. package/cpp/cppjieba/include/cppjieba/UnicodeFile.hpp +68 -0
  52. package/ios/OnLoad.mm +35 -0
  53. package/ios/generated/ReactCodegen/JiebaSpec/JiebaSpec-generated.mm +126 -0
  54. package/ios/generated/ReactCodegen/JiebaSpec/JiebaSpec.h +103 -0
  55. package/ios/generated/ReactCodegen/JiebaSpecJSI.h +144 -0
  56. package/lib/module/NativeJieba.js +5 -0
  57. package/lib/module/NativeJieba.js.map +1 -0
  58. package/lib/module/NativeJiebaAndroidHelper.js +5 -0
  59. package/lib/module/NativeJiebaAndroidHelper.js.map +1 -0
  60. package/lib/module/index.js +5 -0
  61. package/lib/module/index.js.map +1 -0
  62. package/lib/module/init.js +24 -0
  63. package/lib/module/init.js.map +1 -0
  64. package/lib/module/jieba.js +31 -0
  65. package/lib/module/jieba.js.map +1 -0
  66. package/lib/module/package.json +1 -0
  67. package/lib/typescript/package.json +1 -0
  68. package/lib/typescript/src/NativeJieba.d.ts +22 -0
  69. package/lib/typescript/src/NativeJieba.d.ts.map +1 -0
  70. package/lib/typescript/src/NativeJiebaAndroidHelper.d.ts +7 -0
  71. package/lib/typescript/src/NativeJiebaAndroidHelper.d.ts.map +1 -0
  72. package/lib/typescript/src/index.d.ts +4 -0
  73. package/lib/typescript/src/index.d.ts.map +1 -0
  74. package/lib/typescript/src/init.d.ts +2 -0
  75. package/lib/typescript/src/init.d.ts.map +1 -0
  76. package/lib/typescript/src/jieba.d.ts +18 -0
  77. package/lib/typescript/src/jieba.d.ts.map +1 -0
  78. package/package.json +197 -0
  79. package/react-native.config.js +17 -0
  80. package/src/NativeJieba.ts +19 -0
  81. package/src/NativeJiebaAndroidHelper.ts +7 -0
  82. package/src/index.tsx +13 -0
  83. package/src/init.ts +25 -0
  84. package/src/jieba.ts +43 -0
package/Jieba.podspec ADDED
@@ -0,0 +1,30 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "Jieba"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/leonsilicon/react-native-jieba.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm}", "cpp/*.{hpp,cpp,c,h}", "ios/generated/*.{h,cpp,mm}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+ s.resources = ["cpp/cppjieba/dict/*.utf8"]
20
+
21
+ s.pod_target_xcconfig = {
22
+ "HEADER_SEARCH_PATHS" => [
23
+ "\"$(PODS_TARGET_SRCROOT)/cpp/cppjieba/include\"",
24
+ "\"$(PODS_TARGET_SRCROOT)/cpp/cppjieba/deps/limonp/include\"",
25
+ ].join(" "),
26
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
27
+ }
28
+
29
+ install_modules_dependencies(s)
30
+ end
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leon Si
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # react-native-jieba
2
+
3
+ Native Chinese text segmentation for React Native, powered by [cppjieba](https://github.com/yanyiwu/cppjieba).
4
+
5
+ - Runs on the New Architecture as a C++ Turbo Module — no bridge overhead, no JS port of jieba.
6
+ - Ships the cppjieba dictionaries (`jieba.dict.utf8`, `hmm_model.utf8`, `idf.utf8`, `stop_words.utf8`, `user.dict.utf8`) inside the package, bundled as iOS pod resources and Android assets.
7
+ - Supports the standard jieba modes: precise (`cut`), full (`cutAll`), search engine (`cutForSearch`), HMM (`cutHMM`), small-word (`cutSmall`), POS tagging (`tag`), and TF-IDF keyword extraction (`extract`).
8
+
9
+ ## Requirements
10
+
11
+ - React Native **0.85+** with the New Architecture enabled.
12
+ - iOS 15.1+, Android `minSdkVersion` 24+.
13
+ - C++20 toolchain (default on recent Xcode and Android NDK 26+).
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ npm install react-native-jieba
19
+ # or
20
+ yarn add react-native-jieba
21
+ ```
22
+
23
+ iOS:
24
+
25
+ ```sh
26
+ cd ios && pod install
27
+ ```
28
+
29
+ Android: no extra steps — autolinking picks up the AAR.
30
+
31
+ ## Usage
32
+
33
+ Call `initJieba()` once before the first segmentation call. On iOS the dictionary path is resolved from the app bundle automatically; on Android it extracts the bundled assets to `filesDir/jieba-dict/` on first run.
34
+
35
+ ```ts
36
+ import {
37
+ initJieba,
38
+ cut,
39
+ cutAll,
40
+ cutForSearch,
41
+ tag,
42
+ extract,
43
+ } from 'react-native-jieba';
44
+
45
+ await initJieba();
46
+
47
+ cut('我来到北京清华大学');
48
+ // ['我', '来到', '北京', '清华大学']
49
+
50
+ cutAll('我来到北京清华大学');
51
+ // ['我', '来到', '北京', '清华', '清华大学', '华大', '大学']
52
+
53
+ cutForSearch('小明硕士毕业于中国科学院计算所');
54
+ // ['小明', '硕士', '毕业', '于', '中国', '科学', '学院', '科学院', '中国科学院', '计算', '计算所']
55
+
56
+ tag('我爱北京天安门');
57
+ // [{ word: '我', tag: 'r' }, { word: '爱', tag: 'v' }, ...]
58
+
59
+ extract('我是拖拉机学院手扶拖拉机专业的。', 5);
60
+ // [{ word: '手扶拖拉机', weight: 10.01 }, ...]
61
+ ```
62
+
63
+ ## API
64
+
65
+ All segmentation calls are synchronous JSI calls — no Promises.
66
+
67
+ | Function | Signature | Notes |
68
+ | --- | --- | --- |
69
+ | `initJieba()` | `() => Promise<void>` | Must be awaited once before any other call. Idempotent. |
70
+ | `cut(sentence, hmm?)` | `(string, boolean) => string[]` | Precise mode. `hmm` defaults to `true`. |
71
+ | `cutAll(sentence)` | `(string) => string[]` | Full mode (every possible word). |
72
+ | `cutForSearch(sentence, hmm?)` | `(string, boolean) => string[]` | Search-engine mode. |
73
+ | `cutHMM(sentence)` | `(string) => string[]` | HMM-only segmentation. |
74
+ | `cutSmall(sentence, maxWordLen)` | `(string, number) => string[]` | Limits the maximum word length. |
75
+ | `tag(sentence)` | `(string) => Array<{ word, tag }>` | Part-of-speech tagging. |
76
+ | `extract(sentence, topK?)` | `(string, number) => Array<{ word, weight }>` | TF-IDF keyword extraction. `topK` defaults to `5`. |
77
+ | `insertUserWord(word, tag?)` | `(string, string) => boolean` | Adds a user dictionary word at runtime. |
78
+ | `find(word)` | `(string) => boolean` | Tests whether a word is in the dictionary. |
79
+
80
+ ## How it works
81
+
82
+ - The Turbo Module lives in `cpp/JiebaImpl.{h,cpp}` and wraps `cppjieba::Jieba` as a JSI Cxx module.
83
+ - iOS resolves the dictionary directory from `NSBundle` in `ios/OnLoad.mm` before the module is registered, so `initJieba()` is a no-op on iOS.
84
+ - Android ships the dictionary as AAR assets and extracts them on demand via `JiebaAndroidHelperModule`, which then hands the path to the C++ module via the codegen-exposed `setDictPath` JSI method.
85
+ - cppjieba and its `limonp` dependency are vendored as git submodules under `cpp/cppjieba/`. The published npm tarball contains only the headers and dictionaries that are actually needed at build time.
86
+
87
+ ## Contributing
88
+
89
+ This repository uses git submodules. Clone with:
90
+
91
+ ```sh
92
+ git clone --recursive https://github.com/leonsilicon/react-native-jieba.git
93
+ # or after a plain clone:
94
+ git submodule update --init --recursive
95
+ ```
96
+
97
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
98
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
99
+ - [Code of conduct](CODE_OF_CONDUCT.md)
100
+
101
+ ## License
102
+
103
+ `react-native-jieba` is MIT-licensed. The bundled [cppjieba](https://github.com/yanyiwu/cppjieba) and [limonp](https://github.com/yanyiwu/limonp) projects are MIT-licensed; their respective `LICENSE` files are included inside `cpp/cppjieba/` and `cpp/cppjieba/deps/limonp/`.
@@ -0,0 +1,29 @@
1
+ cmake_minimum_required(VERSION 3.4.1)
2
+ project(Jieba)
3
+
4
+ set (CMAKE_VERBOSE_MAKEFILE ON)
5
+
6
+ add_library(
7
+ react-native-jieba STATIC
8
+ ../cpp/JiebaImpl.cpp
9
+ )
10
+
11
+ set_target_properties(
12
+ react-native-jieba PROPERTIES
13
+ CXX_STANDARD 20
14
+ CXX_STANDARD_REQUIRED ON
15
+ CXX_EXTENSIONS OFF
16
+ )
17
+
18
+ target_include_directories(
19
+ react-native-jieba PUBLIC
20
+ ../cpp
21
+ ../cpp/cppjieba/include
22
+ ../cpp/cppjieba/deps/limonp/include
23
+ )
24
+
25
+ target_link_libraries(
26
+ react-native-jieba jsi
27
+ reactnative
28
+ react_codegen_JiebaSpec
29
+ )
@@ -0,0 +1,60 @@
1
+ buildscript {
2
+ ext.safeExtGet = { prop, fallback ->
3
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4
+ }
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+ dependencies {
10
+ classpath "com.android.tools.build:gradle:8.7.2"
11
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24"
12
+ }
13
+ }
14
+
15
+ apply plugin: 'com.android.library'
16
+ apply plugin: 'org.jetbrains.kotlin.android'
17
+ apply plugin: 'com.facebook.react'
18
+
19
+ android {
20
+ namespace 'com.jieba'
21
+ compileSdk safeExtGet('compileSdkVersion', 35)
22
+ ndkVersion safeExtGet('ndkVersion', '27.1.12297006')
23
+
24
+ defaultConfig {
25
+ minSdk safeExtGet('minSdkVersion', 24)
26
+ targetSdk safeExtGet('targetSdkVersion', 35)
27
+ externalNativeBuild {
28
+ cmake {
29
+ cppFlags "-std=c++20"
30
+ arguments "-DANDROID_STL=c++_shared"
31
+ }
32
+ }
33
+ }
34
+
35
+ externalNativeBuild {
36
+ cmake {
37
+ path "CMakeLists.txt"
38
+ }
39
+ }
40
+
41
+ compileOptions {
42
+ sourceCompatibility JavaVersion.VERSION_17
43
+ targetCompatibility JavaVersion.VERSION_17
44
+ }
45
+
46
+ kotlinOptions {
47
+ jvmTarget = '17'
48
+ }
49
+
50
+ sourceSets {
51
+ main {
52
+ java.srcDirs += "generated/java"
53
+ assets.srcDirs += "$projectDir/../cpp/cppjieba/dict"
54
+ }
55
+ }
56
+ }
57
+
58
+ dependencies {
59
+ implementation 'com.facebook.react:react-android'
60
+ }
@@ -0,0 +1,38 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJavaSpec.js
9
+ *
10
+ * @nolint
11
+ */
12
+
13
+ package com.jieba;
14
+
15
+ import com.facebook.proguard.annotations.DoNotStrip;
16
+ import com.facebook.react.bridge.Promise;
17
+ import com.facebook.react.bridge.ReactApplicationContext;
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
+ import com.facebook.react.bridge.ReactMethod;
20
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule;
21
+ import javax.annotation.Nonnull;
22
+
23
+ public abstract class NativeJiebaAndroidHelperSpec extends ReactContextBaseJavaModule implements TurboModule {
24
+ public static final String NAME = "JiebaAndroidHelper";
25
+
26
+ public NativeJiebaAndroidHelperSpec(ReactApplicationContext reactContext) {
27
+ super(reactContext);
28
+ }
29
+
30
+ @Override
31
+ public @Nonnull String getName() {
32
+ return NAME;
33
+ }
34
+
35
+ @ReactMethod
36
+ @DoNotStrip
37
+ public abstract void prepareDictDir(Promise promise);
38
+ }
@@ -0,0 +1,74 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJavaSpec.js
9
+ *
10
+ * @nolint
11
+ */
12
+
13
+ package com.jieba;
14
+
15
+ import com.facebook.proguard.annotations.DoNotStrip;
16
+ import com.facebook.react.bridge.ReactApplicationContext;
17
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
18
+ import com.facebook.react.bridge.ReactMethod;
19
+ import com.facebook.react.bridge.WritableArray;
20
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule;
21
+ import javax.annotation.Nonnull;
22
+
23
+ public abstract class NativeJiebaSpec extends ReactContextBaseJavaModule implements TurboModule {
24
+ public static final String NAME = "Jieba";
25
+
26
+ public NativeJiebaSpec(ReactApplicationContext reactContext) {
27
+ super(reactContext);
28
+ }
29
+
30
+ @Override
31
+ public @Nonnull String getName() {
32
+ return NAME;
33
+ }
34
+
35
+ @ReactMethod
36
+ @DoNotStrip
37
+ public abstract void setDictPath(String path);
38
+
39
+ @ReactMethod(isBlockingSynchronousMethod = true)
40
+ @DoNotStrip
41
+ public abstract WritableArray cut(String sentence, boolean hmm);
42
+
43
+ @ReactMethod(isBlockingSynchronousMethod = true)
44
+ @DoNotStrip
45
+ public abstract WritableArray cutAll(String sentence);
46
+
47
+ @ReactMethod(isBlockingSynchronousMethod = true)
48
+ @DoNotStrip
49
+ public abstract WritableArray cutForSearch(String sentence, boolean hmm);
50
+
51
+ @ReactMethod(isBlockingSynchronousMethod = true)
52
+ @DoNotStrip
53
+ public abstract WritableArray cutHMM(String sentence);
54
+
55
+ @ReactMethod(isBlockingSynchronousMethod = true)
56
+ @DoNotStrip
57
+ public abstract WritableArray cutSmall(String sentence, double maxWordLen);
58
+
59
+ @ReactMethod(isBlockingSynchronousMethod = true)
60
+ @DoNotStrip
61
+ public abstract WritableArray tag(String sentence);
62
+
63
+ @ReactMethod(isBlockingSynchronousMethod = true)
64
+ @DoNotStrip
65
+ public abstract WritableArray extract(String sentence, double topK);
66
+
67
+ @ReactMethod(isBlockingSynchronousMethod = true)
68
+ @DoNotStrip
69
+ public abstract boolean insertUserWord(String word, String tag);
70
+
71
+ @ReactMethod(isBlockingSynchronousMethod = true)
72
+ @DoNotStrip
73
+ public abstract boolean find(String word);
74
+ }
@@ -0,0 +1,28 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ cmake_minimum_required(VERSION 3.13)
7
+ set(CMAKE_VERBOSE_MAKEFILE on)
8
+
9
+ file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/JiebaSpec/*.cpp)
10
+
11
+ add_library(
12
+ react_codegen_JiebaSpec
13
+ OBJECT
14
+ ${react_codegen_SRCS}
15
+ )
16
+
17
+ target_include_directories(react_codegen_JiebaSpec PUBLIC . react/renderer/components/JiebaSpec)
18
+
19
+ target_link_libraries(
20
+ react_codegen_JiebaSpec
21
+ fbjni
22
+ jsi
23
+ # We need to link different libraries based on whether we are building rncore or not, that's necessary
24
+ # because we want to break a circular dependency between react_codegen_rncore and reactnative
25
+ reactnative
26
+ )
27
+
28
+ target_compile_reactnative_options(react_codegen_JiebaSpec PRIVATE)
@@ -0,0 +1,98 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniCpp.js
9
+ */
10
+
11
+ #include "JiebaSpec.h"
12
+
13
+ namespace facebook::react {
14
+
15
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_setDictPath(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
16
+ static jmethodID cachedMethodId = nullptr;
17
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, VoidKind, "setDictPath", "(Ljava/lang/String;)V", args, count, cachedMethodId);
18
+ }
19
+
20
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_cut(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
21
+ static jmethodID cachedMethodId = nullptr;
22
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "cut", "(Ljava/lang/String;Z)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
23
+ }
24
+
25
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_cutAll(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
26
+ static jmethodID cachedMethodId = nullptr;
27
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "cutAll", "(Ljava/lang/String;)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
28
+ }
29
+
30
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_cutForSearch(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
31
+ static jmethodID cachedMethodId = nullptr;
32
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "cutForSearch", "(Ljava/lang/String;Z)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
33
+ }
34
+
35
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_cutHMM(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
36
+ static jmethodID cachedMethodId = nullptr;
37
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "cutHMM", "(Ljava/lang/String;)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
38
+ }
39
+
40
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_cutSmall(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
41
+ static jmethodID cachedMethodId = nullptr;
42
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "cutSmall", "(Ljava/lang/String;D)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
43
+ }
44
+
45
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_tag(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
46
+ static jmethodID cachedMethodId = nullptr;
47
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "tag", "(Ljava/lang/String;)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
48
+ }
49
+
50
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_extract(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
51
+ static jmethodID cachedMethodId = nullptr;
52
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, ArrayKind, "extract", "(Ljava/lang/String;D)Lcom/facebook/react/bridge/WritableArray;", args, count, cachedMethodId);
53
+ }
54
+
55
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_insertUserWord(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
56
+ static jmethodID cachedMethodId = nullptr;
57
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, BooleanKind, "insertUserWord", "(Ljava/lang/String;Ljava/lang/String;)Z", args, count, cachedMethodId);
58
+ }
59
+
60
+ static facebook::jsi::Value __hostFunction_NativeJiebaSpecJSI_find(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
61
+ static jmethodID cachedMethodId = nullptr;
62
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, BooleanKind, "find", "(Ljava/lang/String;)Z", args, count, cachedMethodId);
63
+ }
64
+
65
+ NativeJiebaSpecJSI::NativeJiebaSpecJSI(const JavaTurboModule::InitParams &params)
66
+ : JavaTurboModule(params) {
67
+ methodMap_["setDictPath"] = MethodMetadata {1, __hostFunction_NativeJiebaSpecJSI_setDictPath};
68
+ methodMap_["cut"] = MethodMetadata {2, __hostFunction_NativeJiebaSpecJSI_cut};
69
+ methodMap_["cutAll"] = MethodMetadata {1, __hostFunction_NativeJiebaSpecJSI_cutAll};
70
+ methodMap_["cutForSearch"] = MethodMetadata {2, __hostFunction_NativeJiebaSpecJSI_cutForSearch};
71
+ methodMap_["cutHMM"] = MethodMetadata {1, __hostFunction_NativeJiebaSpecJSI_cutHMM};
72
+ methodMap_["cutSmall"] = MethodMetadata {2, __hostFunction_NativeJiebaSpecJSI_cutSmall};
73
+ methodMap_["tag"] = MethodMetadata {1, __hostFunction_NativeJiebaSpecJSI_tag};
74
+ methodMap_["extract"] = MethodMetadata {2, __hostFunction_NativeJiebaSpecJSI_extract};
75
+ methodMap_["insertUserWord"] = MethodMetadata {2, __hostFunction_NativeJiebaSpecJSI_insertUserWord};
76
+ methodMap_["find"] = MethodMetadata {1, __hostFunction_NativeJiebaSpecJSI_find};
77
+ }
78
+ static facebook::jsi::Value __hostFunction_NativeJiebaAndroidHelperSpecJSI_prepareDictDir(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
79
+ static jmethodID cachedMethodId = nullptr;
80
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "prepareDictDir", "(Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
81
+ }
82
+
83
+ NativeJiebaAndroidHelperSpecJSI::NativeJiebaAndroidHelperSpecJSI(const JavaTurboModule::InitParams &params)
84
+ : JavaTurboModule(params) {
85
+ methodMap_["prepareDictDir"] = MethodMetadata {0, __hostFunction_NativeJiebaAndroidHelperSpecJSI_prepareDictDir};
86
+ }
87
+
88
+ std::shared_ptr<TurboModule> JiebaSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
89
+ if (moduleName == "Jieba") {
90
+ return std::make_shared<NativeJiebaSpecJSI>(params);
91
+ }
92
+ if (moduleName == "JiebaAndroidHelper") {
93
+ return std::make_shared<NativeJiebaAndroidHelperSpecJSI>(params);
94
+ }
95
+ return nullptr;
96
+ }
97
+
98
+ } // namespace facebook::react
@@ -0,0 +1,39 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <ReactCommon/JavaTurboModule.h>
14
+ #include <ReactCommon/TurboModule.h>
15
+ #include <jsi/jsi.h>
16
+
17
+ namespace facebook::react {
18
+
19
+ /**
20
+ * JNI C++ class for module 'NativeJieba'
21
+ */
22
+ class JSI_EXPORT NativeJiebaSpecJSI : public JavaTurboModule {
23
+ public:
24
+ NativeJiebaSpecJSI(const JavaTurboModule::InitParams &params);
25
+ };
26
+
27
+ /**
28
+ * JNI C++ class for module 'NativeJiebaAndroidHelper'
29
+ */
30
+ class JSI_EXPORT NativeJiebaAndroidHelperSpecJSI : public JavaTurboModule {
31
+ public:
32
+ NativeJiebaAndroidHelperSpecJSI(const JavaTurboModule::InitParams &params);
33
+ };
34
+
35
+
36
+ JSI_EXPORT
37
+ std::shared_ptr<TurboModule> JiebaSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
38
+
39
+ } // namespace facebook::react
@@ -0,0 +1,144 @@
1
+ /**
2
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
3
+ *
4
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
5
+ * once the code is regenerated.
6
+ *
7
+ * @generated by codegen project: GenerateModuleH.js
8
+ */
9
+
10
+ #pragma once
11
+
12
+ #include <ReactCommon/TurboModule.h>
13
+ #include <react/bridging/Bridging.h>
14
+
15
+ namespace facebook::react {
16
+
17
+
18
+ template <typename T>
19
+ class JSI_EXPORT NativeJiebaCxxSpec : public TurboModule {
20
+ public:
21
+ static constexpr std::string_view kModuleName = "Jieba";
22
+
23
+ protected:
24
+ NativeJiebaCxxSpec(std::shared_ptr<CallInvoker> jsInvoker) : TurboModule(std::string{NativeJiebaCxxSpec::kModuleName}, jsInvoker) {
25
+ methodMap_["setDictPath"] = MethodMetadata {.argCount = 1, .invoker = __setDictPath};
26
+ methodMap_["cut"] = MethodMetadata {.argCount = 2, .invoker = __cut};
27
+ methodMap_["cutAll"] = MethodMetadata {.argCount = 1, .invoker = __cutAll};
28
+ methodMap_["cutForSearch"] = MethodMetadata {.argCount = 2, .invoker = __cutForSearch};
29
+ methodMap_["cutHMM"] = MethodMetadata {.argCount = 1, .invoker = __cutHMM};
30
+ methodMap_["cutSmall"] = MethodMetadata {.argCount = 2, .invoker = __cutSmall};
31
+ methodMap_["tag"] = MethodMetadata {.argCount = 1, .invoker = __tag};
32
+ methodMap_["extract"] = MethodMetadata {.argCount = 2, .invoker = __extract};
33
+ methodMap_["insertUserWord"] = MethodMetadata {.argCount = 2, .invoker = __insertUserWord};
34
+ methodMap_["find"] = MethodMetadata {.argCount = 1, .invoker = __find};
35
+ }
36
+
37
+ private:
38
+ static jsi::Value __setDictPath(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
39
+ static_assert(
40
+ bridging::getParameterCount(&T::setDictPath) == 2,
41
+ "Expected setDictPath(...) to have 2 parameters");
42
+ bridging::callFromJs<void>(rt, &T::setDictPath, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
43
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt));return jsi::Value::undefined();
44
+ }
45
+
46
+ static jsi::Value __cut(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
47
+ static_assert(
48
+ bridging::getParameterCount(&T::cut) == 3,
49
+ "Expected cut(...) to have 3 parameters");
50
+ return bridging::callFromJs<jsi::Array>(rt, &T::cut, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
51
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
52
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asBool());
53
+ }
54
+
55
+ static jsi::Value __cutAll(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
56
+ static_assert(
57
+ bridging::getParameterCount(&T::cutAll) == 2,
58
+ "Expected cutAll(...) to have 2 parameters");
59
+ return bridging::callFromJs<jsi::Array>(rt, &T::cutAll, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
60
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt));
61
+ }
62
+
63
+ static jsi::Value __cutForSearch(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
64
+ static_assert(
65
+ bridging::getParameterCount(&T::cutForSearch) == 3,
66
+ "Expected cutForSearch(...) to have 3 parameters");
67
+ return bridging::callFromJs<jsi::Array>(rt, &T::cutForSearch, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
68
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
69
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asBool());
70
+ }
71
+
72
+ static jsi::Value __cutHMM(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
73
+ static_assert(
74
+ bridging::getParameterCount(&T::cutHMM) == 2,
75
+ "Expected cutHMM(...) to have 2 parameters");
76
+ return bridging::callFromJs<jsi::Array>(rt, &T::cutHMM, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
77
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt));
78
+ }
79
+
80
+ static jsi::Value __cutSmall(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
81
+ static_assert(
82
+ bridging::getParameterCount(&T::cutSmall) == 3,
83
+ "Expected cutSmall(...) to have 3 parameters");
84
+ return bridging::callFromJs<jsi::Array>(rt, &T::cutSmall, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
85
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
86
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asNumber());
87
+ }
88
+
89
+ static jsi::Value __tag(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
90
+ static_assert(
91
+ bridging::getParameterCount(&T::tag) == 2,
92
+ "Expected tag(...) to have 2 parameters");
93
+ return bridging::callFromJs<jsi::Array>(rt, &T::tag, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
94
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt));
95
+ }
96
+
97
+ static jsi::Value __extract(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
98
+ static_assert(
99
+ bridging::getParameterCount(&T::extract) == 3,
100
+ "Expected extract(...) to have 3 parameters");
101
+ return bridging::callFromJs<jsi::Array>(rt, &T::extract, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
102
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
103
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asNumber());
104
+ }
105
+
106
+ static jsi::Value __insertUserWord(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
107
+ static_assert(
108
+ bridging::getParameterCount(&T::insertUserWord) == 3,
109
+ "Expected insertUserWord(...) to have 3 parameters");
110
+ return bridging::callFromJs<bool>(rt, &T::insertUserWord, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
111
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
112
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt));
113
+ }
114
+
115
+ static jsi::Value __find(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
116
+ static_assert(
117
+ bridging::getParameterCount(&T::find) == 2,
118
+ "Expected find(...) to have 2 parameters");
119
+ return bridging::callFromJs<bool>(rt, &T::find, static_cast<NativeJiebaCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule),
120
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt));
121
+ }
122
+ };
123
+
124
+
125
+ template <typename T>
126
+ class JSI_EXPORT NativeJiebaAndroidHelperCxxSpec : public TurboModule {
127
+ public:
128
+ static constexpr std::string_view kModuleName = "JiebaAndroidHelper";
129
+
130
+ protected:
131
+ NativeJiebaAndroidHelperCxxSpec(std::shared_ptr<CallInvoker> jsInvoker) : TurboModule(std::string{NativeJiebaAndroidHelperCxxSpec::kModuleName}, jsInvoker) {
132
+ methodMap_["prepareDictDir"] = MethodMetadata {.argCount = 0, .invoker = __prepareDictDir};
133
+ }
134
+
135
+ private:
136
+ static jsi::Value __prepareDictDir(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* /*args*/, size_t /*count*/) {
137
+ static_assert(
138
+ bridging::getParameterCount(&T::prepareDictDir) == 1,
139
+ "Expected prepareDictDir(...) to have 1 parameters");
140
+ return bridging::callFromJs<jsi::Value>(rt, &T::prepareDictDir, static_cast<NativeJiebaAndroidHelperCxxSpec*>(&turboModule)->jsInvoker_, static_cast<T*>(&turboModule));
141
+ }
142
+ };
143
+
144
+ } // namespace facebook::react