I developed rmmseg-cpp about half a month ago. After running in JavaEye, it is said the performance is good and the memory usage is stable. I'm very glad to see rmmseg-cpp be used in production.
Here's the 0.2.5 release of rmmseg-cpp. There aren't many feature changes. I just created a simple homepage at RubyForge, completed the API document and added the two examples from RMMSeg. The gem releases are now moved from GitHub to RubyForge, which means you can install rmmseg-cpp by a simpler command line now:
gem install rmmseg-cpp
And unlike GitHub, RubyForge also archived the old releases. Finally, here's the release note:
rmmseg-cpp version 0.2.5 by pluskid http://rmmseg-cpp.rubyforge.org== DESCRIPTION
rmmseg-cpp is a high performance Chinese word segmentation utility for Ruby. It features full "Ferret":http://ferret.davebalmain.com/ integration as well as support for normal Ruby program usage.
rmmseg-cpp is a re-written of the original RMMSeg(http://rmmseg.rubyforge.org/) gem in C++. RMMSeg is written in pure Ruby. Though I tried hard to tweak RMMSeg, it just consumes lots of memory and the segmenting process is rather slow.
The interface is almost identical to RMMSeg but the performance is much better. This gem is always preferable in production use. However, if you want to understand how the MMSEG segmenting algorithm works, the source code of RMMSeg is a better choice than this.
== CHANGES
* Created homepage on Rubyforge. * Gem can be installed directly from Rubyforge now. * Added rdoc for native extensions.
I wish you like it. :)
Comments (20)
:( 我的服务器也是windows,是不是rmmseg-cpp不支持windows呢?
@blogkid, 确实,目前 rmmseg-cpp 是不支持 Windows 的。本来想编译一个 win32 的 pre-built 的 gem 发布,但是我今天折腾了一上午也没有完全解决这个问题(编译好了加载似乎也有路径问题,而且不同版本的编译器编译出来的版本似乎不能直接在其他平台上使用)。最后还是暂时放弃了。
如果你想要自己编译试试的话,首先要有一个编译环境,例如 Visual Studio Express ,其次这篇文章可以参考一下。
我折腾折腾看
是啊,好像确实是这样的。其实我也只是实现了 MMSEG 这个算法,至于对于分词乃至于 IR 整个领域我还并不是特别熟悉,等我有所了解之后说不定会能有所改进。不过目前应该只能通过添加自定义词典的方式来解决这个问题了。 :)
在 OS X 下遇到兩個問題:
1. 在 require 'rmmseg' 時程式會沒有回應 2. 執行 rmmseg 也是沒有回應
在 0.2.4 時曾經成功過,但現在在三部 mac 下也不行
想試試更改 compile 的 options 的似乎不行...
einstein:rmmseg siuying$ pwd /opt/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.5/ext/rmmseg einstein:rmmseg siuying$ sudo nano -w extconf.rb einstein:rmmseg siuying$ sudo ruby extconf.rb creating Makefile einstein:rmmseg siuying$ sudo make make: Nothing to be done for `all'.
可能是我的方法不對?可否指教怎樣測試 build gems 呢
先
make clean再make试试。我身边没有 Mac 的电脑,没法进行测试,也不知道是怎么造成这种原因的,从 0.2.4 到 0.2.5 似乎没有怎么动过 native extension 的那部分代码。如果你弄好了也请告诉我一下解决方法。 :)謝謝,照你的方法可以 compile 了... 測試後發現只用dynamiclib 的 option 就行
請把 extconf.rb 的這句:
CONFIG['LDSHARED'] = 'g++ --dynamiclib -flat_namespace -undefined suppress'
改成這樣:
CONFIG['LDSHARED'] = 'g++ -dynamiclib '
結果: einstein:~ siuying$ rmmseg 照你的方法可以 compile 了 照 你的 方法 可以 compile 了
(ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin9.2.0] )
不過我在另一部電腦 (ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1] ) 又會遇上另一個問題:
/opt/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.5/lib/../ext/rmmseg/rmmseg.bundle: Failed to load /opt/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.5/lib/../ext/rmmseg/rmmseg.bundle (LoadError)
明晚會再試更新 ruby 看看
@小影, 多谢,不过不知道你在另一台 Mac 上碰到的问题是不是类似的,如果在另一台 Mac 上又需要原来的那个编译参数
就麻烦了。嗯,不过我在想这里也许应该使用和本地 Ruby 编译时同样的参数。只是原来使用 gcc ,而这里用了 C++ 要换成 g++ 罢了。所以我现在换了一种做法,把原来的那些根据平台判断的语句换成了一句:
我已经 push 到 github 上了,我在 Linux 下测试是没有问题的。也许你可以试一下这个方法,这样如果在不同的 Mac 下 Ruby 版本的编译参数不一样的话,应该也可以正常使用吧。
ps: 如果你用是 git 得到的代码的话,直接
rake gem:install就可以测试在本地编译并安装 gem 了。 :)嗯,这个确实没有做处理,如果要解析日期、数字之类的话,也许可以串接一个专门针对日期、数字之类格式的分词器,其实这些东西要处理需要考虑的问题好像还挺多的。
你好,请问如何对字符串做tokenizer?
token=RMMSeg::Ferret::Tokenizer.new(aStr)
当token.next时,报错
NoMethodError: undefined method `start' for token["Hello":0:5:1]:Ferret::Analysis::Token from /usr/local/lib/ruby/gems/1.8/gems/rmmseg-0.1.6/lib/rmmseg/algorithm.rb:33:in `next_token' from /usr/local/lib/ruby/gems/1.8/gems/rmmseg-0.1.6/lib/rmmseg/ferret.rb:42:in `next'请问你用的是哪个版本的 Ferret ? 难道 API 有变化了?现在 Ferret 的主页好像挂了,上不去。
我用的是ferret 0.9几的一个版本. ruby是1.8.4 rmmseg是通过 gem install rmmseg gem install rmmseg-cpp 安装 echo "hello world"|rmmseg可以执行
在ruby代码中运行时,除了上面提到的问题。还有以下问题
analyzer = RMMSeg::Ferret::Analyzer.new { |tokenizer| Ferret::Analysis::LowerCaseFilter.new(tokenizer) } @index = Index::Index.new(:path => '/mypath/',:analyzer =>analyzer)
会显示 (irb):11: [BUG] Segmentation fault ruby 1.8.4 (2005-12-24) [i686-linux]
然后退出irb....
不知道你用的ferret是哪个版本??我安装测试一下!谢谢!
btw.ferrt内部页面还可以访问,首页挂掉了。 http://ferret.davebalmain.com/api/files/TUTORIAL.html
把ferret安装到0.11以后,问题都解决了:)
谢谢pluskid
另外,建议requirement里注明ferrt需要的版本号。这样会更友好一些
好的,多谢提醒,不过我想请问一下你原本遇到的问题是因为 ferret 版本太新了还是太旧了?
我更新了一下主页,提了一下尽量使用最新版本,不过最近 Ferret 的主页好像上不去,我也不确定是否一定至少要 0.11 才行,所以就没有提具体的版本号。如果以后不能正常工作了,我应该会跟进升级的。 :)
# g++ -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.6 [FreeBSD] 20060305
# echo 'sdf0wefwrjwe' | rmmseg
/usr/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.7/lib/../ext/rmmseg/rmmseg.so: /usr/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.7/lib/../ext/rmmseg/rmmseg.so: Undefined symbol "__gxx_personality_v0" - /usr/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.7/lib/../ext/rmmseg/rmmseg.so (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.7/lib/rmmseg.rb:3
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/rmmseg-cpp-0.2.7/bin/rmmseg:4
from /usr/local/bin/rmmseg:19:in `load'
from /usr/local/bin/rmmseg:19
看上去似乎是应该用 g++ 链接的,但是却用了 gcc ,没有在 FreeBSD 下测试过。你在
ext/rmmseg/extconf.rb里写上:之类的试试?