Plagger::Plugin::Filter::HatenaKeywordTag - Hatena::Keyword API for auto-tagging


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Filter::HatenaKeywordTag - Hatena::Keyword API for auto-tagging

SYNOPSIS

Top

  - module: Filter::HatenaKeywordTag
  - module: Filter::2chNewsokuTitle

DESCRIPTION

Top

Hatena::Keyword API for auto-tagging

AUTHOR

Top

Yuichi Tateno (id:secondlife)

SEE ALSO

Top

Plagger Hatena::Keyword


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::Filter::HatenaKeywordTag;
use strict;
use base qw( Plagger::Plugin );
use Hatena::Keyword;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'update.entry.fixup' => \&update,
    );
}

sub update {
    my($self, $context, $args) = @_;
    my $title = $args->{entry}->title;
    my $body = $args->{entry}->body;
    Encode::_utf8_off($body); # Hatena::Keyword's Bug?
    my $keywords = Hatena::Keyword->extract($title . ' ' . $body);
    my @terms = sort { $a->refcount <=> $b->refcount } @$keywords;

    for my $term (@terms) {
        $args->{entry}->add_tag($term);
    }
}

1;

__END__