|
Revision 856
(checked in by miyagawa, 3 years ago)
|
merge from trunk to plagger-server for Enclosures support and such. Sorry for the big commit
|
| 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); |
|---|
| 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 |
|---|