line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Summarize::Extract::ResultSet; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use base qw( Class::Accessor::Fast ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
94
|
|
5
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ length summary sentences /); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use overload ( |
8
|
1
|
|
|
|
|
7
|
q("") => \&as_string, |
9
|
|
|
|
|
|
|
fallback => 1, |
10
|
1
|
|
|
1
|
|
1600
|
); |
|
1
|
|
|
|
|
1033
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
14
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
15
|
0
|
|
0
|
|
|
|
$self->{length} ||= 255; |
16
|
0
|
|
|
|
|
|
$self->init; |
17
|
0
|
|
|
|
|
|
$self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub init { |
21
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my @ranking = (); |
24
|
0
|
|
|
|
|
|
for my $line (@{ $self->sentences }) { |
|
0
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
next unless $line; |
26
|
0
|
|
|
|
|
|
my $score = 0; |
27
|
0
|
|
|
|
|
|
for my $term (@{ $self->summary }) { |
|
0
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my @words = split /\s/, $term->{term}; |
29
|
0
|
|
|
|
|
|
my %tmp; |
30
|
0
|
|
|
|
|
|
my $tmp_score = 0; |
31
|
0
|
|
|
|
|
|
for my $word (@words) { |
32
|
0
|
|
|
|
|
|
for ($line->{text} =~ /(\Q$word\E)/) { |
33
|
0
|
|
|
|
|
|
$tmp_score += $term->{score}; |
34
|
0
|
|
|
|
|
|
$tmp{$word} = 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
|
$score += $tmp_score if scalar(@words) == scalar(keys %tmp); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
push @ranking, +{ %{ $line }, score => $score, A => 'II' }; |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
@ranking = sort { $b->{score} <=> $a->{score} } @ranking; |
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->sentences(\@ranking); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub as_string { |
46
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $text; |
49
|
|
|
|
|
|
|
my @result; |
50
|
0
|
|
|
|
|
|
for my $line (@{ $self->sentences }) { |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
push @result, $line; |
52
|
0
|
|
|
|
|
|
$text .= "$line->{text}\n"; |
53
|
0
|
0
|
|
|
|
|
last if length $text > $self->length; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ($self->{sort} ne 'score') { |
57
|
0
|
|
|
|
|
|
$text = ''; |
58
|
0
|
|
|
|
|
|
for my $line (sort { $a->{line} <=> $b->{line} } @result) { |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$text .= "$line->{text}\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $len = $self->length; |
64
|
0
|
|
|
|
|
|
$text =~ s/^(.{$len}).*$/$1\n/s; |
65
|
0
|
|
|
|
|
|
$text; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |