jieba-kmp 1.0.0 indexed Chinese text segmentation offering precise, full and search modes, HMM‑assisted new-word detection, Traditional Chinese handling, customizable dictionaries, tokenization with offsets, and runtime dictionary tweaks.
Bring this to kpkg
This library is indexed from the KMP ecosystem and already resolves through kpkg.dev's Maven Central proxy. Maintainers can verify the namespace and publish future versions to kpkg for free hosting, real download stats, and signed-provenance pages.
Publishing coming soonMetadata
Owner ErolC
Stars 3
Used by —
Health —
License MIT License
Latest 1.0.0
Repository github.com/ErolC/jieba-kmp
Updated 2026-01-25 Readme Changelog jieba-kmp
jieba-kmp是jieba中文分词 的kotlin多平台版本
提供与jieba基本一致的功能与接口,但不支持其paddle模式。
特点
支持三种分词模式:
精确模式,试图将句子最精确地切开,适合文本分析;
全模式,把句子中所有的可以成词的词语都扫描出来, 速度非常快,但是不能解决歧义;
搜索引擎模式,在精确模式的基础上,对长词再次切分,提高召回率,适合用于搜索引擎分词。
支持繁体分词
支持自定义词典
MIT 授权协议
性能
以下性能表现根据不同硬件会有所不同,仅供参考
初始化
平台 35万词 35万词+缓存 50万词 50万词+缓存 设备 android 1.5秒
分词
长度 android 1200 160ms 6000 500ms
安装
api('cn.erolc.jieba:jieba-kmp:1.0.0' )
混淆规则
-keep class cn .erolc .jieba .model .FreqCache { *; }
使用
初始化
jiebaInit()
Jieba.init ()
android需要在application中进行初始化
分词
Jieba.cut方法接收两个参数:需要分词的字符串;模式;
Jieba.lcut方法接收与Jieba.cut一致的参数,cut返回值是flow,lcut返回值是list
Jieba.cutForSearch方法接受两个参数:需要分词的字符串;是否使用 HMM 模型。该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细
输出
调整词典
使用 addWord(word, freq=None, tag=None) 和 del_word(word) 可在程序中动态修改词典。
使用 suggestFreq(segment) 可调节单个词语的词频,使其能(或不能)被分出来。
注意:自动计算的词频在使用 HMM 新词发现功能时可能无效。
载入词典
开发者可以指定自己自定义的词典,以便包含 jieba 词库里没有的词。虽然 jieba 有新词识别能力,但是自行添加新词可以保证更高的正确率
用法: Jieba.init(diskHelper)
词典格式和 dict.txt 一样,一个词占一行;每一行分三部分:词语、词频(可省略)、词性(可省略),用空格隔开,顺序不可颠倒,则文件必须为
UTF-8 编码。
词频省略时使用自动计算的能保证分出该词的词频。
重新载入
当在使用过程中,修改了自定义词典,那么可以通过Jieba.reload()方法重新载入。
Jieba.tokenize方法接受三个参数:需要分词的字符串;模式;是否使用 HMM 模型。返回值会包含词的位置信息import kotlinx.coroutines.flow.fold
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import cn.erolc.jieba.Jieba
@Test
fun test () = runTest {
val seg_list = Jieba.cut("我来到北京清华大学" , Mode.Full)
val value = seg_list.fold("" ) { acc, value -> if (acc.isEmpty()) value else "$acc /${value} " }
println("Full mode: $value " )
val seg_list2 = Jieba.cut("我来到北京清华大学" , Mode.HMM)
val value1 = seg_list2.fold("" ) { acc, value -> if (acc.isEmpty()) value else "$acc /${value} " }
println("HMM mode: $value1 " )
val seg_list3 = Jieba.cut("他来到了网易杭研大厦" )
val value2 = seg_list3.fold("" ) { acc, value -> if (acc.isEmpty()) value else "$acc /${value} " }
println("新词识别: $value2 " )
val seg_list4 = Jieba.cutForSearch("小明硕士毕业于中国科学院计算所,后在日本京都大学深造" )
val value3 = seg_list4.fold("" ) { acc, value -> if (acc.isEmpty()) value else "$acc /${value} " }
println("Search mode: $value3 " )
Jieba.tokenize("永和服装饰品有限公司" ).collect { println(it) }
Jieba.tokenize("永和服装饰品有限公司" , "search" ).collect { println(it) }
}
cut(9):382.907833ms
Full mode: 我/来到/北京/清华/清华大学/华大/大学
cut(9):300.5us
HMM mode: 我/来到/北京/清华大学
cut(10):2.267ms
新词识别: 他/来到/了/网易/杭研/大厦 (此处,“杭研”并没有在词典中,但是也被Viterbi算法识别出来了)
cutForSearch(26):4.532458ms
Search mode: 小明/硕士/毕业/于/中国/科学/学院/科学院/中国科学院/计算/计算所/,/后/在/日本/京都/大学/日本京都大学/深造
//默认模式
SegToken(word =永和, startOff set=0 , endOff set=2 )
SegToken(word =服装, startOff set=2 , endOff set=4 )
SegToken(word =饰品, startOff set=4 , endOff set=6 )
SegToken(word =有限公司, startOff set=6 , endOff set=10 )
tokenize(10):1.907375ms
//搜索模式
SegToken(word =永和, startOff set=0 , endOff set=2 )
SegToken(word =服装, startOff set=2 , endOff set=4 )
SegToken(word =饰品, startOff set=4 , endOff set=6 )
SegToken(word =有限, startOff set=6 , endOff set=8 )
SegToken(word =公司, startOff set=8 , endOff set=10 )
SegToken(word =有限公司, startOff set=6 , endOff set=10 )
tokenize(10):856.959us
Related libraries Surfaced from shared tags and platforms — no rankings paid for.
Emoji.kt ★ 75
kosi-libs Display and parse emoji in strings, extract and list emoji, replace short-codes/emoticons; render using Noto images or animations with system-font fallback and customizable download handling. Shared: text, parsing commonmark-kotlin ★ 7
darriousliu Parses and renders CommonMark Markdown syntax, transforming Java files to Kotlin. Offers full CommonMark compliance, extensibility, type safety, and support for multiple platforms. Shared: text, parsing compose-markdown ★ 2
adamglin0 Incremental Markdown parser and renderer producing append-only streaming snapshots with stable block identity for Compose UIs; presets optimized for chat and streaming previews. Shared: text, parsing markdown ★ 941
JetBrains Extensible Markdown processor enabling consistent client and server-side document parsing, supporting various Markdown flavors, with capabilities for HTML generation and syntax highlighting, tailored for easy customization and extension. Shared: text, parsing crossword ★ 163
JakeWharton A 2D text canvas for rendering in console applications, handling multi-character codepoints and ANSI control sequences for colored text output without overwriting issues. Shared: text, parsing mp_stools ★ 55
sergeych Portable utilities: sprintf-style formatting with advanced flags, base64 (including URL-safe), fast Boyer–Moore byte search, ByteArray int ops, cached expressions, reentrant coroutine mutex, coroutine-based async logging. Shared: text, kotlin-flow