HTML::ContentExtractorとYahoo! APIのキーフレーズ抽出を使うと結構お手軽に Webページからそこそこの精度でキーワードを取り出せる。 以下スクリプト例。
use WebService::Simple;
use HTML::ContentExtractor;
use LWP::UserAgent;
use Encode;
my $url = $ARGV[0] || 'http://yusukebe.com/archives/10/05/12/150832.html';
my $extractor = HTML::ContentExtractor->new();
my $ua = LWP::UserAgent->new();
my $res = $ua->get($url);
my $html = $res->decoded_content();
$extractor->extract( $url, $html );
my $text = $extractor->as_text();
$text = substr $text, 0, 500;
my $service = WebService::Simple->new(
base_url => 'http://jlp.yahooapis.jp/KeyphraseService/V1/extract',
response_parser => 'JSON',
);
$res = $service->get(
{
appid => 'xxxx',
sentence => $text,
output => 'json'
}
);
my $ref = $res->parse_response();
for my $key ( keys %$ref ) {
print encode_utf8("$key\n") if $ref->{$key} > 50;
}
靴下パンツ、ユニクロで買うか?無印で買うか? - ゆーすけべー日記からキーワードを抽出すると以下のようになった。
$ perl keyword.pl yusukebe 無印 ボタン ちんこ飛び出る状態 ユニクロ Erogeek パンツ 前あき型ボクサータイプ
いいんじゃないでしょうか!