| 1 | package Plagger::Plugin::Summary::Japanese; | ||
| 2 | use strict; | ||
| 3 | use base qw( Plagger::Plugin ); | ||
| 4 | |||
| 5 | use Lingua::JA::Summarize::Extract; | ||
| 6 | |||
| 7 | sub register { | ||
| 8 | my($self, $context) = @_; | ||
| 9 | $context->autoload_plugin({ module => 'Filter::GuessLanguage' }); | ||
| 10 | $self->{extracter} = Lingua::JA::Summarize::Extract->new($self->conf); | ||
| 11 | $context->register_hook( | ||
| 12 | $self, | ||
| 13 | 'summarizer.summarize' => \&summarize, | ||
| 14 | ); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub summarize { | ||
| 18 | my($self, $context, $args) = @_; | ||
| 19 | |||
| 20 | my $lang = $args->{entry}->language || $args->{feed}->language; | ||
| 21 | return unless $lang && $lang eq 'ja'; | ||
| 22 | |||
| 23 | my $summary = $self->{extracter}->extract($args->{entry}->body->plaintext); | ||
| 24 | $summary->length(128) unless $self->conf->{length}; | ||
| 25 | return $summary->as_string; | ||
| 26 | } | ||
| 27 | |||
| 28 | 1; | ||
| 29 | __END__ |