Comparison of Chinese word segmentation of Lucene

For several Chinese analyzers, the accuracy and efficiency of word segmentation are compared. The analyzers are: StandardAnalyzer, ChineseAnalyzer, CJKAnalyzer, IK_CAnalyzer, MIK_CAnalyzer, MMAnalyzer (JE word segmentation), PaodingAnalyzer.
The implementation of simple Chinese word segmentation is generally indexed by word or indexed by word. Word-by-word indexing, as the name suggests, is to create an index by a single word. Indexing by word is by word, and according to the words in the thesaurus, the text is segmented. Chedong's cross-word segmentation or binary word segmentation, I think it should be regarded as an improvement by word index, and it should still belong to the category of word index.
It is difficult to evaluate the accuracy of word segmentation, it is difficult to have a unified standard, and the requirements of different applications are also different. Solemnly held." As an example.
For word segmentation efficiency, the full text of "The Legend of the Condor Heroes" is uniformly used as an example to illustrate. Ha ha. For the word-indexed analyzer, using the unified base thesaurus, the vocabulary size is 227,719. Running in a development environment, performance is not accurate, but relative values ​​can be compared.

 

 

Analyzer:


by word

StandardAnalyzer

Standard analyzers that come with Lucene.

 

ChineseAnalyzer

Analyzer included in Lucene contrib, similar to StandardAnalyzer. Note that they are similar, but there are differences.

 

CJKAnalyzer

Binary participles that come with Lucene contrib

by word

IK_CAnalyzer、MIK_CAnalyzer

http://lucene-group.group.javaeye.com/group/blog/165287 . Use version 2.0.2

 

MMAnalyzer

The latest version I can find now is 1.5.3. However, the download has not been found on the original website, and it is said that it is declared that it does not provide maintenance and support. Because there are more people talking about it, it is listed here. But it doesn't feel very stable in use.

 

PaodingAnalyzer

Paoding Jie Niu. http://code.google.com/p/paoding/downloads/list . The version used is 2.0.4beta.

 

   Word segmentation accuracy:


StandardAnalyzer

2008/year/8/month/8/day/evening/ju/world/eyes/eyes/of/Beijing/Second/Ten/Ninth/Session/Olympic/Lin/Pg/G/Sport/Sport/ meeting / opening / curtain / ceremony / in / country / home / sports / sports / field / grand / solemn / held / line /

Unary participle, nothing to say.

ChineseAnalyzer

Year/month/day/evening/movement/world/watching/eyes/day/Beijing/Beijing/Second/Ten/Ninth/Session/Olympic/Lin/P/G/Sport/Sport/Meet/Open/Curtain/ formula / in / country / home / sports / sports / field / grand / solemn / held / row /

There is still a difference, because ChineseAnalyzer only processes Character.LOWERCASE_LETTER, Character.UPPERCASE_LETTER, and Character.OTHER_LETTER, and filters out other types. See the code for details.

CJKAnalyzer

2008/year/8/month/8/day evening/world/world attention/attention/purpose/the North/Beijing/Beijing/Second/Twenty/Nineteen/Ninth/Olympic/Olympic/Limpi /Peak/Kyun/sports/sports meeting/opening/opening/closing ceremony/ceremony in/in country/country/family/sports/stadium/field long/grand/heavylift/held/

Binary word segmentation, as an improvement of unary word segmentation, the established index is smaller than unary, and the query efficiency is better, which can meet the general query requirements.

PaodingAnalyzer

2008/year/8/month/8/day/evening/world-wide attention/world-wide attention/purpose/Beijing/2/2/10/20/20/9/19/29/9 /Olympic/Olympic/sports/sports/Olympic Games/opening/opening/country/sports/stadium/grand/held/grandly held/

Fine-grained full segmentation. Binary tokenization for words that are not in the dictionary.

IK_CAnalyzer

