| 1 | package KinoSearch1::Analysis::Stemmer; | ||||||||||
| 2 | 26 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 26 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 26 | ▶ | use KinoSearch1::Util::ToolSet; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 26 | ▶ | use base qw( KinoSearch1::Analysis::Analyzer ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 26 | our %supported_languages; | |||||||||
| 8 | |||||||||||
| 9 | 26 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 26 | __PACKAGE__->init_instance_vars( | |||||||||
| 11 | # constructor params / members | ||||||||||
| 12 | stemmifier => undef, | ||||||||||
| 13 | ); | ||||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 26 | ▶ | use Lingua::Stem::Snowball qw( stemmers ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | # build a list of supported languages. | ||||||||||
| 19 | 26 | $supported_languages{$_} = 1 for stemmers(); | |||||||||
| 20 | |||||||||||
| 21 | 4 | ▶ | sub init_instance { | ||||||||
|
Subroutine
init_instance: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 22 | 4 | my $self = shift; | |||||||||
| 23 | |||||||||||
| 24 | # verify language param | ||||||||||
| 25 | 4 | my $language = $self->{language} = lc( $self->{language} ); | |||||||||
| 26 | croak("Unsupported language: '$language'") | ||||||||||
| 27 | 4 | ▶ | unless $supported_languages{$language}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | # create instance of Snowball stemmer | ||||||||||
| 30 | 4 | $self->{stemmifier} = Lingua::Stem::Snowball->new( lang => $language ); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 11075 | ▶ | sub analyze { | ||||||||
|
Subroutine
analyze: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | 11075 | my ( $self, $batch ) = @_; | |||||||||
| 35 | |||||||||||
| 36 | # replace terms with stemmed versions. | ||||||||||
| 37 | 11075 | my $all_texts = $batch->get_all_texts; | |||||||||
| 38 | 11075 | $self->{stemmifier}->stem_in_place($all_texts); | |||||||||
| 39 | 11075 | $batch->set_all_texts($all_texts); | |||||||||
| 40 | |||||||||||
| 41 | 11075 | $batch->reset; | |||||||||
| 42 | 11075 | return $batch; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 26 | 1; | |||||||||
| 46 | |||||||||||
| 47 | __END__ | ||||||||||