rvmã§å ¥ããårubyã«mecab rubyãã¤ã³ãã£ã³ã°ãã¤ã³ã¹ãã¼ã«ãã
mecab rubyãã¤ã³ãã£ã³ã°ã¯gemã§ã¤ã³ã¹ãã¼ã«ã§ããªãã®ã§ãrvmã§å
¥ããåãã¼ã¸ã§ã³ã®rubyããmecabã使ãã®ã¯å°ãé¢åã
ä»ã¾ã§portã§å
¥ããrubyãããportã®rb-mecabã使ã£ã¦ããã©ãrvmã§$GEM_HOMEãåãæ¿ããã¨portã§å
¥ããrubyãã¤ã³ãã£ã³ã°ãèªããªãã®ã§ãåå¥ã«å
¥ãã
portã§mecabã®ææ°ç0.9.8ãå ¥ãã¦ãã
sudo port install mecab +utf8only which mecab mecab -v
ã¡ããã¨0.98ã«ãªã£ã¦ã
mecabã®rubyãã¤ã³ãã£ã³ã°å
¥ããã
http://sourceforge.net/projects/mecab/files/ ããmecab-ruby-0.98ããã¦ã³ãã¼ããã
tar -zxvf mecab-ruby-0.98.tar cd mecab-ruby-0.98 use rvm 1.9.2 ruby -v ruby exconf.rb
ãã§
make
g++ -I. -I/Users/sho/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/i386-darwin9.8.0 -I/Users/sho/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/Users/sho/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -DHAVE_MECAB_H -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -I/opt/local/include -o MeCab_wrap.o -c MeCab_wrap.cpp g++ -dynamic -bundle -o MeCab.bundle MeCab_wrap.o -L. -L/Users/sho/.rvm/rubies/ruby-1.9.2-p0/lib -L. -L/usr/local/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace -lruby.1.9.1 -lstdc++ -lmecab -lpthread -ldl -lobjc
make install
/opt/local/bin/ginstall -c -m 0755 MeCab.bundle /Users/sho/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
ã¡ããã¨rvmã®ä¸ã«å ¥ã£ã
åæ§ã«rvmã§å ¥ãã1.8.7ã®æ¹ã«ãå ¥ãã
cd ../ rm -rf mecab-ruby-0.98 tar -zxvf mecab-ruby-0.98.tar cd mecab-ruby-0.98 use rvm 1.8.7 ruby -v ruby exconf.rb make make install
åãã試ãã
mecab-split-terms.rb
#!/usr/bin/env ruby require 'MeCab' exit if ARGV.size < 1 puts str = ARGV.join(' ') node = MeCab::Tagger.new.parseToNode(str) while node do puts node.surface node = node.next end puts '*'*5 puts MeCab::Tagger.new.parse(str).split(/[\r\n]/).map{|i| i.split(/\t/).first}.delete_if{|i| i =~ /^EOS$/}
rvm use 1.8.7 ruby mecab-split-terms.rb BIG丼ã¯ãã°ã rvm use 1.9.2 ruby mecab-split-terms.rb BIG丼ã¯ãã°ã
ã©ã£ã¡ãåãæ§ã«splitã§ãã
1.9.2ã ã¨Array.to_sããæã«åå¾ã« [ 㨠] ãä»ãã®ã§ã¯ã¾ã£ã
ãã¨æ¹è¡åºåãã®Stringãmapã§è¡æ¯ã«å¦çã§ããªãã£ã