2008年/2008/年/8月/8/月/8日/8/晚/举世瞩目/举世/瞩目/目的/北京/第二十九届/第二十九/第二十/第二/二十九/二十 /十九/九届/九/奥林匹克运动会/奥林匹克/奥林/运动会/运动/开幕式/开幕/在国/国家/国/体育场/体育/隆重举行/隆重/举行/行/

细粒度全切分。对于不在词典中的词进行二元分词。

MIK_CAnalyzer

2008年/8月/8日/晚/举世瞩目/目的/北京/第二十九届/奥林匹克运动会/开幕式/在国/国家/体育场/隆重举行/

最大匹配分词。和细粒度全切分配合使用。

MMAnalyzer

2008/年/8/月/8/日/晚/举世瞩目/北京/第二十/九届/奥林匹克运动会/开幕式/国家/体育场/隆重举行/

对于不在字典项的内容,进行一元分词。

 

 

分词性能(毫秒):

分析器

第一次

第二次

第三次

分词数

StandardAnalyzer

243

246

241

767675

ChineseAnalyzer

245

233

242

766298

CJKAnalyzer

383

383

373

659264

PaodingAnalyzer

927

899

909

482890

IK_CAnalyzer

1842

1877

1855

530830

MIK_CAnalyzer

2009

1978

1998

371013

MMAnalyzer

2923

2933

2948

392521

需要说明的是,IK_CAnalyzer在性能上对于词典的敏感度较高。
总结:
对于一般性的应用,采用二元分词法应该就可以满足需求。如果需要分词的话,从分词效果、性能、扩展性、还是可维护性来综合考虑,建议使用庖丁解牛。

 

 

mmseg4j 多分词模式与 paoding 分词效果对比

发表于:2009年4月12日 | 分类: mmseg4j | 标签:  mmseg4jpaoding中文分词 | views(6,709)

版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原文出处, 即下面的声明.

 

原文出处:http://blog.chenlb.com/2009/04/mmseg4j-max-word-segment-compare-with-paoding-in-effect.html

mmseg4j 1.6支持最多分词,应网友的要求:分词效果与 paoding 对比下。观察了 paoding 部分分词结果,现总结下。

