File Coverage

blib/lib/Lingua/Stem/Patch/PL.pm
Criterion Covered Total %
statement 74 74 100.0
branch 52 52 100.0
condition n/a
subroutine 14 14 100.0
pod 0 8 0.0
total 140 148 94.5


line stmt bran cond sub pod time code
1             package Lingua::Stem::Patch::PL;
2              
3 1     1   25515 use v5.8.1;
  1         3  
  1         34  
4 1     1   4 use utf8;
  1         2  
  1         4  
5 1     1   15 use strict;
  1         2  
  1         22  
6 1     1   4 use warnings;
  1         1  
  1         30  
7 1     1   411 use parent 'Exporter';
  1         261  
  1         4  
8              
9             our $VERSION = '0.06';
10             our @EXPORT_OK = qw( stem stem_pl );
11              
12             *stem_pl = \&stem;
13              
14             sub stem {
15 1     1 0 5 my $word = lc shift;
  1     77   2  
  1         15  
  77         293  
16              
17 77         17503 $word = remove_noun($word);
18 77         114 $word = remove_diminutive($word);
19 77         108 $word = remove_adjective($word);
20 77         100 $word = remove_verb($word);
21 77         108 $word = remove_adverb($word);
22 77         95 $word = remove_plural($word);
23 77         94 $word = remove_other($word);
24              
25 77         233 return $word;
26             }
27              
28             sub remove_noun {
29 77     77 0 84 my ($word) = @_;
30 77         99 my $length = length $word;
31              
32 77 100       151 if ($length > 6) {
33 37 100       187 return $word if $word =~ s{ (?:
34             tach
35             | acj[aąi] # -acja -acją -acji
36             | [ae]ni[eu] # -anie -aniu -enie -eniu
37             | (?<= ty ) ka # -tyka → -ty
38             ) $}{}x;
39             }
40              
41 68 100       99 if ($length > 5) {
42 53 100       199 return $word if $word =~ s{ (?:
43             ach | ami | ce | ta
44             | [cn]i[au] # -cia -ciu -nia -niu
45             | (?<= c ) j[aąi] # -cja -cją -cji → -c
46             ) $}{}x;
47             }
48              
49 56         153 return $word;
50             }
51              
52             sub remove_diminutive {
53 77     77 0 74 my ($word) = @_;
54 77         76 my $length = length $word;
55              
56 77 100       114 if ($length > 6) {
57 21 100       79 return $word if $word =~ s{ (?:
58             (?: [aiu]s | [ei]c ) zek # -aszek -eczek -iczek -iszek -uszek
59             | (?<= e[jnr] ) ek # -ejek -enek -erek → -ej -en -er
60             ) $}{}x;
61             }
62              
63 71 100       105 if ($length > 4) {
64 54 100       102 return $word if $word =~ s{
65             [ae]k # -ak -ek
66             $}{}x;
67             }
68              
69 67         86 return $word;
70             }
71              
72             sub remove_adjective {
73 77     77 0 63 my ($word) = @_;
74 77         64 my $length = length $word;
75              
76 77 100       112 if ($length > 7) {
77 10 100       33 return $1 if $word =~ m{^
78             naj # naj-
79             ( .+ ) # $1
80             sz (?: [ey] | ych ) # -sze -szy -szych
81             $}x;
82             }
83              
84 74 100       125 if ($length > 6) {
85 11 100       28 return $word
86             if $word =~ s{ czny $}{}x;
87             }
88              
89 73 100       99 if ($length > 5) {
90 31 100       120 return $word if $word =~ s{ (?:
91             ego | ej | ych
92             | ow[aey] # -owa -owe -owy
93             ) $}{}x;
94             }
95              
96 67         82 return $word;
97             }
98              
99             sub remove_verb {
100 77     77 0 63 my ($word) = @_;
101 77         70 my $length = length $word;
102              
103 77 100       110 if ($length > 5) {
104 25 100       90 return $word if $word =~ s{ (?:
105             bym | cie | łem
106             | [ae] (?: my | sz | ść ) # -amy -emy -asz -esz -aść -eść
107             ) $}{}x;
108             }
109              
110 68 100       103 if ($length > 3) {
111 54 100       218 return $word if $word =~ s{ (?:
112             ąc
113             | a[ćmł] # -ać -am -ał
114             | e[ćm] # -eć -em
115             | i[ćł] # -ić -ił
116             | (?<= a ) j # -aj → -a
117             | (?<= [ae] ) (?: sz | ść ) # -asz -aść -esz -eść → -a -e
118             ) $}{}x;
119             }
120              
121 55         60 return $word;
122             }
123              
124             sub remove_adverb {
125 77     77 0 68 my ($word) = @_;
126 77         75 my $length = length $word;
127              
128 77 100       125 if ($length > 4) {
129 29 100       80 return $word if $word =~ s{ (?:
130             (?<= r ) ze # -rze → -r
131             | (?<= [nw] ) ie # -nie -wie → -n -w
132             ) $}{}x;
133             }
134              
135 74         85 return $word;
136             }
137              
138             sub remove_plural {
139 77     77 0 68 my ($word) = @_;
140 77         85 my $length = length $word;
141              
142 77 100       109 if ($length > 4) {
143 26 100       84 return $word if $word =~ s{ (?:
144             ami | om | ów
145             ) $}{}x;
146             }
147              
148 75         78 return $word;
149             }
150              
151             sub remove_other {
152 77     77 0 64 my ($word) = @_;
153 77         58 my $length = length $word;
154              
155 77 100       119 if ($length > 4) {
156 25 100       55 return $word if $word =~ s{
157             i[ae] # -ia -ie
158             $}{}x;
159             }
160              
161 75 100       91 if ($length > 3) {
162 47 100       138 return $word
163             if $word =~ s{ [aąęiłuy] $}{}x;
164             }
165              
166 60         67 return $word;
167             }
168              
169             1;
170              
171             __END__