Acme.Jieba.NET
1.0.0
dotnet add package Acme.Jieba.NET --version 1.0.0
NuGet\Install-Package Acme.Jieba.NET -Version 1.0.0
<PackageReference Include="Acme.Jieba.NET" Version="1.0.0" />
<PackageVersion Include="Acme.Jieba.NET" Version="1.0.0" />
<PackageReference Include="Acme.Jieba.NET" />
paket add Acme.Jieba.NET --version 1.0.0
#r "nuget: Acme.Jieba.NET, 1.0.0"
#:package Acme.Jieba.NET@1.0.0
#addin nuget:?package=Acme.Jieba.NET&version=1.0.0
#tool nuget:?package=Acme.Jieba.NET&version=1.0.0
Acme.Jieba.NET
A C# / .NET port of "Jieba" (结巴) Chinese word segmentation.
The dictionary and HMM probabilities come straight from fxsjy/jieba,
so output matches Python jieba word-for-word.
Compatible with netstandard2.0 (.NET 5–10 and later, .NET Framework 4.6.1+, Mono).
Features
- Three cutting modes:
- Accurate — the most precise segmentation (default).
- Full — scans every possible word, fast but ambiguous.
- Search — finer granularity tuned for search-engine indexing.
- HMM new-word discovery (Viterbi) for out-of-vocabulary words.
- POS tagging (
PosSegmenter) — part-of-speech flags liken,v,ns. - Keyword extraction — TF-IDF and TextRank (
TfidfExtractor,TextRankExtractor). - Tokenize with start/end character offsets.
- User dictionaries: load files, add / delete words at runtime with a custom weight.
- Self-contained: the dictionary and models are embedded (gzip-compressed) in the assembly — no extra data files to ship.
Install
dotnet add package Acme.Jieba.NET
Quick start
using Acme.Jieba;
var seg = JiebaSegmenter.Default; // shared, lazily-initialized instance
// Full mode
string.Join("/", seg.Cut("我来到北京清华大学", cutAll: true));
// 我/来到/北京/清华/清华大学/华大/大学
// Accurate mode (default)
string.Join("/", seg.Cut("我来到北京清华大学"));
// 我/来到/北京/清华大学
// Accurate mode with HMM (recovers unknown words)
string.Join("/", seg.Cut("他来到了网易杭研大厦"));
// 他/来到/了/网易/杭研/大厦
// Search-engine mode
string.Join("/", seg.CutForSearch("小明硕士毕业于中国科学院计算所"));
// 小明/硕士/毕业/于/中国/科学/学院/科学院/中国科学院/计算/计算所
Tokenize with offsets
foreach (var t in seg.Tokenize("永和服装饰品有限公司"))
Console.WriteLine($"{t.Word}\t[{t.Start}, {t.End}]");
// 永和 [0, 2]
// 服装 [2, 4]
// 饰品 [4, 6]
// 有限公司 [6, 10]
Adding words at runtime
// Auto-suggested weight so the word will be cut out:
seg.Add("石墨烯");
// Or give an explicit priority (frequency/weight) — higher = more likely whole:
seg.Add("台中", 69091);
// Force a word to be split back into characters:
seg.DelWord("中将");
// Load a whole user dictionary file ("word [freq] [tag]" per line, utf-8):
seg.LoadUserDict("userdict.txt");
Add(word, priority)is a convenience alias forAddWord(word, freq).
POS tagging
using Acme.Jieba.Posseg;
var pos = PosSegmenter.Default;
foreach (var w in pos.Cut("我爱北京天安门"))
Console.Write($"{w.Word}/{w.Flag} ");
// 我/r 爱/v 北京/ns 天安门/ns
Keyword extraction
using Acme.Jieba.Analyse;
var text = "此外,公司拟对全资子公司吉林欧亚置业有限公司增资4.3亿元……";
// Reuse the extractor — its constructor loads the IDF table once.
var tfidf = new TfidfExtractor();
tfidf.ExtractTags(text, topK: 5); // 欧亚, 增资, 吉林, 置业, 4.3
tfidf.ExtractTagsWithWeight(text, topK: 5); // returns (word, weight) pairs
tfidf.ExtractTags(text, 10, allowPos: new[] { "ns", "n", "vn", "nr" }); // keep only these POS
new TextRankExtractor().TextRank(text, topK: 5); // 欧亚, 吉林, 置业, 增资, 子公司
Custom stop words / IDF:
tfidf.SetStopWords(path),tfidf.SetIdfPath(path).
Parallel segmentation
Same behavior as Python jieba's enable_parallel: flip the switch and Cut /
CutForSearch transparently split their input by lines and segment it across CPU
cores. Output is unchanged, just faster on large multi-line input.
seg.EnableParallel(); // or EnableParallel(4) to cap worker threads
seg.Cut(bigMultiLineText); // now runs in parallel, same result
seg.DisableParallel();
Or call it explicitly without the global switch:
var words = seg.CutInParallel(bigMultiLineText);
var search = seg.CutForSearchInParallel(bigMultiLineText);
Read-only segmentation is thread-safe; don't mutate the dictionary
(AddWord / LoadUserDict) during a parallel cut.
API surface
| Member | Description |
|---|---|
JiebaSegmenter.Default |
Process-wide shared segmenter using the built-in dictionary. |
Cut(text, cutAll, hmm) |
Lazily yields words. |
CutToList(...) |
Same as Cut but returns a List<string>. |
CutForSearch(text, hmm) / CutForSearchToList(...) |
Search-engine granularity. |
EnableParallel(processNum) / DisableParallel() |
Toggle: make Cut / CutForSearch parallel (jieba's enable_parallel). |
CutInParallel(...) / CutForSearchInParallel(...) |
Explicit line-parallel segmentation (no global switch). |
Tokenize(text, search, hmm) |
Yields JiebaToken { Word, Start, End }. |
Add(word) / Add(word, priority, tag) |
Add a word at runtime. |
AddWord(...) / DelWord(word) |
Lower-level add / delete. |
LoadUserDict(path | TextReader) |
Bulk-load a user dictionary. |
SuggestFreq(word) / SuggestFreq(segments) |
Suggest a weight to join or split. |
PosSegmenter.Cut(text, hmm) |
POS-tagged words (JiebaWord { Word, Flag }). |
TfidfExtractor.ExtractTags(...) / ExtractTagsWithWeight(...) |
TF-IDF keywords. |
TextRankExtractor.TextRank(...) / TextRankWithWeight(...) |
TextRank keywords. |
You can also create independent instances with new JiebaSegmenter() (each keeps
its own mutable dictionary).
Not supported
- Paddle mode (
use_paddle) is not ported.
Building from source
dotnet build -c Release
dotnet test
dotnet run --project samples/Acme.Jieba.Demo
| 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
- No dependencies.
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.0.0 | 222 | 6/30/2026 |