さくらでmecabのユーザ辞書使う
まず辞書つくる。
http://mecab.sourceforge.net/dic.html
書式に従ってcsvファイルを作り、サーバーの好きな場所へ置きます。
辞書のコンパイル
/usr/local/libexec/mecab/mecab-dict-index -d/usr/local/lib/mecab/dic/ipadic -u foo.dic -f euc-jp -t euc-jp foo.csv
csvファイルを置いた場所へ移動し、上記のコマンドを実行する。自分が借りているさくらのスペースの、mecabはeu-jpだった。これでサーバー側は終わりです。
次は実行ファイルの作成。PHP Mecab Extensionでユーザ辞書の利用方法がわからなかった。
http://www.php-seed.net/blog/archives/293
http://mecab.sourceforge.net/mecab.html
http://kudelab.com/archives/15
これらを参考に、
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body> <?php $text = "this is pen"; $descriptorspec = array( 0 => array("pipe", "r") , 1 => array("pipe", "w") ); $process = proc_open("/usr/local/bin/mecab --userdic=/home/userID/foobar/mydic.dic", $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], mb_convert_encoding($text, "EUC-JP", "UTF-8")); fclose($pipes[0]); $result = stream_get_contents($pipes[1]); fclose($pipes[1]); proc_close($process); var_dump(mb_convert_encoding($result, "UTF-8", "EUC-JP")); } ?> </body> </html>