Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
15
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Yahooの日本語形態素解析API

yahoo_ma_test.php
<?php
require_once 'HTTP/Request2.php';
$appid = '<your appid>';

$sentence = $argv[1];

$request = new HTTP_Request2('http://jlp.yahooapis.jp/MAService/V1/parse', HTTP_Request2::METHOD_GET);
$url = $request->getUrl();
$url->setQueryVariables(array(
  'appid' => $appid,
  'sentence' => $sentence,
  'results' => 'uniq',
  'filter' => '9'
));

try {
  $response = $request->send();
  if (200 == $response->getStatus()) {
    $xml = new SimpleXMLElement($response->getBody());
    foreach ($xml->uniq_result->word_list->word as $word) {
      printf("%s\t%d\n", $word->surface, $word->count);
    }
  } else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
      $response->getReasonPhrase();
  }
} catch (HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
?>
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
15
Help us understand the problem. What are the problem?