blib/lib/KSx/Analysis/StripAccents.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package KSx::Analysis::StripAccents;
5 1 ▶use base qw( KinoSearch::Analysis::Analyzer );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 our $VERSION = '0.05';
8  
9 use Encode qw 'encode decode';
10 use Text::Unaccent 'unac_string_utf16';
11  
12 sub analyze_batch {
13 my ( $self, $batch ) = @_;
14  
15 # lc and unaccent all of the terms, one by one
16 while ( my $token = $batch->next ) {
17 # I have to use UTF-16BE, since, although it’s not documented,
18 # Text::Unaccent only supports big-endian. And I have to encode it,
19 # since it doesn’t support Perl’s Unicode strings. (And it’ll con-
20 # vert it to UTF-16 behind the scenes anyway, if I don’t.)
21 $token->set_text(
22 lc uc decode 'utf-16be', unac_string_utf16
23 encode 'UTF-16BE', $token->get_text );
24 # We have an ‘lc uc’ there, since some letters won’t be normalised
25 # properly without it; e.g., ‘Σσς’ should be normalised to three
26 # instances of the same character (‘σσσ’ as opposed to ‘σσς’).
27 }
28  
29 $batch->reset;
30 return $batch;
31 }
32  
33 *transform = *analyze_batch;
34  
35 1;
36  
37 __END__
↑ Summary