aptitude install php5-dev aptitude install mecab-dev
解凍
tar xzvf php_mecab-0.0.3.tgz cd php_mecab-0.0.3/
バイナリ作成
phpize ./configure --with-php-config=/usr/bin/php-config --with-mecab=/usr/bin/mecab-config make make test ... FAIL mecab_node_next() function [tests/mecab_node_next.phpt] FAIL mecab_node_rewind() function [tests/mecab_node_rewind.phpt] FAIL mecab_node_toarray() function [tests/mecab_node_toarray.phpt] FAIL mecab_node_valid() function [tests/mecab_node_valid.phpt] FAIL mecab_path_get_cost() function [tests/mecab_path_get_cost.phpt] FAIL mecab_path_get_lnext() function [tests/mecab_path_get_lnext.phpt] FAIL mecab_path_get_lnode() function [tests/mecab_path_get_lnode.phpt] FAIL mecab_path_get_prob() function [tests/mecab_path_get_prob.phpt] FAIL mecab_path_get_rnext() function [tests/mecab_path_get_rnext.phpt] FAIL mecab_path_get_rnode() function [tests/mecab_path_get_rnode.phpt] FAIL mecab_sparse_tonode() function [tests/mecab_sparse_tonode.phpt] FAIL mecab_sparse_tostr() function [tests/mecab_sparse_tostr.phpt] ===================================================================== Number of tests : 42 42 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 42 (100.0%) (100.0%) Tests passed : 0 ( 0.0%) ( 0.0%)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
ログをみると
EXPECTED OUTPUT OK ACTUAL OUTPUT PHP Warning: PHP Startup: Unable to load dynamic library 'modules/pdo.so' - modules/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0 OK FAILED
がーん、ぜんぜん違うエラーじゃないか。
/etc/php5/conf.d/pdo.ini
から
extension=pdo.so
の行をコメントアウトする
... PASS mecab_sparse_tostr() function [tests/mecab_sparse_tostr.phpt] ===================================================================== Number of tests : 42 42 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Tests passed : 42 (100.0%) (100.0%)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
作成したバイナリのコピー
sudo make install
実際にexampleのソースを動かしてみるとエラーがでる。
/root/package/php_mecab/php_mecab-0.0.3/examples/parse-oo.php:6: tagger.cpp(133) [load_dictionary_resource(param)] param.cpp(30) [ifs] no such file or directory: /opt/local/lib/mecab/dic/ipadic-utf8/dicrc
うーん、そんなところに辞書ファイルは置いてないんだけどなぁ。
php_mecabのソースを追っていったら、mecab_mainでパラメータを受け取っていることが判明。
よく見るとphpのソース内で辞書ファイルのパスがかいてあるじゃないかぁ。
mecab_new() のパラメータに辞書のパスを渡す必要があるみたい。
$mecab_argv = array("-d" => '/var/lib/mecab/dic/debian', # ←ココにパスをいれる "-N" => 3, "-l" => "2"); $handle = mecab_new($mecab_argv); ... ...
そしたらできた。
Array ( [node] => Array ( [surface] => た [feature] => 助動詞,*,*,*,特殊・タ,基本形,た,タ,タ [id] => 42 [length] => 3 [rlength] => 3 [rcAttr] => 435 [lcAttr] => 435 [posid] => 0 [char_type] => 0 [stat] => 0 [isbest] => 1 [alpha] => 9.45328617096 [beta] => 0.693147182465 [prob] => 0.485714107752 [wcost] => 5280 ........