OpenccJiebaLib 1.2.0
See the version list below for details.
dotnet add package OpenccJiebaLib --version 1.2.0
NuGet\Install-Package OpenccJiebaLib -Version 1.2.0
<PackageReference Include="OpenccJiebaLib" Version="1.2.0" />
<PackageVersion Include="OpenccJiebaLib" Version="1.2.0" />
<PackageReference Include="OpenccJiebaLib" />
paket add OpenccJiebaLib --version 1.2.0
#r "nuget: OpenccJiebaLib, 1.2.0"
#:package OpenccJiebaLib@1.2.0
#addin nuget:?package=OpenccJiebaLib&version=1.2.0
#tool nuget:?package=OpenccJiebaLib&version=1.2.0
OpenccJiebaLib
A .NET Standard 2.0 library providing a managed C# wrapper for the Rust-based OpenCC and Jieba C API, enabling efficient Chinese text conversion (Simplified/Traditional), segmentation, and keyword extraction in .NET applications.
Features
- Chinese Text Conversion: Convert between Simplified, Traditional, and other Chinese variants using OpenCC.
- Word Segmentation: Segment Chinese text into words using Jieba.
- Keyword Extraction: Extract keywords using TF-IDF or TextRank algorithms.
- Native Performance: Leverages native OpenCC/Jieba libraries for high performance.
Supported OpenCC Configurations
s2t, t2s, s2tw, tw2s, s2twp, tw2sp, s2hk, hk2s, t2tw,
t2twp, t2hk, tw2t, tw2tp, hk2t, t2jp, jp2t
Getting Started
Prerequisites
- .NET Standard 2.0 or higher (.NET Framework, .NET Core/5+/6+, Mono, Xamarin, etc.).
- .NET 6.0 or later recommended.
- Native
opencc_jieba_capilibrary (must be available to the runtime).
Installation
Option 1 — Project Reference
- Add a project reference to OpenccJiebaLib in your solution.
- Ensure the native binary is available at runtime in the standard layout:
runtimes/<RID>/native/
Expected filenames:
- Windows:
opencc_jieba_capi.dll - Linux:
libopencc_jieba_capi.so - macOS:
libopencc_jieba_capi.dylib
🧪 Unit tests (MSTest/xUnit/nUnit) also need the native binaries in the test project’s output folder. Use the same copy strategy (copy
runtimes/**intobin/…) or add an MSBuildTargetto auto-copy natives after build.
Option 2 — From NuGet
dotnet add package OpenccJiebaLib
- The NuGet package includes platform-specific native runtimes under:
runtimes/<RID>/native/
Shipped RIDs: win-x64, linux-arm64, linux-x64, osx-arm64
When publishing with
-r <RID>,dotnet publishcopies only the matching native runtime into the publishing output.
Custom native runtimes (drop-in)
OpenccJiebaLib loads the native library from the standard NuGet layout:
runtimes/<RID>/native/<library>
To add support for another platform, drop in your own native binary:
Create the directory:
runtimes/<RID>/native/Copy the native library using the expected filename:
- Windows:
opencc_jieba_capi.dll - Linux:
libopencc_jieba_capi.so - macOS:
libopencc_jieba_capi.dylib
Example (Intel macOS):
runtimes/osx-x64/native/libopencc_jieba_capi.dylib
The loader will pick it up automatically at runtime.
Usage
using OpenccJiebaLib;
using (var openccJieba = new OpenccJieba())
{
string traditional = openccJieba.Convert("汉字转换测试", "s2t");
string[] words = openccJieba.JiebaCut("我来到北京清华大学", hmm: true);
string[] keywords = openccJieba.JiebaKeywordExtractTfidf(
"这是一个用于关键词提取的测试文本", 5);
var (kw, weights) = openccJieba.JiebaExtractKeywordsWeights(
"这是一个用于关键词提取的测试文本", 5, "textrank");
}
Error Handling
If initialization fails or a native error occurs, an InvalidOperationException is thrown.
API Overview
Convert(string input, string config, bool punctuation = false)Convert(string input, OpenccConfig configId, bool punctuation = false)JiebaCut(string input, bool hmm)JiebaCutAndJoin(string input, bool hmm, string delimiter)JiebaKeywordExtractTfidf(string input, int topK)JiebaKeywordExtractTextRank(string input, int topK)JiebaExtractKeywordsWeights(string input, int topK, string method)
Troubleshooting
DllNotFoundException
- Ensure the native file exists under
runtimes/<RID>/native/. - If using NuGet, clean and rebuild the project.
BadImageFormatException
- Architecture mismatch (x86 vs x64).
Platform Notes
- Linux: may require
LD_LIBRARY_PATH. - macOS: remove Gatekeeper quarantine flags:
xattr -dr com.apple.quarantine libopencc_jieba_capi.dylib
License
MIT License. See LICENSE.
Acknowledgements
- OpenCC
- Jieba
- opencc-jieba-rs
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.2.0
- Extracted native interop codes into a dedicated native class
- Fixed ABI mismatch in C# P/Invoke by using UnmanagedType.I1 for Rust bool parameters
- Added OpenccConfig enum for conversion configuration
- Added Jieba CutForSearch/CutAll/Tag functions
- Added POS Tag in Jieba Keyword Extractions