Rails4ã§nattoã使ããmecabã§å½¢æ ç´ è§£æãããæ¹æ³ï¼CentOS6ï¼
mecab ãã¤ã³ã¹ãã¼ã«
mecabãyumã§ã¤ã³ã¹ãã¼ã«
CentOS6ã§yumã使ã£ã¦mecabã¨mecabã®è¾æ¸ãã¡ã¤ã«ãã¤ã³ã¹ãã¼ã«ãããã¨ãã¦
以ä¸ã®ããã«yumãå®è¡ãããã¨ããã¨ããã±ã¼ã¸ããªãã¨æããã
> sudo yum install mecab mecab-ipadic No package mecab available. No package mecab-ipadic available.
æ®éã«RPMããã¦ã³ãã¼ããã¦ãããããæããã®ã§å¥ã®æ¹æ³ããç´¹ä»ãã
å ¨ææ¤ç´¢ã¨ã³ã¸ã³groongaã®ãªãã¸ããªã追å
> sudo rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-1.noarch.rpm
refs http://groonga.org/ja/docs/install/centos.html#centos-6
åã³ yumã§mecabæ¬ä½ã¨è¾æ¸ãã¡ã¤ã«mecab-ipadicãã¤ã³ã¹ãã¼ã«ã試ã¿ã
> yum install mecab mecab-ipadic // ãã¼ã¸ã§ã³ç¢ºèª > mecab --version mecab of 0.996
ç¡äºã¤ã³ã¹ãã¼ã«ã§ãã
mecabåä½ç¢ºèª
> mecab ããããã«ã¬ã¼ãé£ã¹ã«è¡ãã ãã å¯è©,ä¸è¬,*,*,*,*,ãã,ã¢ã¦,ã¢ã¼ ãã åè©,èªç«,*,*,äºæ®µã»ã©è¡,ä½è¨æ¥ç¶ç¹æ®,ãã,ã¤ã³,ã¤ã³ ã«ã¬ã¼ åè©,ä¸è¬,*,*,*,*,ã«ã¬ã¼,ã«ã¬ã¼,ã«ã¬ã¼ ã å©è©,æ ¼å©è©,ä¸è¬,*,*,*,ã,ã²,ã² é£ã¹ åè©,èªç«,*,*,ä¸æ®µ,é£ç¨å½¢,é£ã¹ã,ã¿ã,ã¿ã ã« å©è©,æ ¼å©è©,ä¸è¬,*,*,*,ã«,ã,ã è¡ã åè©,èªç«,*,*,äºæ®µã»ã«è¡ä¿é³ä¾¿,æªç¶ã¦æ¥ç¶,è¡ã,ã¤ã³,ã¤ã³ ã å©åè©,*,*,*,ä¸å¤åå,åºæ¬å½¢,ã,ã¦,㦠EOS
YES YES
Railsã¨mecabãã¤ãªã
railsããã¸ã§ã¯ããä½æ
æ°è¦ä½æ
// mysql ãå©ç¨ããå ´åã¯ã-d mysqlãã¤ãã > rails new PROJECT_NAME -d mysql
Railsããmecabãå©ç¨ã§ããããã«ãã
Gemfileãç·¨éããnattoãã¤ã³ã¹ãã¼ã«ãã
# CentOSã®å ´åã¯ãtherubyracer ãã³ã¡ã³ãã¢ã¦ããã gem 'therubyracer', platforms: :ruby # nattoã追å gem 'natto'
ããã§bundle installããã¨mecabã®ã©ã¤ãã©ãªãè¦ã¤ãããªãã¦ã¨ã©ã¼ã«ãªãå ´åãããã
> bundle exec rails c /home/vagrant/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/ffi-1.9.3/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'mecab': /usr/lib64/mecab: cannot read file data: Is a directory. (LoadError) Could not open library 'libmecab.so': libmecab.so: cannot open shared object file: No such file or directory
ç°å¢å¤æ°ã«mecabç¨ã®ãã¹ã追å ãã
mecabã®ã©ã¤ãã©ãªã®ããå ´æã調ã¹ã
> sudo find / -name libmecab.so* /usr/lib64/libmecab.so.2 /usr/lib64/libmecab.so.2.0.0 // /usr/lib64/libmecab.so.2ã¯ã·ã³ããªãã¯ãªã³ã¯ > ls -l /usr/lib64/libmecab.so.2 lrwxrwxrwx 1 root root 17 2æ 7 12:22 2014 /usr/lib64/libmecab.so.2 -> libmecab.so.2.0.0
調ã¹ãã©ã¤ãã©ãªãç°å¢å¤æ°ã«è¿½å ãã
> echo 'export MECAB_PATH=/usr/lib64/libmecab.so.2' >> ~/.bash_profile # bashè¨å®ã®åèªã¿è¾¼ã¿ > source ~/.bash_profile
åã³bundle install
> bundle install
nattoã®åä½ç¢ºèª
> bundle exec rails c nm = Natto::MeCab.new => #<Natto::MeCab:0x007f231d70f638 @tagger=#<FFI::Pointer address=0x007f231e7539b0>, @options={}, @dicts=[#<Natto::DictionaryInfo:0x007f231d70f110 type="0", filename="/usr/lib64/mecab/dic/ipadic/sys.dic", charset="utf8">], @version="0.996"> irb(main):007:0> puts nm.parse('åæµ·éã«å¸°ãããã®ã§ãªã¢ã¼ãã¯ã¼ã¯åºæ¥ãä¼ç¤¾æ±ã') åæµ·é åè©,åºæåè©,å°å,ä¸è¬,*,*,åæµ·é,ããã«ã¤ãã¦,ããã«ã¤ãã¼ ã« å©è©,æ ¼å©è©,ä¸è¬,*,*,*,ã«,ã,ã 帰ã åè©,èªç«,*,*,äºæ®µã»ã©è¡,é£ç¨å½¢,帰ã,ã«ã¨ãª,ã«ã¨ãª ãã å©åè©,*,*,*,ç¹æ®ã»ã¿ã¤,åºæ¬å½¢,ãã,ã¿ã¤,ã¿ã¤ ã®ã§ å©è©,æ¥ç¶å©è©,*,*,*,*,ã®ã§,ãã,ãã ãªã¢ã¼ã åè©,ä¸è¬,*,*,*,*,ãªã¢ã¼ã,ãªã¢ã¼ã,ãªã¢ã¼ã ã¯ã¼ã¯ åè©,ä¸è¬,*,*,*,*,ã¯ã¼ã¯,ã¯ã¼ã¯,ã¯ã¼ã¯ åºæ¥ã åè©,èªç«,*,*,ä¸æ®µ,åºæ¬å½¢,åºæ¥ã,ããã«,ããã« ä¼ç¤¾ åè©,ä¸è¬,*,*,*,*,ä¼ç¤¾,ã«ã¤ã·ã£,ã«ã¤ã·ã£ æ±ã åè©,èªç«,*,*,äºæ®µã»ãè¡,åºæ¬å½¢,æ±ã,ã¢ãã ,ã¢ãã EOS => nil
refs https://bitbucket.org/buruzaemon/natto/wiki/Quick-Start