line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Stemmer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7124
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
159
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1974
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
my $aa = "\xe1"; |
9
|
|
|
|
|
|
|
my $ea = "\xe9"; |
10
|
|
|
|
|
|
|
my $ia = "\xed"; |
11
|
|
|
|
|
|
|
my $oa = "\xf3"; |
12
|
|
|
|
|
|
|
my $ua = "\xfa"; |
13
|
|
|
|
|
|
|
my $at = "\xe3"; |
14
|
|
|
|
|
|
|
my $ot = "\xf5"; |
15
|
|
|
|
|
|
|
my $ac = "\xe2"; |
16
|
|
|
|
|
|
|
my $ec = "\xea"; |
17
|
|
|
|
|
|
|
my $cc = "\xe7"; |
18
|
|
|
|
|
|
|
my %rule; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$rule{plural} = { |
21
|
|
|
|
|
|
|
"ns" => [ 1, "m" ], |
22
|
|
|
|
|
|
|
"${ot}es" => [ 3, "${at}o" ], |
23
|
|
|
|
|
|
|
"${at}es" => [ 1, "${at}o" ], |
24
|
|
|
|
|
|
|
"ais" => [ 1, "al" ], |
25
|
|
|
|
|
|
|
"${ea}is" => [ 2, "el" ], |
26
|
|
|
|
|
|
|
"eis" => [ 2, "el" ], |
27
|
|
|
|
|
|
|
"${oa}is" => [ 2, "ol" ], |
28
|
|
|
|
|
|
|
"is" => [ 2, "il" ], |
29
|
|
|
|
|
|
|
"les" => [ 2, "l" ], |
30
|
|
|
|
|
|
|
"res" => [ 3, "r" ], |
31
|
|
|
|
|
|
|
"s" => [ 2, "" ], |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$rule{femin} = { |
35
|
|
|
|
|
|
|
"ona" => [ 3, "${at}o" ], |
36
|
|
|
|
|
|
|
"${at}" => [ 2, "${at}o" ], |
37
|
|
|
|
|
|
|
"ora" => [ 3, "or" ], |
38
|
|
|
|
|
|
|
"na" => [ 4, "no" ], |
39
|
|
|
|
|
|
|
"inha" => [ 3, "inho" ], |
40
|
|
|
|
|
|
|
"esa" => [ 3, "${ec}s" ], |
41
|
|
|
|
|
|
|
"osa" => [ 3, "oso" ], |
42
|
|
|
|
|
|
|
"${ia}aca" => [ 3, "${ia}aco" ], |
43
|
|
|
|
|
|
|
"ica" => [ 3, "ico" ], |
44
|
|
|
|
|
|
|
"ada" => [ 3, "ado" ], |
45
|
|
|
|
|
|
|
"ida" => [ 3, "ido" ], |
46
|
|
|
|
|
|
|
"${ia}da" => [ 3, "ido" ], |
47
|
|
|
|
|
|
|
"ima" => [ 3, "imo" ], |
48
|
|
|
|
|
|
|
"iva" => [ 3, "ivo" ], |
49
|
|
|
|
|
|
|
"eira" => [ 3, "eiro" ], |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$rule{augment} = { |
53
|
|
|
|
|
|
|
"d${ia}ssimo" => [ 5, '' ], |
54
|
|
|
|
|
|
|
"abil${ia}ssimo" => [ 5,'' ], |
55
|
|
|
|
|
|
|
"${ia}ssimo" => [ 3,'' ], |
56
|
|
|
|
|
|
|
"${ea}simo" => [ 3,'' ], |
57
|
|
|
|
|
|
|
"${ea}rrimo" => [ 4,'' ], |
58
|
|
|
|
|
|
|
"zinho" => [ 2,'' ], |
59
|
|
|
|
|
|
|
"quinho" => [ 4, "c" ], |
60
|
|
|
|
|
|
|
"uinho" => [ 4,'' ], |
61
|
|
|
|
|
|
|
"adinho" => [ 3,'' ], |
62
|
|
|
|
|
|
|
"inho" => [ 3,'' ], |
63
|
|
|
|
|
|
|
"alh${at}o" => [ 4,'' ], |
64
|
|
|
|
|
|
|
"u${cc}a" => [ 4,'' ], |
65
|
|
|
|
|
|
|
"a${cc}o" => [ 4,'' ], |
66
|
|
|
|
|
|
|
"ad${at}o" => [ 4,'' ], |
67
|
|
|
|
|
|
|
"${aa}zio" => [ 3,'' ], |
68
|
|
|
|
|
|
|
"arraz" => [ 4,'' ], |
69
|
|
|
|
|
|
|
"arra" => [ 3,'' ], |
70
|
|
|
|
|
|
|
"z${at}o" => [ 2,'' ], |
71
|
|
|
|
|
|
|
"${at}o" => [ 3,'' ], |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$rule{noun} = { |
76
|
|
|
|
|
|
|
"encialista" => [ 4, '' ], |
77
|
|
|
|
|
|
|
"alista" => [ 5, '' ], |
78
|
|
|
|
|
|
|
"agem" => [ 3, '' ], |
79
|
|
|
|
|
|
|
"iamento" => [ 4, '' ], |
80
|
|
|
|
|
|
|
"amento" => [ 3, '' ], |
81
|
|
|
|
|
|
|
"imento" => [ 3, '' ], |
82
|
|
|
|
|
|
|
"alizado" => [ 4, '' ], |
83
|
|
|
|
|
|
|
"atizado" => [ 4, '' ], |
84
|
|
|
|
|
|
|
"izado" => [ 5, '' ], |
85
|
|
|
|
|
|
|
"ativo" => [ 4, '' ], |
86
|
|
|
|
|
|
|
"tivo" => [ 4, '' ], |
87
|
|
|
|
|
|
|
"ivo" => [ 4, '' ], |
88
|
|
|
|
|
|
|
"ado" => [ 2, '' ], |
89
|
|
|
|
|
|
|
"ido" => [ 3, '' ], |
90
|
|
|
|
|
|
|
"ador" => [ 3,'' ], |
91
|
|
|
|
|
|
|
"edor" => [ 3, '' ], |
92
|
|
|
|
|
|
|
"idor" => [ 4, '' ], |
93
|
|
|
|
|
|
|
"at${oa}ria" => [ 5, '' ], |
94
|
|
|
|
|
|
|
"or" => [ 2, '' ], |
95
|
|
|
|
|
|
|
"abilidade" => [ 5,'' ], |
96
|
|
|
|
|
|
|
"icionista" => [ 4, '' ], |
97
|
|
|
|
|
|
|
"cionista" => [ 5, '' ], |
98
|
|
|
|
|
|
|
"ional" => [ 4, '' ], |
99
|
|
|
|
|
|
|
"${ec}ncia" => [ 3, '' ], |
100
|
|
|
|
|
|
|
"${ac}ncia" => [ 4, '' ], |
101
|
|
|
|
|
|
|
"edouro" => [ 3, '' ], |
102
|
|
|
|
|
|
|
"queiro" => [ 3, 'c' ], |
103
|
|
|
|
|
|
|
"eiro" => [ 3, '' ], |
104
|
|
|
|
|
|
|
"oso" => [ 3, '' ], |
105
|
|
|
|
|
|
|
"aliza${cc}" => [ 5, '' ], |
106
|
|
|
|
|
|
|
"ismo" => [ 3, '' ], |
107
|
|
|
|
|
|
|
"iza${cc}" => [ 5, '' ], |
108
|
|
|
|
|
|
|
"a${cc}" => [ 3, '' ], |
109
|
|
|
|
|
|
|
"i${cc}" => [ 3, '' ], |
110
|
|
|
|
|
|
|
"${aa}rio" => [ 3, '' ], |
111
|
|
|
|
|
|
|
"${ea}rio" => [ 6, '' ], |
112
|
|
|
|
|
|
|
"${ec}s" => [ 4, '' ], |
113
|
|
|
|
|
|
|
"eza" => [ 3, '' ], |
114
|
|
|
|
|
|
|
"ez" => [ 4, '' ], |
115
|
|
|
|
|
|
|
"esco" => [ 4, '' ], |
116
|
|
|
|
|
|
|
"ante" => [ 2, '' ], |
117
|
|
|
|
|
|
|
"${aa}stico" => [ 4, '' ], |
118
|
|
|
|
|
|
|
"${aa}tico" => [ 3, '' ], |
119
|
|
|
|
|
|
|
"ico" => [ 4, '' ], |
120
|
|
|
|
|
|
|
"ividade" => [ 5, '' ], |
121
|
|
|
|
|
|
|
"idade" => [ 5, '' ], |
122
|
|
|
|
|
|
|
"oria" => [ 4, '' ], |
123
|
|
|
|
|
|
|
"encial" => [ 5, '' ], |
124
|
|
|
|
|
|
|
"ista" => [ 4, '' ], |
125
|
|
|
|
|
|
|
"quice" => [ 4, 'c' ], |
126
|
|
|
|
|
|
|
"ice" => [ 4, '' ], |
127
|
|
|
|
|
|
|
"${ia}aco" => [ 3, '' ], |
128
|
|
|
|
|
|
|
"ente" => [ 4, '' ], |
129
|
|
|
|
|
|
|
"inal" => [ 3, '' ], |
130
|
|
|
|
|
|
|
"ano" => [ 4, '' ], |
131
|
|
|
|
|
|
|
"${aa}vel" => [ 2, '' ], |
132
|
|
|
|
|
|
|
"${ia}vel" => [ 5, '' ], |
133
|
|
|
|
|
|
|
"ura" => [ 4, '' ], |
134
|
|
|
|
|
|
|
"ual" => [ 3, '' ], |
135
|
|
|
|
|
|
|
"ial" => [ 3, '' ], |
136
|
|
|
|
|
|
|
"al" => [ 4, '' ], |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$rule{verb} = { |
141
|
|
|
|
|
|
|
"ar${ia}amo" => [ 2, ''], |
142
|
|
|
|
|
|
|
"eria" => [ 3, '' ], |
143
|
|
|
|
|
|
|
"${aa}ssemo" => [ 2, '' ], |
144
|
|
|
|
|
|
|
"ermo" => [ 3, '' ], |
145
|
|
|
|
|
|
|
"er${ia}amo" => [ 2, '' ], |
146
|
|
|
|
|
|
|
"esse" => [ 3, '' ], |
147
|
|
|
|
|
|
|
"${ec}ssemo" => [ 2, '' ], |
148
|
|
|
|
|
|
|
"este" => [ 3, '' ], |
149
|
|
|
|
|
|
|
"ir${ia}amo" => [ 3, '' ], |
150
|
|
|
|
|
|
|
"${ia}amo" => [ 3, '' ], |
151
|
|
|
|
|
|
|
"${ia}ssemo" => [ 3, '' ], |
152
|
|
|
|
|
|
|
"iram" => [ 3, '' ], |
153
|
|
|
|
|
|
|
"${aa}ramo" => [ 2, '' ], |
154
|
|
|
|
|
|
|
"${ia}ram" => [ 3, '' ], |
155
|
|
|
|
|
|
|
"${aa}rei" => [ 2, '' ], |
156
|
|
|
|
|
|
|
"irde" => [ 2, '' ], |
157
|
|
|
|
|
|
|
"aremo" => [ 2, '' ], |
158
|
|
|
|
|
|
|
"irei" => [ 3, '' ], |
159
|
|
|
|
|
|
|
"ariam" => [ 2, '' ], |
160
|
|
|
|
|
|
|
"irem" => [ 3, '' ], |
161
|
|
|
|
|
|
|
"ar${ia}ei" => [ 2, '' ], |
162
|
|
|
|
|
|
|
"iria" => [ 3, '' ], |
163
|
|
|
|
|
|
|
"${aa}ssei" => [ 2, '' ], |
164
|
|
|
|
|
|
|
"irmo" => [ 3, '' ], |
165
|
|
|
|
|
|
|
"assem" => [ 2, '' ], |
166
|
|
|
|
|
|
|
"isse" => [ 3, '' ], |
167
|
|
|
|
|
|
|
"${aa}vamo" => [ 2, '' ], |
168
|
|
|
|
|
|
|
"iste" => [ 4, '' ], |
169
|
|
|
|
|
|
|
"${ec}ramo" => [ 3, '' ], |
170
|
|
|
|
|
|
|
"amo" => [ 2, '' ], |
171
|
|
|
|
|
|
|
"eremo" => [ 3, '' ], |
172
|
|
|
|
|
|
|
"ara" => [ 2, '' ], |
173
|
|
|
|
|
|
|
"eriam" => [ 3, '' ], |
174
|
|
|
|
|
|
|
"ar${aa}" => [ 2, '' ], |
175
|
|
|
|
|
|
|
"er${ia}ei" => [ 3, '' ], |
176
|
|
|
|
|
|
|
"are" => [ 2, '' ], |
177
|
|
|
|
|
|
|
"${ec}ssei" => [ 3, '' ], |
178
|
|
|
|
|
|
|
"ava" => [ 2, '' ], |
179
|
|
|
|
|
|
|
"essem" => [ 3, '' ], |
180
|
|
|
|
|
|
|
"emo" => [ 2, '' ], |
181
|
|
|
|
|
|
|
"${ia}ramo" => [ 3, '' ], |
182
|
|
|
|
|
|
|
"era" => [ 3, '' ], |
183
|
|
|
|
|
|
|
"iremo" => [ 3, '' ], |
184
|
|
|
|
|
|
|
"er${aa}" => [ 3, '' ], |
185
|
|
|
|
|
|
|
"iriam" => [ 3, '' ], |
186
|
|
|
|
|
|
|
"ere" => [ 3, '' ], |
187
|
|
|
|
|
|
|
"ir${ia}ei" => [ 3, '' ], |
188
|
|
|
|
|
|
|
"iam" => [ 3, '' ], |
189
|
|
|
|
|
|
|
"${ia}ssei" => [ 3, '' ], |
190
|
|
|
|
|
|
|
"${ia}ei" => [ 3, '' ], |
191
|
|
|
|
|
|
|
"issem" => [ 3, '' ], |
192
|
|
|
|
|
|
|
"imo" => [ 3, '' ], |
193
|
|
|
|
|
|
|
"ando" => [ 2, '' ], |
194
|
|
|
|
|
|
|
"ira" => [ 3, '' ], |
195
|
|
|
|
|
|
|
"endo" => [ 3, '' ], |
196
|
|
|
|
|
|
|
"ir${aa}" => [ 3, '' ], |
197
|
|
|
|
|
|
|
"indo" => [ 3, '' ], |
198
|
|
|
|
|
|
|
"ire" => [ 3, '' ], |
199
|
|
|
|
|
|
|
"ondo" => [ 3, '' ], |
200
|
|
|
|
|
|
|
"omo" => [ 3, '' ], |
201
|
|
|
|
|
|
|
"aram" => [ 2, '' ], |
202
|
|
|
|
|
|
|
"ai" => [ 2, '' ], |
203
|
|
|
|
|
|
|
"arde" => [ 2, '' ], |
204
|
|
|
|
|
|
|
"am" => [ 2, '' ], |
205
|
|
|
|
|
|
|
"arei" => [ 2, '' ], |
206
|
|
|
|
|
|
|
"ear" => [ 4, '' ], |
207
|
|
|
|
|
|
|
"arem" => [ 2, '' ], |
208
|
|
|
|
|
|
|
"ar" => [ 2, '' ], |
209
|
|
|
|
|
|
|
"aria" => [ 2, '' ], |
210
|
|
|
|
|
|
|
"uei" => [ 3, '' ], |
211
|
|
|
|
|
|
|
"armo" => [ 2, '' ], |
212
|
|
|
|
|
|
|
"ei" => [ 3, '' ], |
213
|
|
|
|
|
|
|
"asse" => [ 2, '' ], |
214
|
|
|
|
|
|
|
"em" => [ 2, '' ], |
215
|
|
|
|
|
|
|
"aste" => [ 2, '' ], |
216
|
|
|
|
|
|
|
"er" => [ 2, '' ], |
217
|
|
|
|
|
|
|
"avam" => [ 2, '' ], |
218
|
|
|
|
|
|
|
"eu" => [ 3, '' ], |
219
|
|
|
|
|
|
|
"${aa}vei" => [ 2, '' ], |
220
|
|
|
|
|
|
|
"ia" => [ 3, '' ], |
221
|
|
|
|
|
|
|
"eram" => [ 3, '' ], |
222
|
|
|
|
|
|
|
"ir" => [ 3, '' ], |
223
|
|
|
|
|
|
|
"erde" => [ 3, '' ], |
224
|
|
|
|
|
|
|
"iu" => [ 3, '' ], |
225
|
|
|
|
|
|
|
"erei" => [ 3, '' ], |
226
|
|
|
|
|
|
|
"ou" => [ 3, '' ], |
227
|
|
|
|
|
|
|
"${ec}rei" => [ 3, '' ], |
228
|
|
|
|
|
|
|
"i" => [ 3, '' ], |
229
|
|
|
|
|
|
|
"erem" => [ 3, '' ], |
230
|
|
|
|
|
|
|
}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$rule{accent} = { |
233
|
|
|
|
|
|
|
$aa => 'a', |
234
|
|
|
|
|
|
|
$ea => 'e', |
235
|
|
|
|
|
|
|
$ia => 'i', |
236
|
|
|
|
|
|
|
$oa => 'o', |
237
|
|
|
|
|
|
|
$ua => 'u', |
238
|
|
|
|
|
|
|
$at => 'a', |
239
|
|
|
|
|
|
|
$ot => 'o', |
240
|
|
|
|
|
|
|
$ec => 'e', |
241
|
|
|
|
|
|
|
$cc => 'c', |
242
|
|
|
|
|
|
|
}; |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub strip($$) { |
245
|
33
|
|
|
33
|
0
|
45
|
my $cmd = shift; |
246
|
33
|
|
|
|
|
44
|
my $word = shift; |
247
|
33
|
100
|
|
|
|
96
|
if($cmd eq 'accent'){ |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
248
|
5
|
|
|
|
|
7
|
foreach my $a (keys %{$rule{accent}}){ |
|
5
|
|
|
|
|
26
|
|
249
|
45
|
|
|
|
|
313
|
$word =~ s/$a/$rule{accent}->{$a}/eg; |
|
0
|
|
|
|
|
0
|
|
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
} |
252
|
5
|
|
|
|
|
7
|
elsif($cmd eq 'adv'){ $word =~ s/(.{4,})mente/$1/o; } |
253
|
5
|
|
|
|
|
281
|
elsif($cmd eq 'vowel'){ $word =~ s/(.{3,})$_$/$1/ for qw/a e o/; } |
254
|
|
|
|
|
|
|
else{ |
255
|
18
|
|
|
|
|
32
|
my $cmdref = $rule{$cmd}; |
256
|
18
|
|
|
|
|
21
|
for my $key (sort { length $b <=> length $a } keys %{$cmdref}){ |
|
4201
|
|
|
|
|
4547
|
|
|
18
|
|
|
|
|
237
|
|
257
|
732
|
|
|
|
|
1754
|
my $patt = join q//, "^(.{", $cmdref->{$key}->[0], ",})", $key, '$'; |
258
|
732
|
100
|
|
|
|
10264
|
if($word =~ /$patt/){ |
259
|
5
|
|
|
|
|
96
|
$word =~ s/$patt/$1.($cmdref->{$key}->[1])/e; |
|
5
|
|
|
|
|
29
|
|
260
|
5
|
|
|
|
|
15
|
last; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
33
|
|
|
|
|
154
|
return $word; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub stem { |
268
|
1
|
|
|
1
|
0
|
10
|
my @stems; |
269
|
1
|
50
|
|
|
|
6
|
foreach ( ref($_[0]) ? @{$_[0]} : @_ ){ |
|
0
|
|
|
|
|
0
|
|
270
|
5
|
|
|
|
|
10
|
my $word = $_; |
271
|
5
|
100
|
|
|
|
33
|
$word = strip('plural', $word) if $word =~ /s$/o; |
272
|
5
|
100
|
|
|
|
23
|
$word = strip('femin', $word) if $word =~ /a$/o; |
273
|
5
|
|
|
|
|
9
|
foreach my $op (qw/augment adv noun verb vowel accent/){ |
274
|
30
|
|
|
|
|
56
|
$word = strip($op, $word); |
275
|
|
|
|
|
|
|
} |
276
|
5
|
|
|
|
|
15
|
push @stems, $word; |
277
|
|
|
|
|
|
|
} |
278
|
1
|
50
|
|
|
|
14
|
wantarray ? @stems : \@stems; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
1; |
283
|
|
|
|
|
|
|
__END__ |