LoginSignup
3
3

More than 5 years have passed since last update.

PHP から Mecab を使うコード

Posted at
mecab_test.php
<?php
$text = $argv[1];
$mecab = new Mecab();

$keywords = array();
$nodes = $mecab->parseToNode($text);
foreach ($nodes as $node) {
  if ($node->posid >= 37 && $node->posid <= 66) {
    if (isset($keywords[$node->surface])) {
      $keywords[$node->surface]++;
    } else{
      $keywords[$node->surface] = 1;
    }
  }
}
arsort($keywords);
print_r($keywords);
?>
$ php mecab_test.php <sentence>
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3