root/trunk/plagger/lib/Plagger/Plugin/Summary/GetSen.pm

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

added Summary::GetSen?

Line 
1 package Plagger::Plugin::Summary::GetSen;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Encode;
6 use XMLRPC::Lite;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->autoload_plugin({ module => 'Filter::GuessLanguage' });
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     $context->log(info => "Call GetSen XMLRPC API for " . ( $args->{entry}->permalink || '(no-url)' ));
24     my $res;
25     eval {
26         $res = XMLRPC::Lite->proxy("http://www.ryo.com/getsen/rpc.php")
27             ->call("ryocomJapanese.getsen", encode_utf8($args->{text}->plaintext))
28             ->result;
29     };
30
31     if (my $err = $res->{flerror} ? $res->{message} : $@) {
32         $context->log(error => "Got error: $err");
33         return;
34     }
35
36     decode_utf8($res->{summarySentence});
37 }
38
39 1;
40 __END__
41
42 =for stopwords GetSen
43
44 =head1 NAME
45
46 Plagger::Plugin::Summary::GetSen - Use GetSen XML-RPC API to extract summary from Japanese text
47
48 =head1 SYNOPSIS
49
50   - module: Summary::GetSen
51
52 =head1 DESCRIPTION
53
54 This plugin uses GetSen L<http://www.ryo.com/getsen/getsen.php>
55 XML-RPC API to auto-summarize Japanese text.
56
57 =head1 AUTHOR
58
59 Tatsuhiko Miyagawa
60
61 =head1 SEE ALSO
62
63 L<Plagger>, L<http://www.ryo.com/getsen/getsen.php>, L<http://www.ryo.com/ryo/2005/06/03/45/>
64
65 =cut
Note: See TracBrowser for help on using the browser.