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