root/trunk/plagger/lib/Plagger/Plugin/Filter/HatenaKeywordTag.pm

Revision 746 (checked in by miyagawa, 14 years ago)

apply misc match to Hatena plugins from http://d.hatena.ne.jp/j708/20060515#1147682524

Line 
1 package Plagger::Plugin::Filter::HatenaKeywordTag;
2 use strict;
3 use base qw( Plagger::Plugin );
4 use Hatena::Keyword;
5
6 sub register {
7     my($self, $context) = @_;
8     $context->register_hook(
9         $self,
10         'update.entry.fixup' => \&update,
11     );
12 }
13
14 sub update {
15     my($self, $context, $args) = @_;
16     my $title = $args->{entry}->title;
17     my $body = $args->{entry}->body;
18     Encode::_utf8_off($body); # Hatena::Keyword's Bug?
19     my $keywords = Hatena::Keyword->extract($title . ' ' . $body);
20     my @terms = sort { $a->refcount <=> $b->refcount } @$keywords;
21
22     for my $term (@terms) {
23         $args->{entry}->add_tag($term);
24     }
25 }
26
27 1;
28
29 __END__
30
31 =head1 NAME
32
33 Plagger::Plugin::Filter::HatenaKeywordTag - Hatena::Keyword API for auto-tagging
34
35 =head1 SYNOPSIS
36
37   - module: Filter::HatenaKeywordTag
38   - module: Filter::2chNewsokuTitle
39
40 =head1 DESCRIPTION
41
42 Hatena::Keyword API for auto-tagging
43
44 =head1 AUTHOR
45
46 Yuichi Tateno (id:secondlife)
47
48 =head1 SEE ALSO
49
50 L<Plagger>
51 L<Hatena::Keyword>
52
53 =cut
Note: See TracBrowser for help on using the browser.