Gem 自制中文分词 gem

gyorou · March 02, 2014 · Last by gyorou replied at March 03, 2014 · 3636 hits

gem install cseg

使用之前须下载并安装 CRF++。(http://crfpp.googlecode.com/svn/trunk/doc/index.html

使用 MIRA 学习了大量的素性。

require 'cseg'

result=Kurumi.segment(str)

结果以数组保存。

precision

94.43%

recall

92.86%

tested on seghan 05 pku test set

源码是 https://github.com/lengshuiyulangcn/kurumi 么?

看来很靠谱的样子,不过有几点可以改进下:

  • 缩进推荐换成 2 空格而不是 tab
  • 每次分词都启动一次 crf++ 进程有点重... 如果能直接调用 crf++ api 就更好了
  • 读写 tempfile 不如直接用 pipe 啦:
result_data = IO.popen %w'crf_test -m pkumodle.data', 'r+' do |io|
  io.puts *str.chars
  io.close_write
  io.read
end

#1 楼 @luikore 多谢指点。马上去研究研究

You need to Sign in before reply, if you don't have an account, please Sign up first.