#author("2016-05-02T15:08:40+09:00","default:wikiwriter","wikiwriter")
&tag(Mecab);
*目次 [#v2823667]
#contents

*関連ページ [#w6d560fc]
-[[./古い情報]]

*参考情報 [#m005e2b7]
-[[MeCab: Yet Another Part-of-Speech and Morphological Analyzer:http://mecab.googlecode.com/svn/trunk/mecab/doc/index.html#download]]

*Mac OS X Lionにソースからインストール(2012/06/21(木)) [#a48e9ffb]
**基本 [#j043337f]
-相変わらずソースからインストールする。
*インストール [#xce0b1a8]
-Homebrewの場合
 brew install mecab mecab-ipadic

**ダウンロード。 [#oca4e209]
-[[MeCab: Yet Another Part-of-Speech and Morphological Analyzer:http://mecab.googlecode.com/svn/trunk/mecab/doc/index.html#download]]から、mecab-0.994、mecab-ipadic-2.7.0-20070801、 mecab-ruby-0.994をダウンロード。
*Rubyから使う [#we3794b4]

**Mecab本体のインストール [#q28c0a10]
-簡単。
**nattoから使う [#nd9d0626]
-[[rubyのmecabバインディングnattoを使う - Qiita:http://qiita.com/k-shogo/items/0f8a98c52913c729c7eb]]によると標準の拡張よりnattoから使った方が便利っぽい。
#pre{{
$ ./configure
$ make
$ sudo make install
}}
require 'natto'

**Mecabの辞書のインストール [#b17f4ce5]
-簡単。
#pre{{
cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf8
$ make
$sudo make install
}}
text = <<"EOS"
悪質な業者によるトラブルが全国で急増している。
EOS

**Ruby拡張のインストール [#z005cd79]
-簡単になった。[[OSX-GCC-Installer]]が必要かもしれない。
#pre{{
$ ruby extconf.rb
$ make
$ sudo make install
nm = Natto::MeCab.new
nm.parse(text) do |n|
  puts "#{n.surface}\t#{n.feature}"
end
}}
-test.rbを実行してみる。

*Mac OS X Lionにソースからインストール(2011/10/29(土)) [#t22c02dd]
**基本 [#b79ff4b4]
-MacPortsのrb-mecabがruby1.8に依存している。ruby1.9で使おうと思った場合ソースコードからインストールするしかない([[Mac 10.6 + Ruby 1.9.2 + MeCab - shuiichiの日記 -明日になったら本気出す-:http://d.hatena.ne.jp/shuiichi/20110502/1304324179]])。

**ダウンロード [#c779a9ee]
-[[MeCab: Yet Another Part-of-Speech and Morphological Analyzer:http://mecab.sourceforge.net/]]から
mecab-0.98, mecab-ipadic-2.7.0-20070801, mecab-ruby-0.98をダウンロードして展開する。

**MeCab本体のインストール [#j882c432]
-簡単
**標準のRubyバインディングから使う [#q2c5cd72]
-ソースをダウンロードし、extconf.rbを編集
#pre{{
$ ./configure
$ make
$ sudo make install
}}
**MeCabの辞書 [#r94093c2]
-これも簡単。
#pre{{
cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf8
$ make
$sudo make install
}}

**Ruby拡張 [#g535fd9b]
-これがめんどくさかった。
-上記リンクにあるようにまずextconf.rbを編集し$CFLAGの下に追加。
#pre{{
$CFLAGS += ' ' + `#{mecab_config} --cflags`.chomp
$LDFLAGS = '-L/usr/local/lib'
have_header('mecab.h') && create_makefile('MeCab')
}}
-gcc-4.2とg++-4.2が存在しないためリンクしておく。これをしないとruby extconf.rbでエラー。
 ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
 ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2
-あとは普通に実行できる。
#pre{{
$ ruby extconf.rb
$ make
$ sudo make install
}}
-test.rbを実行。ただしruby1.9なのでencoding指定を足さないとだめ。
 # -*- encoding: utf-8 -*-

※補足)
-gcc-4.2とg++-4.2が存在しないのはLionアップデート環境だから(?)。それぞれのかわりにllvm-gcc-4.2とllvm-g++-4.2が存在していた。
-この状態でruby extconf.rbを実行すると次のエラーが表示される。
#pre{{
/opt/local/lib/ruby1.9/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
}}
-何かツールのインストールがたらないかと思ったけど、extconf.rbがgcc-4.2とg++-4.2を探しにいって存在しないからこのメッセージが表示されているらしい。一応シンボリックリンクで解決できるけど本当はどうすればいいか不明。
-ちなみにextconf.rbがgcc-4.2を探しにいくのは、MacPortsのrbconfig.rbでCCが/usr/bin/gcc-4.2に設定されているため。MacPortsのCCが/usr/bin/llvm-gcc-4.2を使うようになれば解決するのかな?



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS