| 1 | package Plucene::Search::PhraseScorer::Sloppy; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Plucene::Search::PhraseScorer::Sloppy - sloppy phrase scorer | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | # isa Plucene::Search::PhraseScorer | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | This is a sloppy phrase scorer | ||||||||||
| 14 | |||||||||||
| 15 | =head1 METHODS | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 4 | ▶ | use List::Util qw(max); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 4 | ▶ | use base 'Plucene::Search::PhraseScorer'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 4 | __PACKAGE__->mk_accessors(q{slop}); | |||||||||
| 27 | |||||||||||
| 28 | 10 | ▶ | sub _phrase_freq { | ||||||||
|
Subroutine
_phrase_freq: called CC=6 SCAR=17.9
| |||||||||||
| 29 | 10 | my $self = shift; | |||||||||
| 30 | 10 | my $end = 0; | |||||||||
| 31 | 10 | $#{ $self->{pq} } = -1; | |||||||||
| 32 | 10 | my $pp = $self->first; | |||||||||
| 33 | 10 | ▶ | while ($pp) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 20 | $pp->first_position; | |||||||||
| 35 | 20 | $end = max($end, $pp->position); | |||||||||
| 36 | 20 | push @{ $self->{pq} }, $pp; | |||||||||
| 37 | 20 | $pp = $pp->next_in_list; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 10 | my $freq = 0; | |||||||||
| 41 | 10 | my $done = 0; | |||||||||
| 42 | 10 | ▶ | do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 31 | my $pp = shift @{ $self->{pq} }; | |||||||||
| 44 | 31 | my $start = $pp->position; | |||||||||
| 45 | 31 | my $next = $self->{pq}->[0]->position; | |||||||||
| 46 | 31 | ▶ | for (my $pos = $start ; $pos <= $next ; $pos = $pp->position) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 59 | $start = $pos; | |||||||||
| 48 | 59 | ▶ | if (!$pp->next_position) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 10 | $done = 1; | |||||||||
| 50 | 10 | last; | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 31 | my $length = $end - $start; | |||||||||
| 55 | 31 | ▶ | $freq += 1 / ($length + 1) if $length <= $self->slop; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 31 | $end = max($end, $pp->position); | |||||||||
| 57 | 31 | push @{ $self->{pq} }, $pp; | |||||||||
| 58 | } while (!$done); | ||||||||||
| 59 | 10 | return $freq; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 4 | 1; | |||||||||