File Coverage

blib/lib/Lingua/JA/Summarize/Extract.pm
Criterion Covered Total %
statement 18 44 40.9
branch 0 12 0.0
condition 0 6 0.0
subroutine 6 10 60.0
pod 2 4 50.0
total 26 76 34.2


line stmt bran cond sub pod time code
1             package Lingua::JA::Summarize::Extract;
2              
3 1     1   4 use strict;
  1         2  
  1         32  
4 1     1   5 use base qw( Class::Accessor::Fast );
  1         2  
  1         783  
5             __PACKAGE__->mk_accessors(qw/ text rate /);
6              
7 1     1   2870 use Carp ();
  1         3  
  1         12  
8 1     1   716 use UNIVERSAL::require;
  1         1380  
  1         9  
9              
10             our $VERSION = '0.02';
11              
12 1     1   609 use Lingua::JA::Summarize::Extract::ResultSet;
  1         2  
  1         7  
13              
14             my %DefaultPlugins = (
15             scoring => 'Scoring::Base',
16             parse => 'Parser::Ngram',
17             sentence => 'Sentence::Base',
18             );
19              
20             sub new {
21 0     0 1   my $class = shift;
22 0           my $self = $class->SUPER::new(@_);
23              
24 0           for my $plugin (@{ $self->{plugins} }) {
  0            
25 0           $self->add_plugin($plugin);
26             }
27              
28 0           for my $method (keys %DefaultPlugins) {
29 0 0         $self->add_plugin($DefaultPlugins{$method}) unless $self->can($method);
30             }
31              
32 0   0       $self->{rate} ||= 1;
33              
34 0           $self;
35             }
36              
37             sub add_plugin {
38 0     0 0   my($self, $plugin) = @_;
39 0           my $class = ref $self;
40              
41 0 0         my $package = ($plugin =~ /^\+(.+)$/) ? $1 :
42             sprintf '%s::Plugin::%s', $class, $plugin;
43             {
44 1     1   173 no strict 'refs';
  1         1  
  1         214  
  0            
45 0 0         $package->require or Carp::croak($@);
46 0           unshift @{"$class\::ISA"}, $package;
  0            
47             }
48 0           $package->init($self);
49             }
50              
51             sub extract {
52 0     0 1   my($class, $text, @opt) = @_;
53 0 0         my $self = ref $class ? $class : $class->new(@opt);
54              
55 0           utf8::decode($text);
56 0 0         $self->text($text) if $text;
57              
58 0           Lingua::JA::Summarize::Extract::ResultSet->new({
59 0   0       %{ $self },
      0        
60             summary => $self->summarize || [],
61             sentences => $self->sentence || [],
62             });
63             }
64              
65             sub summarize {
66 0     0 0   my($self, $text) = @_;
67 0 0         $self->text($text) if $text;
68 0           $self->scoring($self->parse);
69             }
70              
71             1;
72              
73             __END__