paoding 分词效果:

  1. -------------------------- 
  2. 清华大学 
  3. 清华 | 大 | 华大 | 大学 | 
  4. -------------------------- 
  5. 华南理工大学 
  6. 华南 | 理工 | 大 | 大学 | 
  7. -------------------------- 
  8. 广东工业大学 
  9. 广东 | 工业 | 大 | 业大 | 大学 | 
  10. -------------------------- 
  11. 西伯利亚 
  12. 西伯 | 伯利 | 西伯利亚 | 
  13. -------------------------- 
  14. 研究生命起源 
  15. 研究 | 研究生 | 生命 | 起源 | 
  16. -------------------------- 
  17. 为首要考虑 
  18. 为首 | 首要 | 考虑 | 
  19. -------------------------- 
  20. 化装和服装 
  21. 化装 | 和服 | 服装 | 
  22. -------------------------- 
  23. 中国人民银行 
  24. 中国 | 国人 | 人民 | 银行 | 
  25. -------------------------- 
  26. 中华人民共和国 
  27. 中华 | 华人 | 人民 | 共和 | 共和国 | 
  28. -------------------------- 
  29. 羽毛球拍 
  30. 羽毛 | 羽毛球 | 球拍 | 
  31. -------------------------- 
  32. 人民币 
  33. 人民 | 人民币 | 
  34. -------------------------- 
  35. 很好听 
  36. 很好 | 好听 | 
  37. -------------------------- 
  38. 下一个 
  39. 下一 | 一个 | 
  40. -------------------------- 
  41. 为什么 
  42. 为什么 | 
  43. -------------------------- 
  44. 北京首都机场 
  45. 北京 | 首都 | 机场 | 
  46. -------------------------- 
  47. 东西已经拍卖了 
  48. 东西 | 已经 | 拍卖 | 卖了 | 
  49. -------------------------- 
  50. 主人因之生气 
  51. 主人 | 生气 | 
  52. -------------------------- 
  53. 虽然某些动物很凶恶 
  54. 动物 | 凶恶 | 
  55. -------------------------- 
  56. 朋友真背叛了你了 
  57. 朋友 | 真 | 背叛 | 
  58. -------------------------- 
  59. 建设盒蟹社会 
  60. 建设 | 盒蟹 | 社会 | 
  61. -------------------------- 
  62. 建设盒少蟹社会 
  63. 建设 | 盒少 | 少蟹 | 社会 | 
  64. -------------------------- 
  65. 我们家门前的大水沟很难过。 
  66. 我们 | 家门 | 前 | 门前 | 前的 | 大 | 大水 | 水沟 | 很难 | 难过 | 
  67. -------------------------- 
  68. 罐头不如果汁营养丰富。 
  69. 罐头 | 不如 | 如果 | 果汁 | 营养 | 丰富 | 
  70. -------------------------- 
  71. 今天真热,是游泳的好日子。 
  72. 今天 | 天真 | 热 | 游泳 | 日子 | 好日子 | 
  73. -------------------------- 
  74. 妹妹的数学只考十分,真丢脸。 
  75. 妹妹 | 数学 | 只考 | 十分 | 真 | 丢脸 | 
  76. -------------------------- 
  77. 我做事情,都是先从容易的做起。 
  78. 做事 | 事情 | 都是 | 先从 | 从容 | 容易 | 容易的 | 做起 | 
  79. -------------------------- 
  80. 老师说明天每个人参加大队接力时,一定要尽力。 
  81. 老师 | 师说 | 说明 | 明天 | 每个 | 个人 | 人参 | 参加 | 大 | 加大 | 大队 | 接力 | 时 | 一定 | 定要 | 要尽 | 尽力 | 
  82. -------------------------- 
  83. 小明把大便当作每天早上起床第一件要做的事 
  84. 小明 | 大 | 大便 | 便当 | 当作 | 每天 | 早上 | 上起 | 起床 | 床第 | 第一 | 一件 | 要做 | 做的 | 的事 |  

