line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Inflect; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
77099
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
144
|
|
4
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
126
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
258
|
|
6
|
3
|
|
|
3
|
|
3105
|
use Lingua::PT::Hyphenate; |
|
3
|
|
|
|
|
9200
|
|
|
3
|
|
|
|
|
1099
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
13
|
|
|
|
|
|
|
sing2plural |
14
|
|
|
|
|
|
|
) ] ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our @EXPORT = qw( |
19
|
|
|
|
|
|
|
sing2plural |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Lingua::PT::Inflect - Converts Portuguese words from singular to plural |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Lingua::PT::Inflect; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$plural = sing2plural('programador') # now holds 'programadores' |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Converts Portuguese words from singular to plural. There may be some |
37
|
|
|
|
|
|
|
special cases that will fail (words ending in -ão or -s might fail, as |
38
|
|
|
|
|
|
|
many special cases are yet to be prevented; anyone volunteering to |
39
|
|
|
|
|
|
|
look at a huge list of words?) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my (%exceptions,@rules,%rules); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
BEGIN { |
46
|
3
|
|
|
3
|
|
48
|
%exceptions = ( |
47
|
|
|
|
|
|
|
'lápis' => 'lápis', |
48
|
|
|
|
|
|
|
'pires' => 'pires', |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
'mão' => 'mãos', |
51
|
|
|
|
|
|
|
'afegão' => 'afegãos', |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
'pão' => 'pães', |
54
|
|
|
|
|
|
|
'capitão' => 'capitães', |
55
|
|
|
|
|
|
|
'cão' => 'cães', |
56
|
|
|
|
|
|
|
'alemão' => 'alemães', |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
292
|
@rules = map qr/$_/, qw(ás ês el ol al oi ul m ão (?<=[aeiou]) (?<=[rnsz])); |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
1067
|
%rules = ( |
62
|
|
|
|
|
|
|
qr/ás/ => 'ases', |
63
|
|
|
|
|
|
|
qr/ês/ => 'eses', |
64
|
|
|
|
|
|
|
qr/el/ => 'éis', |
65
|
|
|
|
|
|
|
qr/ol/ => 'óis', |
66
|
|
|
|
|
|
|
qr/al/ => 'ais', |
67
|
|
|
|
|
|
|
qr/oi/ => 'ois', |
68
|
|
|
|
|
|
|
qr/ul/ => 'uis', |
69
|
|
|
|
|
|
|
qr/m/ => 'ns', |
70
|
|
|
|
|
|
|
qr/ão/ => 'ões', |
71
|
|
|
|
|
|
|
qr/(?<=[aeiou])/ => 's', |
72
|
|
|
|
|
|
|
qr/(?<=[rnsz])/ => 'es', |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 new |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Creates a new Lingua::PT::Inflect object. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
If you're doing this lots of time, it would probably be better for you |
86
|
|
|
|
|
|
|
to use the sing2plural function directly (that is, creating a new |
87
|
|
|
|
|
|
|
object for each word in a long text doesn't seem so bright if you're |
88
|
|
|
|
|
|
|
not going to use it later on). |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub new { |
93
|
27
|
|
|
27
|
1
|
13845
|
my ($self, $word) = @_; |
94
|
27
|
|
|
|
|
100
|
bless \$word, $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 sing2plural |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Converts a word in the singular gender to plural. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$plural = sing2plural($singular); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub sing2plural { |
106
|
54
|
50
|
|
54
|
1
|
14450
|
defined $_[0] || return undef; |
107
|
|
|
|
|
|
|
|
108
|
54
|
|
|
|
|
62
|
my $word; |
109
|
54
|
100
|
|
|
|
125
|
if (ref($_[0]) eq 'Lingua::PT::Inflect') { |
110
|
27
|
|
|
|
|
32
|
my $self = shift; |
111
|
27
|
|
|
|
|
51
|
$word = $$self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
27
|
|
|
|
|
40
|
$word = shift; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
54
|
|
|
|
|
77
|
$_ = $word; |
118
|
|
|
|
|
|
|
|
119
|
54
|
100
|
|
|
|
150
|
defined $exceptions{$_} && return $exceptions{$_}; |
120
|
|
|
|
|
|
|
|
121
|
46
|
|
|
|
|
76
|
for my $rule (@rules) { |
122
|
406
|
100
|
|
|
|
5289
|
if (s/$rule$/$rules{$rule}/) {return $_} |
|
32
|
|
|
|
|
157
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
14
|
100
|
|
|
|
2615
|
if (/il$/) { |
126
|
8
|
|
|
|
|
41
|
my @syl = hyphenate($_); |
127
|
|
|
|
|
|
|
|
128
|
8
|
100
|
|
|
|
1153
|
s!il$!$syl[-2] =~ /[ãâáêéíóõôúÃÁÉÍÓÕÔÊÂÚ]/ ? 'eis' : 'is' !e; |
|
8
|
|
|
|
|
45
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
14
|
|
|
|
|
67
|
return $_; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
__END__ |