line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Inflect;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
159216
|
use 5.006;
|
|
3
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict;
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
78
|
|
5
|
3
|
|
|
3
|
|
17
|
use warnings;
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
98
|
|
6
|
3
|
|
|
3
|
|
1580
|
use Lingua::PT::Hyphenate;
|
|
3
|
|
|
|
|
5211
|
|
|
3
|
|
|
|
|
947
|
|
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.08';
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=encoding latin1
|
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
|
|
50
|
%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
|
|
|
|
|
240
|
@rules = map qr/$_/, qw(ás ês el ol al oi ul m ão (?<=[aeiou]) (?<=[rnsz]));
|
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
1116
|
%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 C object.
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
If you're doing this lots of time, it would probably be better for you
|
88
|
|
|
|
|
|
|
to use the C 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
|
14719
|
my ($self, $word) = @_;
|
96
|
27
|
|
|
|
|
85
|
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
|
13812
|
defined $_[0] || return undef;
|
109
|
|
|
|
|
|
|
|
110
|
54
|
|
|
|
|
81
|
my $word;
|
111
|
54
|
100
|
|
|
|
141
|
if (ref($_[0]) eq 'Lingua::PT::Inflect') {
|
112
|
27
|
|
|
|
|
43
|
my $self = shift;
|
113
|
27
|
|
|
|
|
56
|
$word = $$self;
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
else {
|
116
|
27
|
|
|
|
|
47
|
$word = shift;
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
54
|
|
|
|
|
103
|
$_ = $word;
|
120
|
|
|
|
|
|
|
|
121
|
54
|
100
|
|
|
|
149
|
defined $exceptions{$_} && return $exceptions{$_};
|
122
|
|
|
|
|
|
|
|
123
|
46
|
|
|
|
|
93
|
for my $rule (@rules) {
|
124
|
406
|
100
|
|
|
|
3663
|
if (s/$rule$/$rules{$rule}/) {return $_}
|
|
32
|
|
|
|
|
171
|
|
125
|
|
|
|
|
|
|
}
|
126
|
|
|
|
|
|
|
|
127
|
14
|
100
|
|
|
|
64
|
if (/il$/) {
|
128
|
8
|
|
|
|
|
41
|
my @syl = hyphenate($_);
|
129
|
|
|
|
|
|
|
|
130
|
8
|
100
|
|
|
|
822
|
s!il$!$syl[-2] =~ /[ãâáêéíóõôúÃÁÉÍÓÕÔÊÂÚ]/ ? 'eis' : 'is' !e;
|
|
8
|
|
|
|
|
40
|
|
131
|
|
|
|
|
|
|
}
|
132
|
|
|
|
|
|
|
|
133
|
14
|
|
|
|
|
67
|
return $_;
|
134
|
|
|
|
|
|
|
}
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1;
|
137
|
|
|
|
|
|
|
__END__
|