PortableUbuntuでmecab-rubyを使う
PortableUbuntu for Windows(9.04)
Ubuntuに形態素解析(ChaSen,Mecab)をインストール
↑でMecabのインストールだけ書いたけど、結局0.98にアップデートはできなかった。
だけでなく、まっ更な状態から0.98を入れることもできなかった。
OSがインストールされたドライブでないとmakeが通らないとか。
PortableUbuntuだからだめなのか?
ぺーぺーの私には解決策がわかりませんでした。
今回はrubyでmecabが使えるようになるまでをおさらい。
諦めてapt-getでmecabを入れます。
(※ver0.97が入りますが、最新版は0.98)
$ sudo apt-get -y install mecab libmecab-dev $ sudo apt-get -y install mecab-ipadic-utf8 mecab-jumandic-utf8
mecabと、mecab用utf8辞書がインストールされたはず
次にmecab-rubyを入れる。
http://sourceforge.net/projects/mecab/files/
↑こっから手動で落としてもいいけど、wgetでやってみよう。
verを揃えるので、今回はmecab-ruby-0.97となる。
$ wget http://sourceforge.net/projects/mecab/files/mecab-ruby/0.97/mecab-ruby-0.97.tar.gz $ tar zxvf mecab-ruby-0.97.tar.gz $ cd mecab-ruby-0.97 $ ruby extconf.rb $ make $ sudo make install
問題なく入った。
端末上で
$ mecab -h
とすると、使える引数一覧が表示された。
Usage: mecab [options] files -r, --rcfile=FILE use FILE as resource file -d, --dicdir=DIR set DIR as a system dicdir -u, --userdic=FILE use FILE as a user dictionary -l, --lattice-level=INT lattice information level (default 0) -D, --dictionary-info show dictionary information and exit -a, --all-morphs output all morphs(default false) -O, --output-format-type=TYPE set output format type (wakati,none,...) -p, --partial partial parsing mode -F, --node-format=STR use STR as the user-defined node format -U, --unk-format=STR use STR as the user-defined unk format -B, --bos-format=STR use STR as the user-defined bos format -E, --eos-format=STR use STR as the user-defined eos format -x, --unk-feature=STR use STR as the feature for unknown word -b, --input-buffer-size=INT set input buffer size (default 8192) -P, --dump-config dump MeCab parameters -M, --open-mutable-dictionary open dictioanry with mutable mode (experimental) -C, --allocate-sentence allocate new memory for input sentence -N, --nbest=INT output N best results (default 1) -t, --theta=FLOAT set temparature parameter theta (default 0.75) -o, --output=FILE set the output file name -v, --version show the version and exit. -h, --help show this help and exit.
今のところ使いそうだなって思ったのは
-O, --output-format-type=TYPE, set output format type(wakati,none,...)
くらい。
mecab -Owakati
とすることで、単語の分かち書きのみを得ることができる。
$ echo 来週は期末テストです | mecab -Owakati 来週 は 期末 テスト です
ruby内で使ってみる
require 'MeCab' mecab = Mecab::Tagger.new("-Owakati") puts mecab.parse("分かち書きしたい文章")
こんな感じらしい。