line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Stem::Gl; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $RCSfile: De.pm,v $ $Revision: 1.4 $ $Date: 1999/06/24 23:33:37 $ $Author: snowhare $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Lingua::Stem::Gl - Stemming algorithm for Galacian |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Lingua::Stem::Gl; |
12
|
|
|
|
|
|
|
my $stems = Lingua::Stem::Gl::stem({ -words => $word_list_reference, |
13
|
|
|
|
|
|
|
-locale => 'gl', |
14
|
|
|
|
|
|
|
-exceptions => $exceptions_hash, |
15
|
|
|
|
|
|
|
}); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This routine applies a stemming algorithm to a passed anon array of Galician words, |
20
|
|
|
|
|
|
|
returning the stemmed words as an anon array. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
It is a 'convienence' wrapper for 'Lingua::Stemmer::GL' that provides |
23
|
|
|
|
|
|
|
a standardized interface and caching. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 CHANGES |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1.02 2004.04.26 - Documenation fix |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1.01 2003.09.28 - Documentation fix |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1.00 2003.04.05 - Initial release |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
####################################################################### |
36
|
|
|
|
|
|
|
# Initialization |
37
|
|
|
|
|
|
|
####################################################################### |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
1391
|
use Lingua::GL::Stemmer; |
|
1
|
|
|
|
|
5678
|
|
|
1
|
|
|
|
|
58
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
10
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
44
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
45
|
1
|
|
|
1
|
|
5
|
use vars qw (@ISA @EXPORT_OK @EXPORT %EXPORT_TAGS $VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
113
|
|
46
|
|
|
|
|
|
|
BEGIN { |
47
|
1
|
|
|
1
|
|
18
|
@ISA = qw (Exporter); |
48
|
1
|
|
|
|
|
2
|
@EXPORT = (); |
49
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw (stem clear_stem_cache stem_caching); |
50
|
1
|
|
|
|
|
725
|
%EXPORT_TAGS = (); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
$VERSION = "1.02"; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $Stem_Caching = 0; |
55
|
|
|
|
|
|
|
my $Stem_Cache = {}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
####################################################################### |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=over 4 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item stem({ -words => \@words, -locale => 'gl', -exceptions => \%exceptions }); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Stems a list of passed words using the rules of Galican. Returns |
68
|
|
|
|
|
|
|
an anonymous list reference to the stemmed words. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Example: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $stemmed_words = Lingua::Stem::Gl::stem({ -words => \@words, |
73
|
|
|
|
|
|
|
-locale => 'gl', |
74
|
|
|
|
|
|
|
-exceptions => \%exceptions, |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=back |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub stem { |
82
|
1
|
50
|
|
1
|
1
|
5
|
return [] if ($#_ == -1); |
83
|
1
|
|
|
|
|
3
|
my $parm_ref; |
84
|
1
|
50
|
|
|
|
7
|
if (ref $_[0]) { |
85
|
1
|
|
|
|
|
2
|
$parm_ref = shift; |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
0
|
$parm_ref = { @_ }; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
3
|
my $words = []; |
91
|
1
|
|
|
|
|
2
|
my $locale = 'gl'; |
92
|
1
|
|
|
|
|
2
|
my $exceptions = {}; |
93
|
1
|
|
|
|
|
6
|
foreach (keys %$parm_ref) { |
94
|
3
|
|
|
|
|
8
|
my $key = lc ($_); |
95
|
3
|
100
|
|
|
|
13
|
if ($key eq '-words') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
96
|
1
|
|
|
|
|
2
|
@$words = @{$parm_ref->{$key}}; |
|
1
|
|
|
|
|
6
|
|
97
|
|
|
|
|
|
|
} elsif ($key eq '-exceptions') { |
98
|
1
|
|
|
|
|
4
|
$exceptions = $parm_ref->{$key}; |
99
|
|
|
|
|
|
|
} elsif ($key eq '-locale') { |
100
|
1
|
|
|
|
|
4
|
$locale = $parm_ref->{$key}; |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
0
|
croak (__PACKAGE__ . "::stem() - Unknown parameter '$key' with value '$parm_ref->{$key}'\n"); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
3
|
local $_; |
107
|
1
|
|
|
|
|
3
|
foreach (@$words) { |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Check against exceptions list |
110
|
5
|
50
|
|
|
|
119
|
if (exists $exceptions->{$_}) { |
111
|
0
|
|
|
|
|
0
|
$_ = $exceptions->{$_}; |
112
|
0
|
|
|
|
|
0
|
next; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Check against cache of stemmed words |
116
|
5
|
|
|
|
|
9
|
my $original_word = $_; |
117
|
5
|
50
|
33
|
|
|
23
|
if ($Stem_Caching && exists $Stem_Cache->{$original_word}) { |
118
|
0
|
|
|
|
|
0
|
$_ = $Stem_Cache->{$original_word}; |
119
|
0
|
|
|
|
|
0
|
next; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
5
|
|
|
|
|
28
|
($_) = Lingua::GL::Stemmer::stem("$_"); |
123
|
5
|
50
|
|
|
|
46605
|
$Stem_Cache->{$original_word} = $_ if $Stem_Caching; |
124
|
|
|
|
|
|
|
} |
125
|
1
|
50
|
|
|
|
8
|
$Stem_Cache = {} if ($Stem_Caching < 2); |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
11
|
return $words; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
############################################################## |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item stem_caching({ -level => 0|1|2 }); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Sets the level of stem caching. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
'0' means 'no caching'. This is the default level. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
'1' means 'cache per run'. This caches stemming results during a single |
141
|
|
|
|
|
|
|
call to 'stem'. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
'2' means 'cache indefinitely'. This caches stemming results until |
144
|
|
|
|
|
|
|
either the process exits or the 'clear_stem_cache' method is called. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub stem_caching { |
151
|
0
|
|
|
0
|
1
|
|
my $parm_ref; |
152
|
0
|
0
|
|
|
|
|
if (ref $_[0]) { |
153
|
0
|
|
|
|
|
|
$parm_ref = shift; |
154
|
|
|
|
|
|
|
} else { |
155
|
0
|
|
|
|
|
|
$parm_ref = { @_ }; |
156
|
|
|
|
|
|
|
} |
157
|
0
|
|
|
|
|
|
my $caching_level = $parm_ref->{-level}; |
158
|
0
|
0
|
|
|
|
|
if (defined $caching_level) { |
159
|
0
|
0
|
|
|
|
|
if ($caching_level !~ m/^[012]$/) { |
160
|
0
|
|
|
|
|
|
croak(__PACKAGE__ . "::stem_caching() - Legal values are '0','1' or '2'. '$caching_level' is not a legal value"); |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
$Stem_Caching = $caching_level; |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
return $Stem_Caching; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
############################################################## |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item clear_stem_cache; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Clears the cache of stemmed words |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub clear_stem_cache { |
180
|
0
|
|
|
0
|
1
|
|
$Stem_Cache = {}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
############################################################## |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 NOTES |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This code is a wrapper around Lingua::Stemmer::GL written by |
188
|
|
|
|
|
|
|
xern |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SEE ALSO |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Lingua::Stem Lingua::Stemmer::GL; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 AUTHOR |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Integration in Lingua::Stem by |
197
|
|
|
|
|
|
|
Benjamin Franz, FreeRun Technologies, |
198
|
|
|
|
|
|
|
snowhare@nihongo.org or http://www.nihongo.org/snowhare/ |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 COPYRIGHT |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Benjamin Franz, FreeRun Technologies |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This code is freely available under the same terms as Perl. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 BUGS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 TODO |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |