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();
}
?>