mmseg4j maxword 分词效果:

  1. -------------------------- 
  2. 清华大学 
  3. 清华 | 大学 | 
  4. -------------------------- 
  5. 华南理工大学 
  6. 华南 | 理工 | 工大 | 大学 | 
  7. -------------------------- 
  8. 广东工业大学 
  9. 广东 | 工业 | 大学 | 
  10. -------------------------- 
  11. 西伯利亚 
  12. 西 | 伯利 | 利亚 | 
  13. -------------------------- 
  14. 研究生命起源 
  15. 研究 | 生命 | 起源 | 
  16. -------------------------- 
  17. 为首要考虑 
  18. 为首 | 要 | 考虑 | 
  19. -------------------------- 
  20. 化装和服装 
  21. 化装 | 和 | 服装 | 
  22. -------------------------- 
  23. 中国人民银行 
  24. 中国 | 国人 | 人民 | 银行 | 
  25. -------------------------- 
  26. 中华人民共和国 
  27. 中华 | 华人 | 人民 | 共和 | 国 | 
  28. -------------------------- 
  29. 羽毛球拍 
  30. 羽毛 | 球拍 | 
  31. -------------------------- 
  32. 人民币 
  33. 人民 | 币 | 
  34. -------------------------- 
  35. 很好听 
  36. 很好 | 好听 | 
  37. -------------------------- 
  38. 下一个 
  39. 下一 | 一个 | 
  40. -------------------------- 
  41. 为什么 
  42. 为 | 什么 | 
  43. -------------------------- 
  44. 北京首都机场 
  45. 北京 | 首都 | 机场 | 
  46. -------------------------- 
  47. 东西已经拍卖了 
  48. 东西 | 已经 | 拍卖 | 了 | 
  49. -------------------------- 
  50. 主人因之生气 
  51. 主人 | 因 | 之 | 生气 | 
  52. -------------------------- 
  53. 虽然某些动物很凶恶 
  54. 虽然 | 某些 | 动物 | 很 | 凶恶 | 
  55. -------------------------- 
  56. 朋友真背叛了你了 
  57. 朋友 | 真 | 背叛 | 了 | 你了 | 
  58. -------------------------- 
  59. 建设盒蟹社会 
  60. 建设 | 盒 | 蟹 | 社会 | 
  61. -------------------------- 
  62. 建设盒少蟹社会 
  63. 建设 | 盒 | 少 | 蟹 | 社会 | 
  64. -------------------------- 
  65. 我们家门前的大水沟很难过。 
  66. 我们 | 家 | 门前 | 的 | 大水 | 水沟 | 很难 | 过 | 
  67. -------------------------- 
  68. 罐头不如果汁营养丰富。 
  69. 罐头 | 不如 | 果汁 | 营养 | 丰富 | 
  70. -------------------------- 
  71. 今天真热,是游泳的好日子。 
  72. 今天 | 天真 | 热 | 是 | 游泳 | 的 | 好 | 日子 | 
  73. -------------------------- 
  74. 妹妹的数学只考十分,真丢脸。 
  75. 妹妹 | 的 | 数学 | 只 | 考 | 十分 | 真 | 丢脸 | 
  76. -------------------------- 
  77. 我做事情,都是先从容易的做起。 
  78. 我做 | 事情 | 都是 | 先 | 从容 | 易 | 的 | 做起 | 
  79. -------------------------- 
  80. 老师说明天每个人参加大队接力时,一定要尽力。 
  81. 老师 | 师说 | 明天 | 每个 | 个人 | 参加 | 大队 | 接力 | 时 | 一定 | 要 | 尽力 | 
  82. -------------------------- 
  83. 小明把大便当作每天早上起床第一件要做的事 
  84. 小明 | 把 | 大便 | 当作 | 每天 | 早上 | 起床 | 第一 | 一件 | 要做 | 的 | 事 |  

paoding 几乎把所有的子词都拆出来,有时候还有最长的词,还没搞懂“华南理工大学”会分出“大”;mmseg4j 的 maxword  是在  complex分词后的结果再把子词都拆出来(1.6版按二元,不是词的去掉或保存单字。下一版本可能方式有点不同,“为什么”不应该为“为|什么”,也 即是三个字的前后不是词的应该不分,有待研究,:))。

如“化装和服装” mmseg4j 的 complex是可以较好的分出来(“化装 | 和 | 服装”),而 paoding  少了字频的信息,比较难到这事。mmseg4j complex 也有个缺点:“都是先从容易的做起” 不能把“容易”分出来,这是因为 mmseg  算法是用 3 个chunk的原因,我认为把整句的 chunk  (还是仅仅3个chunk)来处理的话,分词效果要好),当然要更多的开销,选3个可能是效果与性能平衡吧。

mmseg4j 没有加任何 stopword,这东西留给使用者自己加,因为我不认为加 stopword 是好的方法。如音乐搜索,给加上 the,this……,还能找到歌曲?

当然分词效果还与词库有关,sogou 的词库是统计得出,有些高频的单字组合也成了词,如“我们的”。如果还要提高 mmseg4j 的分词效果,还要在整理下词库。

 

 

作者:唐福林 来源:福林雨 博客   酷勤网收集 2009-08-04

 

1. 基本介绍:

paoding :Lucene中文分词“庖丁解牛” Paoding Analysis
imdict :imdict智能词典所采用的智能中文分词程序
mmseg4j : 用 Chih-Hao Tsai 的 MMSeg 算法 实现的中文分词器
ik :采用了特有的“正向迭代最细粒度切分算法“,多子处理器分析模式

2. 开发者及开发活跃度:

