blib/lib/Lingua/RU/Inflect.pm

filter: Statementstmt 93.5% 130 / 139 Branchbran 81.1% 86 / 106 Conditioncond 75.0% 18 / 24 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 14 / 14 Podpod 100% 2 / 2 totaltotal 85.9% 256 / 298 CC 62 SCAR 36.8
CC
62
Cov
87%
_inflect_given_name
58.1
detect_gender_by_given_name
15.2
inflect_given_name
2.0
CRAP 39.7
↑ Summary
1 package Lingua::RU::Inflect;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =encoding utf8
8  
9 =head1 NAME
10  
11 Lingua::RU::Inflect - Inflect russian names.
12  
13 =head1 VERSION
14  
15 Version 0.05
16  
17 =head1 DESCRIPTION
18  
19 Lingua::RU::Inflect is a perl module
20 that provides Russian linguistic procedures
21 such as declension of given names (with some nouns and adjectives too),
22 and gender detection by given name.
23  
24 Choosing of proper forms of varying prepositions
25 which added in 0.02 now is unavailable because it moved to L<Lingua::RU::Preposition>.
26  
27 =cut
28  
29 5 our ($REVISION, $DATE);
30 5 ($REVISION) = q$Revision$ =~ /(\d+)/g;
31 5 ($DATE)
32 = q$Date$ =~ /: (\d+)\s*$/g;
33  
34  
35 BEGIN {
36 5 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶ our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 # set the version for version checking
40 5 $VERSION = 0.05;
41  
42 5 @ISA = qw(Exporter);
43 5 @EXPORT = qw(
44 inflect_given_name detect_gender_by_given_name
45 );
46  
47 # exported package globals
48 5 @EXPORT_OK = qw(
49 NOMINATIVE GENITIVE DATIVE
50 ACCUSATIVE INSTRUMENTAL PREPOSITIONAL
51 %CASES
52 MASCULINE FEMININE
53 );
54  
55 5 %EXPORT_TAGS = (
56 'subs' => [ qw(
57 inflect_given_name detect_gender_by_given_name
58 choose_preposition_by_next_word
59 ) ],
60 'genders' => [ qw( MASCULINE FEMININE ) ],
61 'cases' => [ qw(
62 NOMINATIVE GENITIVE DATIVE ACCUSATIVE INSTRUMENTAL PREPOSITIONAL
63 %CASES
64 ) ],
65 'all' => [ @EXPORT, @EXPORT_OK ],
66 )
67  
68 }
69  
70 # Cases
71 # Why I can't use loop?!
72 use constant {
73 5 NOMINATIVE => -1,
74 GENITIVE => 0,
75 DATIVE => 1,
76 ACCUSATIVE => 2,
77 INSTRUMENTAL => 3,
78 PREPOSITIONAL => 4,
79 5 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 5 my @CASE_NAMES = qw(
82 NOMINATIVE GENITIVE DATIVE ACCUSATIVE INSTRUMENTAL PREPOSITIONAL
83 );
84 5 my @CASE_NUMBERS = ( -1 .. 4 );
85  
86 5 ▶use List::MoreUtils 'mesh';
Subroutine BEGIN: called CC=1 SCAR=0.0
87 5 our %CASES = mesh @CASE_NAMES, @CASE_NUMBERS;
88  
89 # Gender
90 use constant {
91 5 FEMININE => 0,
92 MASCULINE => 1,
93 5 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 =head1 SYNOPSIS
96  
97 Inflects russian names which represented in UTF-8.
98  
99 Perhaps a little code snippet.
100  
101 use Lingua::RU::Inflect;
102  
103 my @name = qw/Петрова Любовь Степановна/;
104 # Transliteration of above line is: Petrova Lyubov' Stepanovna
105  
106 my $gender = detect_gender_by_given_name(@name);
107 # $gender == FEMININE
108  
109 my @genitive = inflect_given_name(GENITIVE, @name);
110 # $genitive == qw/Петровой Любови Степановны/;
111 # Transliteration of above line is: Petrovoy Lyubovi Stepanovny
112  
113 =head1 TO DO
114  
115 1. Inflect any nouns, any words, anything...
116  
117 =head1 EXPORT
118  
119 Function C<detect_gender_by_given_name> and
120 C<detect_gender_by_given_name> are exported by default.
121  
122 Also you can export only case names:
123  
124 use Lingua::RU::Inflect qw/:cases/;
125  
126 Or only subs and genders
127  
128 use Lingua::RU::Inflect qw/:subs :genders/;
129  
130 Or only short aliases for subs
131  
132 use Lingua::RU::Inflect qw/:short/;
133  
134 Or everything: subs, aliases, genders and case names:
135  
136 use Lingua::RU::Inflect qw/:all/; # or
137 use Lingua::RU::Inflect qw/:cases :genders :subs :short/;
138  
139 =head1 FUNCTIONS
140  
141 =head2 detect_gender_by_given_name
142  
143 Try to detect gender by name. Up to three arguments expected:
144 lastname, firstname, patronym.
145  
146 Return C<MASCULINE>, C<FEMININE> for successful detection
147 or C<undef> when function can't detect gender.
148  
149 =head3 Detection rules
150  
151 When name match some rule, rest of rules are ignored.
152  
153 =over 4
154  
155 =item 1
156  
157 Patronym (russian отчество — otchestvo), if presented, gives unambiguous
158 detection rules: feminine patronyms ends with “na”, masculine ones ends
159 with “ich” and “ych”.
160  
161 =item 2
162  
163 Most of russian feminine firstnames ends to vowels “a” and “ya”.
164 Most of russian masculine firstnames ends to consonants.
165  
166 There's exists exceptions for both rules: feminine names such as russian
167 name Lubov' (Любовь) and foreign names Ruf' (Руфь), Rachil' (Рахиль)
168 etc. Masculine names also often have affectionate diminutive forms:
169 Alyosha (Алёша) for Alexey (Алексей), Kolya (Коля) for Nickolay
170 (Николай) etc. Some affectionate diminutive names are ambiguous: Sasha
171 (Саша) is diminutive name for feminine name Alexandra (Александра) and
172 for masculine name Alexander (Александр), Zhenya (Женя) is diminutive
173 name for feminine name Eugenia (Евгения) and for masculine name Eugene
174 (Евгений) etc.
175  
176 These exceptions are processed.
177  
178 When got ambiguous result, function try to use next rule.
179  
180 =item 3
181  
182 Most of russian lastnames derived from possessive nouns (and names).
183 Feminine forms of these lastnames ends to “a”.
184 Some lastnames derived from adjectives. Feminine forms of these
185 lastnames ends to “ya”.
186  
187 =back
188  
189 =cut
190  
191 sub detect_gender_by_given_name {
192 44 ▶ my ( $lastname, $firstname, $patronym ) = @_;
Subroutine detect_gender_by_given_name: called CC=15 SCAR=27.2
Pod documented
193 44 ▶ map { $_ ||= '' } ( $lastname, $firstname, $patronym );
Condition100%2/2
$_ ||= ""
l!l
9240
MC/DC100%1/1
$_ ||= ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
194 44 my $ambiguous = 0;
195  
196 # Detect by patronym
197 44 ▶ return FEMININE if $patronym =~ /на$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\x{43d}\x{430}$/ 4 40 44
198 40 ▶ return MASCULINE if $patronym =~ /[иы]ч$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /[\x{438}\x{44b}]\x{447}$/ 8 32 40
199  
200 # Detect by firstname
201 # Drop all names except first
202 32 $firstname =~ s/[\s\-].*//;
203  
204 # Process exceptions
205 map {
206 32 ▶ return MASCULINE if $firstname eq $_;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname eq $_ 8 3012 3020
207 } ( &_MASCULINE_NAMES );
208  
209 map {
210 24 ▶ return FEMININE if $firstname eq $_;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname eq $_ 5 2295 2300
211 } ( &_FEMININE_NAMES );
212  
213 map {
214 19 ▶ $ambiguous++ && last if $firstname eq $_;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname eq $_ 6 108 114
Condition60%3/5
$firstname eq $_ && ($ambiguous++ && (last))
!ll&&!rl&&r
10860
$ambiguous++ and last
!ll
60
MC/DC0%0/2
$firstname eq $_ && ($ambiguous++ && (last))
$firstname eq $_ $ambiguous++
Truth table66%2/3
A && B
A= $firstname eq $_B= $ambiguous++
ABresult
0X0
100
111
215 } ( &_AMBIGUOUS_NAMES );
216  
217 19 ▶ unless ( $ambiguous ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ambiguous) 13 6 19
218 # Feminine firstnames ends to vowels
219 13 ▶ return FEMININE if $firstname =~ /[ая]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ /[\x{430}\x{44f}]$/ 5 8 13
220 # Masculine firstnames ends to consonants
221 8 ▶ return MASCULINE if $firstname !~ /[аеёиоуыэюя]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstname =~ /[\x{430}\x{435}\x{451}\x{438}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}\x{44f}]$/ 8 0 8
222 } # unless
223  
224 # Detect by lastname
225 # possessive names
226 6 ▶ return FEMININE if $lastname =~ /(ев|ин|ын|ёв|ов)а$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{435}\x{432}|\x{438}\x{43d}|\x{44b}\x{43d}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/ 2 4 6
227 4 ▶ return MASCULINE if $lastname =~ /(ев|ин|ын|ёв|ов)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{435}\x{432}|\x{438}\x{43d}|\x{44b}\x{43d}|\x{451}\x{432}|\x{43e}\x{432})$/ 2 2 4
228 # adjectives
229 2 ▶ return FEMININE if $lastname =~ /(ая|яя)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{430}\x{44f}|\x{44f}\x{44f})$/ 0 2 2
230 2 ▶ return MASCULINE if $lastname =~ /(ий|ый)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{438}\x{439}|\x{44b}\x{439})$/ 0 2 2
231  
232 # Unknown or ambiguous name
233 2 return undef;
234 }
235  
236 =head2 _inflect_given_name
237  
238 Inflects name of given gender to given case.
239 Up to 5 arguments expected:
240 I<gender>, I<case>, I<lastname>, I<firstname>, I<patronym>.
241 I<Lastname>, I<firstname>, I<patronym> must be in Nominative.
242  
243 Returns list which contains inflected I<lastname>, I<firstname>, I<patronym>.
244  
245 =cut
246  
247 sub _inflect_given_name {
248 23 ▶ my $gender = shift;
Subroutine _inflect_given_name: called CC=47 SCAR=40.6
249 23 my $case = shift;
250  
251 23 ▶ return @_ if $case eq NOMINATIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $case eq -1 0 23 23
252 return
253 23 ▶ if $case < GENITIVE
Branch: 1 branch
BranchTrueFalseTotal
if $case < 0 or $case > 4 0 23 23
Condition33%1/3
$case < 0 or $case > 4
l!l&&r!l&&!r
0023
MC/DC0%0/2
$case < 0 or $case > 4
$case < 0 $case > 4
Truth table33%1/3
A or B
A= $case < 0B= $case > 4
ABresult
1X1
011
000
254 || $case > PREPOSITIONAL;
255  
256 23 my ( $lastname, $firstname, $patronym ) = @_;
257 23 ▶ map { $_ ||= '' } ( $lastname, $firstname, $patronym );
Condition100%2/2
$_ ||= ""
l!l
4920
MC/DC100%1/1
$_ ||= ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
258  
259 # Patronyms
260 {
261 23 ▶ last unless $patronym;
Branch: 1 branch
BranchTrueFalseTotal
unless $patronym 16 7 23
262  
263 7 ▶ last if $patronym =~ s/на$/qw(ны не ну ной не)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ s/\x{43d}\x{430}$/("\x{43d}\x{44b}", "\x{43d}\x{435}", "\x{43d}\x{443}", "\x{43d}\x{43e}\x{439}", "\x{43d}\x{435}")[$case];/e 2 5 7
264 5 ▶ last if $patronym =~ s/ыч$/qw(ыча ычу ыча ычем ыче)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ s/\x{44b}\x{447}$/("\x{44b}\x{447}\x{430}", "\x{44b}\x{447}\x{443}", "\x{44b}\x{447}\x{430}", "\x{44b}\x{447}\x{435}\x{43c}", "\x{44b}\x{447}\x{435}")[$case];/e 1 4 5
265 4 $patronym =~ s/ич$/qw(ича ичу ича ичем иче)[$case]/e;
266 4 $patronym =~ s/(Иль|Кузьм|Фом)ичем$/$1ичом/;
267 }
268  
269 # Firstnames
270 {
271 23 ▶ last unless $firstname;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstname 2 21 23
272  
273 # Exceptions
274 21 $firstname =~ s/^Пётр$/Петр/;
275 21 $firstname =~ s/^Христос$/Христ/;
276  
277 # Names which ends to vowels “o”, “yo”, “u”, “yu”, “y”, “i”, “e”, “ye”
278 # and to pairs of vowels except “yeya”, “iya”
279 # can not be inflected
280  
281 21 ▶ last if $firstname =~ /[еёиоуыэю]$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ /[\x{435}\x{451}\x{438}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}]$/i 1 20 21
282 20 ▶ last if $firstname =~ /[аеёиоуыэюя]а$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ /[\x{430}\x{435}\x{451}\x{438}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}\x{44f}]\x{430}$/i 0 20 20
283 20 ▶ last if $firstname =~ /[аёоуыэюя]я$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ /[\x{430}\x{451}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}\x{44f}]\x{44f}$/i 0 20 20
284 last
285 if (
286 20 ▶ !defined $gender
Branch: 1 branch
BranchTrueFalseTotal
if !defined($gender) || $gender == 0 and $firstname =~ /[\x{431}\x{432}\x{433}\x{434}\x{436}\x{437}\x{43a}\x{43b}\x{43c}\x{43d}\x{439}\x{43f}\x{440}\x{441}\x{442}\x{444}\x{445}\x{446}\x{447}\x{448}\x{449}]$/i 1 19 20
Condition100%6/6
!defined($gender) || $gender == 0 and $firstname =~ /[\x{431}\x{432}\x{433}\x{434}\x{436}\x{437}\x{43a}\x{43b}\x{43c}\x{43d}\x{439}\x{43f}\x{440}\x{441}\x{442}\x{444}\x{445}\x{446}\x{447}\x{448}\x{449}]$/i
!ll&&!rl&&r
1181
not defined $gender or $gender == 0
l!l&&r!l&&!r
1811
MC/DC66%2/3
!defined($gender) || $gender == 0 and $firstname =~ /[\x{431}\x{432}\x{433}\x{434}\x{436}\x{437}\x{43a}\x{43b}\x{43c}\x{43d}\x{439}\x{43f}\x{440}\x{441}\x{442}\x{444}\x{445}\x{446}\x{447}\x{448}\x{449}]$/i
not defined $gender $gender == 0 $firstname =~ /[\x{431}\x{432}\x{433}\x{434}\x{436}\x{437}\x{43a}\x{43b}\x{43c}\x{43d}\x{439}\x{43f}\x{440}\x{441}\x{442}\x{444}\x{445}\x{446}\x{447}\x{448}\x{449}]$/i
Truth table80%4/5
not(A) or B and C
A= not defined $genderB= $gender == 0C= $firstname =~ /[\x{431}\x{432}\x{433}\x{434}\x{436}\x{437}\x{43a}\x{43b}\x{43c}\x{43d}\x{439}\x{43f}\x{440}\x{441}\x{442}\x{444}\x{445}\x{446}\x{447}\x{448}\x{449}]$/i
ABCresult
00X0
1X00
0100
1X11
0111
287 || $gender == FEMININE
288 )
289 && $firstname =~ /[бвгджзклмнйпрстфхцчшщ]$/i;
290  
291 19 ▶ last if $firstname =~ s/ия$/qw(ии ии ию ией ие)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{438}\x{44f}$/("\x{438}\x{438}", "\x{438}\x{438}", "\x{438}\x{44e}", "\x{438}\x{435}\x{439}", "\x{438}\x{435}")[$case];/e 0 19 19
292 19 ▶ last if $firstname =~ s/([гжйкхчшщ])а$/$1.qw(и е у ой е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/([\x{433}\x{436}\x{439}\x{43a}\x{445}\x{447}\x{448}\x{449}])\x{430}$/$1 . ("\x{438}", "\x{435}", "\x{443}", "\x{43e}\x{439}", "\x{435}")[$case];/e 2 17 19
293 17 ▶ last if $firstname =~ s/а$/qw(ы е у ой е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{430}$/("\x{44b}", "\x{435}", "\x{443}", "\x{43e}\x{439}", "\x{435}")[$case];/e 6 11 17
294 11 ▶ last if $firstname =~ s/мя$/qw(мени мени мя менем мени)[$case]/e; # common nouns such as “Imya” (Name)
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{43c}\x{44f}$/("\x{43c}\x{435}\x{43d}\x{438}", "\x{43c}\x{435}\x{43d}\x{438}", "\x{43c}\x{44f}", "\x{43c}\x{435}\x{43d}\x{435}\x{43c}", "\x{43c}\x{435}\x{43d}\x{438}")[$case];/e 1 10 11
295 10 ▶ last if $firstname =~ s/я$/qw(и е ю ей е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{44f}$/("\x{438}", "\x{435}", "\x{44e}", "\x{435}\x{439}", "\x{435}")[$case];/e 3 7 10
296 7 ▶ last if $firstname =~ s/й$/qw(я ю я ем е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{439}$/("\x{44f}", "\x{44e}", "\x{44f}", "\x{435}\x{43c}", "\x{435}")[$case];/e 1 6 7
297  
298 # Same endings, but different gender
299 6 ▶ if ( $gender == MASCULINE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($gender == 1) { } 5 1 6
elsif ($gender == 0) { } 1 0 1
300 5 ▶ last if $firstname =~ s/ь$/qw(я ю я ем е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{44c}$/("\x{44f}", "\x{44e}", "\x{44f}", "\x{435}\x{43c}", "\x{435}")[$case];/e 0 5 5
301 }
302 elsif ( $gender == FEMININE ) {
303 1 ▶ last if $firstname =~ s/ь$/qw(и и ь ью и)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ s/\x{44c}$/("\x{438}", "\x{438}", "\x{44c}", "\x{44c}\x{44e}", "\x{438}")[$case];/e 1 0 1
304 }
305  
306 # Rest of names which ends to consonants
307 5 $firstname .= qw(а у а ом е)[$case];
308 } # Firstnames
309  
310 # Lastnames
311 {
312 23 ▶ last unless $lastname;
Branch: 1 branch
BranchTrueFalseTotal
unless $lastname 2 21 23
313 21 ▶ last unless defined $gender;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gender 1 20 21
314  
315 # Exception
316 20 $lastname =~ s/^Христос$/Христ/;
317  
318 # Indeclinable
319 20 ▶ last if $lastname =~ /[еёиоуыэю]$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /[\x{435}\x{451}\x{438}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}]$/i 1 19 20
320 19 ▶ last if $lastname =~ /[аеёиоуыэюя]а$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /[\x{430}\x{435}\x{451}\x{438}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}\x{44f}]\x{430}$/i 0 19 19
321 # Lastnames such as “Belaya” and “Sinyaya”
322 # which ends to “aya” and “yaya” must be inflected
323 19 ▶ last if $lastname =~ /[ёоуыэю]я$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /[\x{451}\x{43e}\x{443}\x{44b}\x{44d}\x{44e}]\x{44f}$/i 0 19 19
324 19 ▶ last if $lastname =~ /[иы]х$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /[\x{438}\x{44b}]\x{445}$/i 1 18 19
325  
326 # Feminine lastnames
327 last
328 18 ▶ if $lastname =~ /(ин|ын|ев|ёв|ов)а$/
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/ and $lastname =~ s/\x{430}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e 5 13 18
Condition66%2/3
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/ and $lastname =~ s/\x{430}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e
!ll&&!rl&&r
1305
MC/DC50%1/2
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/ and $lastname =~ s/\x{430}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/ $lastname =~ s/\x{430}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e
Truth table66%2/3
A and B
A= $lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})\x{430}$/B= $lastname =~ s/\x{430}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e
ABresult
0X0
100
111
329 5 && $lastname =~ s/а$/qw(ой ой у ой ой)[$case]/e;
330 # TODO Does not process usual worls: Podkova, Sova etc
331 # TODO Decide/search what can I do with ambigous names: Mashina, Vagina etc
332  
333 # And masculine ones
334 last
335 13 ▶ if $lastname =~ /(ин|ын|ев|ёв|ов)$/
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})$/ and $lastname .= ("\x{430}", "\x{443}", "\x{430}", "\x{44b}\x{43c}", "\x{435}")[$case] 4 9 13
Condition66%2/3
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})$/ and $lastname .= ("\x{430}", "\x{443}", "\x{430}", "\x{44b}\x{43c}", "\x{435}")[$case]
!ll&&!rl&&r
904
MC/DC50%1/2
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})$/ and $lastname .= ("\x{430}", "\x{443}", "\x{430}", "\x{44b}\x{43c}", "\x{435}")[$case]
$lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})$/ $lastname .= ("\x{430}", "\x{443}", "\x{430}", "\x{44b}\x{43c}", "\x{435}")[$case]
Truth table66%2/3
A and B
A= $lastname =~ /(\x{438}\x{43d}|\x{44b}\x{43d}|\x{435}\x{432}|\x{451}\x{432}|\x{43e}\x{432})$/B= $lastname .= ("\x{430}", "\x{443}", "\x{430}", "\x{44b}\x{43c}", "\x{435}")[$case]
ABresult
0X0
100
111
336 && ( $lastname .= qw(а у а ым е)[$case] );
337  
338 # As adjectives
339 9 ▶ last if $lastname =~ s/ая$/qw(ой ой ую ой ой)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{430}\x{44f}$/("\x{43e}\x{439}", "\x{43e}\x{439}", "\x{443}\x{44e}", "\x{43e}\x{439}", "\x{43e}\x{439}")[$case];/e 0 9 9
340 9 ▶ last if $lastname =~ s/яя$/qw(ей ей юю ей ей)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{44f}\x{44f}$/("\x{435}\x{439}", "\x{435}\x{439}", "\x{44e}\x{44e}", "\x{435}\x{439}", "\x{435}\x{439}")[$case];/e 0 9 9
341 9 ▶ last if $lastname =~ s/кий$/qw(кого кому кого ким ком)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{43a}\x{438}\x{439}$/("\x{43a}\x{43e}\x{433}\x{43e}", "\x{43a}\x{43e}\x{43c}\x{443}", "\x{43a}\x{43e}\x{433}\x{43e}", "\x{43a}\x{438}\x{43c}", "\x{43a}\x{43e}\x{43c}")[$case];/e 1 8 9
342 8 ▶ last if $lastname =~ s/ий$/qw(его ему его им ем)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{438}\x{439}$/("\x{435}\x{433}\x{43e}", "\x{435}\x{43c}\x{443}", "\x{435}\x{433}\x{43e}", "\x{438}\x{43c}", "\x{435}\x{43c}")[$case];/e 0 8 8
343 8 ▶ last if $lastname =~ s/ый$/qw(ого ому ого ым ом)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{44b}\x{439}$/("\x{43e}\x{433}\x{43e}", "\x{43e}\x{43c}\x{443}", "\x{43e}\x{433}\x{43e}", "\x{44b}\x{43c}", "\x{43e}\x{43c}")[$case];/e 0 8 8
344 8 ▶ last if $lastname =~ s/ой$/qw(ого ому ого ым ом)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{43e}\x{439}$/("\x{43e}\x{433}\x{43e}", "\x{43e}\x{43c}\x{443}", "\x{43e}\x{433}\x{43e}", "\x{44b}\x{43c}", "\x{43e}\x{43c}")[$case];/e 1 7 8
345  
346 # Rest of masculine lastnames
347 7 ▶ if ( $gender == MASCULINE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gender == 1) 5 2 7
348 5 ▶ last if $lastname =~ s/а$/qw(ы е у ой е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{430}$/("\x{44b}", "\x{435}", "\x{443}", "\x{43e}\x{439}", "\x{435}")[$case];/e 1 4 5
349 4 ▶ last if $lastname =~ s/мя$/qw(мени мени мя менем мени)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{43c}\x{44f}$/("\x{43c}\x{435}\x{43d}\x{438}", "\x{43c}\x{435}\x{43d}\x{438}", "\x{43c}\x{44f}", "\x{43c}\x{435}\x{43d}\x{435}\x{43c}", "\x{43c}\x{435}\x{43d}\x{438}")[$case];/e 1 3 4
350 3 ▶ last if $lastname =~ s/я$/qw(и е ю ёй е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{44f}$/("\x{438}", "\x{435}", "\x{44e}", "\x{451}\x{439}", "\x{435}")[$case];/e 0 3 3
351 3 ▶ last if $lastname =~ s/й$/qw(я ю й ем е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{439}$/("\x{44f}", "\x{44e}", "\x{439}", "\x{435}\x{43c}", "\x{435}")[$case];/e 0 3 3
352 3 ▶ last if $lastname =~ s/ь$/qw(я ю я ем е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ s/\x{44c}$/("\x{44f}", "\x{44e}", "\x{44f}", "\x{435}\x{43c}", "\x{435}")[$case];/e 0 3 3
353 3 $lastname .= qw(а у а ом е)[$case];
354 } # if
355 } # Lastnames
356  
357 23 return ( $lastname, $firstname, $patronym );
358 } # sub _inflect_given_name
359  
360  
361 =head2 inflect_given_name
362  
363 Detects gender by given name and inflect parts of this name.
364  
365 Expects for up to 4 arguments:
366 I<case>, I<lastname>, I<firstname>, I<patronym>
367  
368 Available I<cases> are: C<NOMINATIVE>, C<GENITIVE>, C<DATIVE>,
369 C<ACCUSATIVE>, C<INSTRUMENTAL>, C<PREPOSITIONAL>.
370  
371 It returns list which contains
372 inflected I<lastname>, I<firstname>, I<patronym>
373  
374 =cut
375  
376 sub inflect_given_name {
377 24 ▶ my $case = shift;
Subroutine inflect_given_name: called CC=2 SCAR=6.9
Pod documented
378 24 ▶ return @_ if $case eq NOMINATIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $case eq -1 1 23 24
379 23 my @name = _inflect_given_name(
380 detect_gender_by_given_name( @_ ), $case, @_
381 );
382 } # sub inflect_given_name
383  
384  
385 # Exceptions:
386  
387 # Masculine names which ends to vowels “a” and “ya”
388 sub _MASCULINE_NAMES () {
389 32 ▶ return qw(
Subroutine _MASCULINE_NAMES: called CC=1 SCAR=0.0
390 Аба Азарья Акива Аккужа Аникита Алёша Андрюха Андрюша Аса Байгужа Боря
391 Вафа Ваня Вася Витя Вова Володя Габдулла Габидулла Гаврила Гадельша
392 Гайнулла Гайса Гайфулла Галиулла Гарри Гата Гдалья Гийора Гиля Гога Гоша Гошеа
393 Данила Джиханша Дима Жора Зайнулла Закария Зия Зосима Зхарья Зыя Идельгужа
394 Иешуа Изя Ильмурза Илья Иона Исайя Иуда Йегошуа Йегуда Йедидья Карагужа Коля
395 Костя Кузьма Лёва Лёха Лёша Лука Ларри Марданша Микола Мирза Миха Миша Мойша Моня
396 Муртаза Муса Мусса Мустафа Никита Нэта Нэхэмья Овадья Петя Птахья
397 Рахматулла Риза Рома Савва Сафа Серёга Серёжа Сила Симха Сэадья Товия
398 Толя Федя Фима Фока Фома Хамза Хананья Цфанья Шалва Шахна Шрага Эзра
399 Элиша Элькана Юмагужа Юра Ярулла Яхья Яша
400 )
401 }
402  
403 # Feminine names which ends to consonants
404 sub _FEMININE_NAMES () {
405 24 ▶ return qw(
Subroutine _FEMININE_NAMES: called CC=1 SCAR=0.0
406 Айгуль Айгюль Айзиряк Айрис Альфинур Асылгюль Бадар Бадиян Банат Бедер
407 Бибикамал Бибинур Гайниджамал Гайникамал Гаухар Гиффат Гулендем
408 Гульбадиян Гульдар Гульджамал Гульджихан Гульехан Гульзар Гулькей
409 Гульназ Гульнар Гульнур Гульсем Гульсесек Гульсибар Гульчачак Гульшат
410 Гульшаян Гульюзум Гульямал Гюзель Джамал Джаухар Джихан Дильбар Диляфруз
411 Зайнаб Зайнап Зейнаб Зубарджат Зуберьят Ильсёяр Камяр Карасес Кейт
412 Кэролайн Кэт Кэтрин Кямар Любовь Ляйсан Магинур Магруй Марьям Минджихан
413 Минлегюль Миньеган Наркас Нинель Нурджиган Райхан Раушан Рахель Рахиль
414 Рут Руфь Рэйчел Сагадат Сагдат Сарбиназ Сарвар Сафин Сахибджамал Сулпан
415 Сумбуль Сурур Сюмбель Сясак Тамар Тансулпан Умегульсум Уммегюльсем
416 Фарваз Фархинур Фирдаус Хаджар Хажар Хаят Хуршид Чечек Чулпан Шамсинур
417 Элис Энн Юдифь Юндуз Ямал
418 )
419 }
420  
421 # Ambiguous names which can be masculine and feminine
422 sub _AMBIGUOUS_NAMES () {
423 19 ▶ return qw(
Subroutine _AMBIGUOUS_NAMES: called CC=1 SCAR=0.0
424 Валя Женя Мина Паша Саша Шура
425 )
426 }
427  
428 =head1 AUTHOR
429  
430 Alexander Sapozhnikov, C<< <shoorick at cpan.org> >>
431  
432 =head1 BUGS
433  
434 Please report any bugs or feature requests
435 to C<bug-lingua-ru-inflect at rt.cpan.org>, or through the web interface
436 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-RU-Inflect>.
437 I will be notified, and then
438 you'll automatically be notified of progress on your bug as I make changes.
439  
440 =head1 SUPPORT
441  
442 You can find documentation for this module with the perldoc command.
443  
444 perldoc Lingua::RU::Inflect
445  
446 You can also look for information at:
447  
448 =over 4
449  
450 =item * RT: CPAN's request tracker
451  
452 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lingua-RU-Inflect>
453  
454 =item * AnnoCPAN: Annotated CPAN documentation
455  
456 L<http://annocpan.org/dist/Lingua-RU-Inflect>
457  
458 =item * CPAN Ratings
459  
460 L<http://cpanratings.perl.org/d/Lingua-RU-Inflect>
461  
462 =item * Search CPAN
463  
464 L<http://search.cpan.org/dist/Lingua-RU-Inflect/>
465  
466 =item * Public repository at github
467  
468 L<https://github.com/shoorick/lingua-ru-inflect>
469  
470 =back
471  
472 =head1 SEE ALSO
473  
474 Russian translation of this documentation available
475 at F<RU/Lingua/RU/Inflect.pod>
476  
477 =head1 ACKNOWLEDGEMENTS
478  
479 L<http://www.imena.org/declension.html> (in Russian) for rules of declension.
480  
481 =head1 COPYRIGHT & LICENSE
482  
483 Copyright 2009-2014 Alexander Sapozhnikov.
484  
485 This program is free software; you can redistribute it and/or modify it
486 under the terms of either: the GNU General Public License as published
487 by the Free Software Foundation; or the Artistic License.
488  
489 See http://dev.perl.org/licenses/ for more information.
490  
491 =cut
492  
493 5 1;
↑ Summary