MeCab extensionを使わずにMeCabで形態素解析

クデラボ -KudeLab- » PHPでMeCabを使って形態素解析をするときのメモ

PHPでMeCabを使う時は、MeCab extensionを用いりますが、あえて(か、必要にせまられて)extension moduleを使わないで、MeCabを使う方法を示されています。

$descriptorspec = array(
0 => array(“pipe”, “r”)
, 1 => array(“pipe”, “w”)
);
$process = proc_open(“/usr/local/bin/mecab”, $descriptorspec, $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $text);
fclose($pipes[0]);
$result = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}

おお。proc_open。こういう時に使うのかー。勉強になります。

関連する記事:

Powered by

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">