paoding :qieqie.wang, google code 上最后一次代码提交:2008-06-12,svn 版本号 132
imdict :XiaoPingGao, 进入了 lucene contribute,lucene trunk 中 contrib/analyzers/smartcn/ 最后一次提交:2009-07-24,
mmseg4j :chenlb2008,google code 中 2009-08-03 (昨天),版本号 57,log为:mmseg4j-1.7 创建分支
ik :linliangyi2005,google code 中 2009-07-31,版本号 41

3. 用户自定义词库:

paoding :支持不限制个数的用户自定义词库,纯文本格式,一行一词,使用后台线程检测词库的更新,自动编译更新过的词库到二进制版本,并加载
imdict :暂时不支持用户自定义词库。但 原版 ICTCLAS 支持。支持用户自定义 stop words
mmseg4j :自带sogou词库,支持名为 wordsxxx.dic, utf8文本格式的用户自定义词库,一行一词。不支持自动检测。 -Dmmseg.dic.path
ik : 支持api级的用户词库加载,和配置级的词库文件指定,无 BOM 的 UTF-8 编码,/r/n 分割。不支持自动检测。

4. 速度(基于官方介绍,非自己测试)

paoding :在PIII 1G内存个人机器上,1秒 可准确分词 100万 汉字
imdict :483.64 (字节/秒),259517(汉字/秒)
mmseg4j : complex 1200kb/s左右, simple 1900kb/s左右
ik :具有50万字/秒的高速处理能力

5. 算法和代码复杂度

paoding :svn src 目录一共1.3M,6个properties文件,48个java文件,6895 行。使用不用的 Knife 切不同类型的流,不算很复杂。
imdict :词库 6.7M(这个词库是必须的),src 目录 152k,20个java文件,2399行。使用 ICTCLAS HHMM隐马尔科夫模型,“利用大量语料库的训练来统计汉语词汇的词频和跳转概率,从而根据这些统计结果对整个汉语句子计算最似然(likelihood)的切分”
mmseg4j : svn src 目录一共 132k,23个java文件,2089行。MMSeg 算法 ,有点复杂。
ik : svn src 目录一共6.6M(词典文件也在里面),22个java文件,4217行。多子处理器分析,跟paoding类似,歧义分析算法还没有弄明白。

6. 文档

paoding :几乎无。代码里有一些注释,但因为实现比较复杂,读代码还是有一些难度的。
imdict : 几乎无。 ICTCLAS 也没有详细的文档,HHMM隐马尔科夫模型的数学性太强,不太好理解。
mmseg4j : MMSeg 算法 是英文的,但原理比较简单。实现也比较清晰。
ik : 有一个pdf使用手册,里面有使用示例和配置说明。

7. 其它

paoding :引入隐喻,设计比较合理。search 1.0 版本就用的这个。主要优势在于原生支持词库更新检测。主要劣势为作者已经不更新甚至不维护了。
imdict :进入了 lucene trunk,原版 ictclas 在各种评测中都有不错的表现,有坚实的理论基础,不是个人山寨。缺点为暂时不支持用户词库。
mmseg4j : 在complex基础上实现了最多分词(max-word),但是还不成熟,还有很多需要改进的地方。
ik :  针对Lucene全文检索优化的查询分析器IKQueryParser

8. 结论

个人觉得,可以在 mmseg4j 和 paoding 中选一个。关于这两个分词效果的对比,可以参考:

http://blog.chenlb.com/2009/04/mmseg4j-max-word-segment-compare-with-paoding-in-effect.html

或者自己再包装一下,将 paoding 的词库更新检测做一个单独的模块实现,然后就可以在所有基于词库的分词算法之间无缝切换了。

ps,对不同的 field 使用不同的分词器是一个可以考虑的方法。比如 tag 字段,就应该使用一个最简单的分词器,按空格分词就可以了。

本文来自:http://blog.fulin.org/2009/08/lucene_chinese_analyzer_compare.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326880325&siteId=291194637