OpenCCNET 0.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package OpenCCNET --version 0.2.0
NuGet\Install-Package OpenCCNET -Version 0.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenCCNET" Version="0.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenCCNET" Version="0.2.0" />
<PackageReference Include="OpenCCNET" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenCCNET --version 0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenCCNET, 0.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenCCNET@0.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenCCNET&version=0.2.0
#tool nuget:?package=OpenCCNET&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenCC.NET
介绍
OpenCC.NET是OpenCC(Open Chinese Convert, 开放中文转换)的C#非官方版本,支持中文简繁体之间词汇级别的转换,同时还支持地域间异体字以及词汇的转换。
特点
- 严格区分「一简对多繁」和「一简对多异」
- 完全兼容异体字,可以实现动态替换
- 严格审校一简对多繁词条,原则为「能分则不合」
- 支持港/台/陆异体字转换,以及大陆/台湾常用词汇转换
- 完全兼容OpenCC原生词库,且词库和函数库完全分离,可以自由修改、导入、扩展
- 基于.Net Standard 2.0,同时支持.NET Framework 4.6.1和.NET Core 2.0及以上版本
更新
支持转换到中国大陆繁体异体字标准,字典根据《通用规范汉字表》整理得到。
开始
获取
Nuget搜索OpenCCNET并安装,在项目代码中引入命名空间OpenCCNET。下载仓库中的Dictionary(字典文件)和JiebaResource(Jieba.NET运行所需的词典及其它数据文件)文件夹放入项目程序所在目录。
使用
在使用前请调用ZhUtil.Initialize()。OpenCC.NET提供了两种风格的API:
ZhConverter静态类
| 方法 | 简介 | 备注 |
|---|---|---|
| HansToHant(string) | 简体中文=>繁体中文(OpenCC标准) | |
| HansToTW(string, bool=false) | 简体中文=>繁体中文(台湾) | bool参数决定是否转换为台湾地区常用词汇 |
| HansToHK(string) | 简体中文=>繁体中文(香港) | |
| HansToCN(string) | 简体中文=>繁体中文(中国大陆) | |
| HantToHans(string) | 繁体中文=>简体中文 | |
| HantToTW(string, bool=false) | 繁体中文=>繁体中文(台湾) | bool参数决定是否转换为台湾地区常用词汇 |
| HantToHK(string) | 繁体中文=>繁体中文(香港) | |
| HantToCN(string, bool=false) | 繁体中文=>繁体中文(中国大陆) | bool参数决定是否转换为大陆地区常用词汇 |
| TWToHans(string, bool=false) | 繁体中文(台湾)=>简体中文 | bool参数决定是否转换为大陆地区常用词汇 |
| HKToHans(string) | 繁体中文(香港)=>简体中文 | |
| CNToHans(string) | 繁体中文(中国大陆)=>简体中文 |
var input = "为我的电脑换了内存,开启电脑后感觉网络速度更快了";
// 爲我的電腦換了內存,開啓電腦後感覺網絡速度更快了
Console.WriteLine(ZhConverter.HansToHant(input));
// 為我的電腦換了記憶體,開啟電腦後感覺網路速度更快了
Console.WriteLine(ZhConverter.HansToTW(input, true));
// 為我的電腦換了內存,開啓電腦後感覺網絡速度更快了
Console.WriteLine(ZhConverter.HansToHK(input));
string类扩展方法
| 方法 | 简介 | 备注 |
|---|---|---|
| ToHantFromHans() | 简体中文=>繁体中文(OpenCC标准) | |
| ToTWFromHans(bool=false) | 简体中文=>繁体中文(台湾) | bool参数决定是否转换为台湾地区常用词汇 |
| ToHKFromHans() | 简体中文=>繁体中文(香港) | |
| ToCNFromHans() | 简体中文=>繁体中文(中国大陆) | |
| ToHansFromHant() | 繁体中文=>简体中文 | |
| ToTWFromHant(bool=false) | 繁体中文=>繁体中文(台湾) | bool参数决定是否转换为台湾地区常用词汇 |
| ToHKFromHant() | 繁体中文=>繁体中文(香港) | |
| ToCNFromHant(bool=false) | 繁体中文=>繁体中文(中国大陆) | bool参数决定是否转换为大陆地区常用词汇 |
| ToHansFromTW(bool=false) | 繁体中文(台湾)=>简体中文 | bool参数决定是否转换为大陆地区常用词汇 |
| ToHansFromHK() | 繁体中文(香港)=>简体中文 | |
| ToHansFromCN() | 繁体中文(中国大陆)=>简体中文 |
var input = "為我的電腦換了記憶體,開啟電腦后感覺網路速度更快了";
// 爲我的電腦換了內存,開啓電腦后感覺網絡速度更快了
Console.WriteLine(input.ToHantFromTW(true));
// 为我的电脑换了记忆体,开启电脑后感觉网路速度更快了
Console.WriteLine(input.ToHansFromTW());
// 为我的电脑换了内存,开启电脑后感觉网络速度更快了
Console.WriteLine(input.ToHansFromTW(true));
自定义
分词
OpenCC.NET默认使用jieba.NET实现分词,项目中使用了静态的JiebaSegmenter
public static JiebaSegmenter Jieba = new JiebaSegmenter();
因此可以通过ZhUtil.Jieba进行自定义设置,详情请见jieba.NET。
同时OpenCC.NET支持自定义分词实现:
ZhUtil.Segment = input =>
{
// 输入为string,输出为IEnumerable<string>
return new List<string>();
};
调用ResetSegment()可重新指定使用Jieba分词并且重置Jieba参数
引用
OpenCC
OpenCC提供词库。
jieba.NET
jieba.NET提供分词。
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- jieba.NET (>= 0.42.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.0 | 6,662 | 11/15/2025 | |
| 1.0.3 | 5,080 | 3/21/2025 | |
| 1.0.2 | 169,947 | 5/5/2022 | |
| 1.0.1 | 701 | 4/26/2022 | |
| 1.0.0 | 674 | 4/25/2022 | |
| 0.2.2 | 665 | 1/18/2022 | |
| 0.2.1 | 757 | 1/18/2022 | |
| 0.2.0 | 832 | 12/3/2021 | |
| 0.1.4 | 505 | 11/29/2021 | |
| 0.1.3 | 467 | 11/23/2021 | |
| 0.1.2 | 466 | 11/23/2021 | |
| 0.1.1 | 1,258 | 6/10/2021 | |
| 0.1.0 | 560 | 6/10/2021 |