ã¯ã¦ãªãã¤ã¢ãªã¼ãã¼ã¯ã¼ãæ½åºã¢ã¸ã¥ã¼ã«
ä¸æ¨æ¥ãååã®ç«¹è¿«ããã«ãææ¸å ããã®ãã¼ã¯ã¼ãæ½åºæè¡ã«ã¤ãã¦æãã¦ããã£ã¦ããæããããã TF-IDF注1 ç¨ã«å¥ã®ã³ã¼ãã¹ãç¨æããªãã¦ããMeCab ã ã£ããçèµ·ã³ã¹ããè¾æ¸å ã«æã£ã¦ãããã ãããããã使ãã°ããã®ã§ã¯ãªãããã¨ãã話ã«ãªãã¾ããã
ã竹迫ããããã®æ¥ã®ãã¡ã«ä½ã£ã¦ããããããã¿ã¤ãã§ãã¢ã«ã´ãªãºã ã®æ¹åã¨ãã©ã¡ã¼ã¿ã®ãã¥ã¼ãã³ã°ãè¡ã£ãã¨ãããååãªå質ãåºãããªã®ã§ãæ¸ãç´ãã¦å ¬éãããã¨ã«ãã¾ããã
ã¨ããµã¤ãã¦ãºã©ãã®å¥¥ããã Lingua::JA::Summarize ã¨ãã Mecab ã使ã£ããã¼ã¯ã¼ãæ½åºã¢ã¸ã¥ã¼ã«ããªãªã¼ã¹ã㦠GJ ã§ãã
ã§ãããã«ã¤ã³ã¹ãã¤ã¢ããã¦ã¨ããããããããã°ã¯ã¦ãªããã¯ãã¼ã¯ãã¨ã³ããªã¼ã®ãã¼ã¯ã¼ãæ½åºã¨ããã£ã¦ããªãã¨æã£ã¦ãä¸ãè¦ã¦ã¿ãããããå®è£
ãæ±ãã£ãï½ ãã¨ããä¸ã®å®è£
æ¹æ³ã¯ã¨ããã¨ãæ®éã«ã¯ã¦ãªãã¤ã¢ãªã¼ã®ãã¼ã¯ã¼ããªã³ã¯APIãå©ãã¦ãã¼ã¯ã¼ããæ½åºãã¦ããããããªãã§ããããã®ãã¼ã¯ã¼ããªã³ã¯APIã«ã¯ããã¥ã¡ã³ãã¼ã·ã§ã³ããã¦ãªããã©ã¡ã¼ã¿ã« mode
ã¨ããã®ãããã¾ãã¦ãããã« lite
ãæå®ããã¨ããã¹ãããã¼ã¯ã¢ããããã®ã§ã¯ãªããä¸ããããã¹ãã«å«ã¾ãããã¼ã¯ã¼ãã®ãªã¹ããè¿ãã¦ãããããã¾ããã¯ã¦ãªå
ã®ãµã¼ãã¹ã§ããã¼ã¯ã¼ãæ½åºãã¸ãã¯ã使ãåãããã«ä½ã£ããã®ã ã£ãã¨æããã§ããã
æã¤ã¶ãã«ãã® API ã使ã£ããã¼ã¯ã¼ãæ½åºãæ½è±¡åããã¢ã¸ã¥ã¼ã«ãæ¸ãã¦ã¿ã¾ããã
use Hatena::Keyword; my $body = 'ã¯ã¦ãªãã¤ã¢ãªã¼ã®ãã¼ã¯ã¼ãããªã³ã¯ãã¦ã'; my @keywords = Hatena::Keyword->retrieve($body); print $_->score, "?t", $_->euc, "?n" for @keywords;
ã¨ããã¨
73 ã¯ã¦ãªãã¤ã¢ãªã¼ 42 ãã¼ã¯ã¼ã 23 ãªã³ã¯ 25 ãªã³ã¯ 20 ãªã³ã¯ 16 ãªã³ã¯
ã¨ããçµæãè¿ã£ã¦ããããããããé«æ©è½ãª SYNOPSYS ã¨ãã¦ã¯
my $body = 'ã¯ã¦ãªãã¤ã¢ãªã¼ã®ãã¼ã¯ã¼ãããªã³ã¯ãã¦ã'; # EUC my @keywords = Hatena::Keyword->retrieve( $body { score => 20 cname => [qw(hatena)] }, ); print $_->score, "?t", $_->euc, "?n" for @keywords;
ã¨ããæããretrieve
ã®å¼æ°ã«ã¹ã³ã¢ã®é¾å¤ããæ½åºãããã¼ã¯ã¼ãã®ã«ãã´ãªä¸è¦§ãæå®ã§ããããã¨ããã®ã¯ã©ã¹ã«ã¨ã£ã¦ã¯ã¡ãã£ã¨åé·ãªæ©è½ããã ãã©ãè¿å´ããã¦ãããªãã¸ã§ã¯ãã®æåã³ã¼ããã¡ã½ããã§å¤æã§ãããTT ã¨ãã§ä½¿ããã¨ãèæ
®ãããã®ã(Template::Plugin::Jcode 使ãã¨ãã説ããããã©ã)
å®è£ ã¯ãããªå ·åã§ãã
package Hatena::Keyword; use strict; use warnings; use base qw(Class::Data::Inheritable Class::Accessor Class::ErrorHandler); use overload '""' => ?&as_string, fallback => 1; use Carp; use URI; use RPC::XML; use RPC::XML::Client; use Jcode; our $VERSION = 0.02; my @Fields = qw(refcount word score cname); __PACKAGE__->mk_accessors(@Fields); __PACKAGE__->mk_classdata(rpc_client => RPC::XML::Client->new( URI->new_abs('/xmlrpc', 'http://d.hatena.ne.jp/'), [ useragent => join('/', __PACKAGE__, __PACKAGE__->VERSION) ] )); BEGIN { no strict 'refs'; for my $code (qw(sjis euc jis ucs2 iso_2022_jp)) { *$code = sub { my $self = shift; $self->{$code} and return $self->{code}; return $self->{$code} = Jcode->new($self->word, 'utf8')->$code; }; } } sub retrieve { my $class = shift; my $body = shift or croak sprintf 'usage %s->retrieve($text)', $class; my $args = shift || {}; $args->{mode} = 'lite'; my $res = $class->_call_rpc($body, $args) or $class->error($class->errstr); my @keywords = map { $class->_instance_from_rpcdata($_) }@{$res->{wordlist}}; wantarray ? @keywords : ?@keywords; } sub markup_as_html { my $class = shift; my $body = shift or croak sprintf 'usage %s->markup_as_html($text)', $class; my $args = shift || {}; $args->{mode} = ''; my $res = $class->_call_rpc($body, $args) or $class->error($class->errstr); return $res->value; } sub _call_rpc { my ($class, $body, $args) = @_; my $params = { body => RPC::XML::string->new($body), score => RPC::XML::int->new($args->{score} || 0), mode => RPC::XML::string->new($args->{mode} || ''), cname => defined $args->{cname} ? RPC::XML::array->new( map { RPC::XML::string->new($_) } @{$args->{cname}} ) : undef, a_target => RPC::XML::string->new($args->{a_target} || ''), a_class => RPC::XML::string->new($args->{a_class} || ''), }; # For all categories, It doesn't need an undefined cname value. delete $params->{cname} unless defined $params->{cname}; my $res = $class->rpc_client->send_request( RPC::XML::request->new('hatena.setkeywordlink', $params), ); ref $res ? $res : $class->error(qq/RPC Error: "$res"/); } sub _instance_from_rpcdata { my ($class, $data) = @_; $class->new({ map {$_ => $data->{$_}->value } @Fields, }); } sub as_string { $_[0]->word } 1;
誰ã使ããåãããªããã©ããã¡ããã¢ã¸ã¥ã¼ã«ãã¡ã¤ã«ãç½®ãã¦ããã¾ãã
å¢ãã¤ã㦠CPAN ã« up ãããããªã¨æã£ããã ãã©ãã¡ãã£ã¨åå空éãå¾®å¦ã§ãå
æ¥ãªãªã¼ã¹ãã Hatena::API::Auth ã¨ãã¨æ´åæ§ãæ´ãããªã Hatena::API::Keyword ããªã¨ããHatena::Keyword ã§ãªãªã¼ã¹ãããªãããã¹ãããã¼ã¯ã¢ããããæ©è½ãæè¼ããªãããããªãããªã¨ããmarkup_as_html
ã追å ããã ã㨠CPAN ã«ä¸ãããªã Jcode ã®æ©è½ãå
å
ãã¦ãã®ã¯å¤ãã¦ãããããªã¨ãããã®è¾ºãèãã¦ã¾ãã