| 1 | package Lingua::JA::Summarize::Extract::Plugin::Scoring::Base; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw( Lingua::JA::Summarize::Extract::Plugin ); | ||
| 5 | |||
| 6 | sub scoring { | ||
| 7 | my($self, $term_list) = @_; | ||
| 8 | |||
| 9 | my $part_info = {}; | ||
| 10 | for my $term (keys %{ $term_list }) { | ||
| 11 | my @words = split /\s/, $term; | ||
| 12 | next if @words < 2; | ||
| 13 | |||
| 14 | for my $i (0 .. $#words - 1) { | ||
| 15 | $part_info->{$words[$i]}->{pre}++; | ||
| 16 | $part_info->{$words[$i + 1]}->{post}++; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | my $ret_list = {}; | ||
| 21 | for my $term (keys %{ $term_list }) { | ||
| 22 | my $score = 1; | ||
| 23 | my @words = split /\s/, $term; | ||
| 24 | for my $word (@words){ | ||
| 25 | for my $key (qw/ pre post /) { | ||
| 26 | $score *= ($part_info->{$word}->{$key} || 0) + 1; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | $score = $score ** (1 / (2 * $self->rate * (scalar @words || 1))); | ||
| 31 | $score *= $term_list->{$term}; | ||
| 32 | $ret_list->{$term} = $score; | ||
| 33 | } | ||
| 34 | |||
| 35 | $self->scoring_fixup($ret_list); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub scoring_fixup { | ||
| 39 | my($self, $scoring) = @_; | ||
| 40 | my @fixdata = map { | ||
| 41 | +{ | ||
| 42 | term => $_, | ||
| 43 | score => $scoring->{$_}, | ||
| 44 | } | ||
| 45 | } sort { $scoring->{$b} <=> $scoring->{$a} } keys %{ $scoring }; | ||
| 46 | return \@fixdata; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; |