blib/lib/Lingua/RU/Inflect.pm

filter: Statementstmt 94.7% 145 / 153 Branchbran 84.1% 101 / 120 Conditioncond 80.0% 24 / 30 MC/DCmcdc 58.8% 10 / 17 Subroutinesub 100% 16 / 16 Podpod 100% 2 / 2 totaltotal 88.1% 298 / 338 CC 71 SCAR 37.0
CC
71
Cov
89%
_inflect_given_name
59.8
detect_gender_by_given_name
19.2
inflect_given_name
2.0
CRAP 40.6
↑ 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.06
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
26 to L<Lingua::RU::Preposition>.
27  
28 =cut
29  
30 5 our ($REVISION, $DATE);
31 5 ($REVISION) = q$Revision$ =~ /(\d+)/g;
32 5 ($DATE)
33 = q$Date$ =~ /: (\d+)\s*$/g;
34  
35  
36 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
39  
40 # set the version for version checking
41 5 $VERSION = 0.06;
42  
43 5 @ISA = qw(Exporter);
44 5 @EXPORT = qw(
45 inflect_given_name detect_gender_by_given_name
46 );
47  
48 # exported package globals
49 5 @EXPORT_OK = qw(
50 NOMINATIVE GENITIVE DATIVE
51 ACCUSATIVE INSTRUMENTAL PREPOSITIONAL
52 %CASES
53 MASCULINE FEMININE
54 );
55  
56 5 %EXPORT_TAGS = (
57 'subs' => [ qw(
58 inflect_given_name detect_gender_by_given_name
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 5 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
73 5 NOMINATIVE => -1,
74 GENITIVE => 0,
75 DATIVE => 1,
76 ACCUSATIVE => 2,
77 INSTRUMENTAL => 3,
78 PREPOSITIONAL => 4,
79 5 };
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 qw( any mesh );
Subroutine BEGIN: called CC=1 SCAR=0.0
87 5 our %CASES = mesh @CASE_NAMES, @CASE_NUMBERS;
88  
89 # Gender
90 5 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
91 5 FEMININE => 0,
92 MASCULINE => 1,
93 5 };
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 One-liners also can be used
114  
115 perl -Ilib -Mcommon::sense -MLingua::RU::Inflect=:all \
116 -E 'say join " ", inflect_given_name(GENITIVE, qw/Перец Лев Ильич/)'
117 # Перца Льва Ильича
118 # Transliteration of above line is: Pertsa L'va Il'icha
119  
120 =head1 TO DO
121  
122 1. Inflect any nouns, any words, anything...
123  
124 =head1 EXPORT
125  
126 Function C<detect_gender_by_given_name> and
127 C<detect_gender_by_given_name> are exported by default.
128  
129 Also you can export only case names:
130  
131 use Lingua::RU::Inflect qw/:cases/;
132  
133 Or only subs and genders
134  
135 use Lingua::RU::Inflect qw/:subs :genders/;
136  
137 Or everything: subs, aliases, genders and case names:
138  
139 use Lingua::RU::Inflect qw/:all/; # or
140 use Lingua::RU::Inflect qw/:cases :genders :subs/;
141  
142 =head1 FUNCTIONS
143  
144 =head2 detect_gender_by_given_name
145  
146 Try to detect gender by name. Up to three arguments expected:
147 lastname, firstname, patronym.
148  
149 Return C<MASCULINE>, C<FEMININE> for successful detection
150 or C<undef> when function can't detect gender.
151  
152 =head3 Detection rules
153  
154 When name match some rule, rest of rules are ignored.
155  
156 =over 4
157  
158 =item 1
159  
160 Patronym (russian отчество — otchestvo), if presented, gives unambiguous
161 detection rules: feminine patronyms ends with “na”, masculine ones ends
162 with “ich” and “ych”.
163  
164 =item 2
165  
166 Most of russian feminine firstnames ends to vowels “a” and “ya”.
167 Most of russian masculine firstnames ends to consonants.
168  
169 There's exists exceptions for both rules: feminine names such as russian
170 name Lubov' (Любовь) and foreign names Ruf' (Руфь), Rachil' (Рахиль)
171 etc. Masculine names also often have affectionate diminutive forms:
172 Alyosha (Алёша) for Alexey (Алексей), Kolya (Коля) for Nickolay
173 (Николай) etc. Some affectionate diminutive names are ambiguous: Sasha
174 (Саша) is diminutive name for feminine name Alexandra (Александра) and
175 for masculine name Alexander (Александр), Zhenya (Женя) is diminutive
176 name for feminine name Eugenia (Евгения) and for masculine name Eugene
177 (Евгений) etc.
178  
179 These exceptions are processed.
180  
181 When got ambiguous result, function try to use next rule.
182  
183 =item 3
184  
185 Most of russian lastnames derived from possessive nouns (and names).
186 Feminine forms of these lastnames ends to “a”.
187 Some lastnames derived from adjectives. Feminine forms of these
188 lastnames ends to “ya”.
189  
190 =back
191  
192 =cut
193  
194 103 ▶sub detect_gender_by_given_name {
Subroutine detect_gender_by_given_name: called CC=19 SCAR=29.5
Pod documented
195 103 my ( $lastname, $firstname, $patronym ) = @_;
196 103 ▶ map { $_ ||= '' } ( $lastname, $firstname, $patronym );
Condition100%2/2
$_ ||= ""
l!l
202107
MC/DC100%1/1
$_ ||= ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
197 103 my $ambiguous = 0;
198  
199 # Detect by patronym
200 # Russian
201 103 ▶ return FEMININE if $patronym =~ /на$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\x{43d}\x{430}$/ 5 98 103
202 98 ▶ return MASCULINE if $patronym =~ /[иы]ч$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /[\x{438}\x{44b}]\x{447}$/ 9 89 98
203 # Tatar and Azerbaijani
204 89 ▶ return FEMININE if $patronym =~ /\bкызы$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\b\x{43a}\x{44b}\x{437}\x{44b}$/i 2 87 89
205 87 ▶ return MASCULINE if $patronym =~ /\b(оглы|улы)$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\b(\x{43e}\x{433}\x{43b}\x{44b}|\x{443}\x{43b}\x{44b})$/i 4 83 87
206 # Icelandic
207 83 ▶ return FEMININE if $patronym =~ /доттир$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\x{434}\x{43e}\x{442}\x{442}\x{438}\x{440}$/ 1 82 83
208 82 ▶ return MASCULINE if $patronym =~ /сон$/;
Branch: 1 branch
BranchTrueFalseTotal
if $patronym =~ /\x{441}\x{43e}\x{43d}$/ 1 81 82
209  
210 # Detect by firstname
211 # Drop all names except first
212 81 $firstname =~ s/[\s\-].*//;
213  
214 # Process exceptions
215 81 ▶ return FEMININE if any { $firstname eq $_ } ( &_FEMININE_NAMES );
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $firstname eq $_; } , &_FEMININE_NAMES) 12 69 81
216 69 ▶ return MASCULINE if any { $firstname eq $_ } ( &_MASCULINE_NAMES );
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $firstname eq $_; } , &_MASCULINE_NAMES) 19 50 69
217  
218 map {
219 50 ▶ $ambiguous++ && last if $firstname eq $_;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname eq $_ 6 344 350
Condition60%3/5
$firstname eq $_ && ($ambiguous++ && (last))
!ll&&!rl&&r
34460
$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
220 } ( &_AMBIGUOUS_NAMES );
221  
222 50 ▶ unless ( $ambiguous ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ambiguous) 44 6 50
223 # Feminine firstnames ends to vowels
224 44 ▶ return FEMININE if $firstname =~ /[ая]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $firstname =~ /[\x{430}\x{44f}]$/ 7 37 44
225 # Masculine firstnames ends to consonants
226 37 ▶ 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}]$/ 37 0 37
227 } # unless
228  
229 # Detect by lastname
230 # possessive names
231 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
232 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
233 # adjectives
234 2 ▶ return FEMININE if $lastname =~ /(ая|яя)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{430}\x{44f}|\x{44f}\x{44f})$/ 0 2 2
235 2 ▶ return MASCULINE if $lastname =~ /(ий|ый)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{438}\x{439}|\x{44b}\x{439})$/ 0 2 2
236  
237 # Unknown or ambiguous name
238 2 return undef;
239 }
240  
241 =head2 _inflect_given_name
242  
243 Inflects name of given gender to given case.
244 Up to 5 arguments expected:
245 I<gender>, I<case>, I<lastname>, I<firstname>, I<patronym>.
246 I<Lastname>, I<firstname>, I<patronym> must be in Nominative.
247  
248 Returns list which contains inflected I<lastname>, I<firstname>, I<patronym>.
249  
250 =cut
251  
252 62 ▶sub _inflect_given_name {
Subroutine _inflect_given_name: called CC=52 SCAR=40.9
253 62 my $gender = shift;
254 62 my $case = shift;
255  
256 62 ▶ return @_ if $case eq NOMINATIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $case eq -1 0 62 62
257 return
258 62 ▶ if $case < GENITIVE
Branch: 1 branch
BranchTrueFalseTotal
if $case < 0 or $case > 4 0 62 62
Condition33%1/3
$case < 0 or $case > 4
l!l&&r!l&&!r
0062
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
259 || $case > PREPOSITIONAL;
260  
261 62 my ( $lastname, $firstname, $patronym ) = @_;
262 62 ▶ map { $_ ||= '' } ( $lastname, $firstname, $patronym );
Condition100%2/2
$_ ||= ""
l!l
12759
MC/DC100%1/1
$_ ||= ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
263  
264 # Patronyms
265 {
266 62 ▶ last unless $patronym;
Branch: 1 branch
BranchTrueFalseTotal
unless $patronym 55 7 62
267  
268 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
269 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
270 4 $patronym =~ s/ич$/qw(ича ичу ича ичем иче)[$case]/e;
271 4 $patronym =~ s/(Иль|Кузьм|Фом)ичем$/$1ичом/;
272 }
273  
274 # Firstnames
275 {
276 62 ▶ last unless $firstname;
Branch: 1 branch
BranchTrueFalseTotal
unless $firstname 2 60 62
277  
278 # Exceptions
279 60 $firstname =~ s/^Лев$/Льв/;
280 60 $firstname =~ s/^Павел$/Павл/;
281 60 $firstname =~ s/^Пётр$/Петр/;
282 60 $firstname =~ s/^Христос$/Христ/;
283  
284 # Names which ends to vowels “o”, “yo”, “u”, “yu”, “y”, “i”, “e”, “ye”
285 # and to pairs of vowels except “yeya”, “iya”
286 # can not be inflected
287  
288 60 ▶ 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 5 55 60
289 55 ▶ 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 55 55
290 55 ▶ 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 55 55
291 last
292 if (
293 55 ▶ !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 54 55
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
44101
not defined $gender or $gender == 0
l!l&&r!l&&!r
11044
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
294 || $gender == FEMININE
295 )
296 && $firstname =~ /[бвгджзклмнйпрстфхцчшщ]$/i;
297  
298 0 ▶ 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 54 54
299 54 ▶ 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 52 54
300 52 ▶ 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 11 41 52
301 41 ▶ 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 40 41
302 40 ▶ 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 4 36 40
303 36 ▶ 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 3 33 36
304  
305 # Same endings, but different gender
306 33 ▶ if ( $gender == MASCULINE ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($gender == 1) { } 32 1 33
elsif ($gender == 0) { } 1 0 1
307 32 ▶ 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 1 31 32
308 }
309 elsif ( $gender == FEMININE ) {
310 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
311 }
312  
313 # Rest of names which ends to consonants
314 31 $firstname .= qw(а у а ом е)[$case];
315 } # Firstnames
316  
317 # Lastnames
318 {
319 62 ▶ last unless $lastname;
Branch: 1 branch
BranchTrueFalseTotal
unless $lastname 2 60 62
320 60 ▶ last unless defined $gender;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gender 1 59 60
321  
322 # Indeclinable
323 59 ▶ 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 58 59
324 58 ▶ 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 58 58
325 # Lastnames such as “Belaya” and “Sinyaya”
326 # which ends to “aya” and “yaya” must be inflected
327 58 ▶ 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 58 58
328  
329 # Undeclinable lastnames -ikh and -ykh
330 last
331 58 ▶ if $lastname =~ /ых$/i
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /\x{44b}\x{445}$/i and not $lastname =~ /^(\x{411}\x{443}\x{43b}\x{442}|(|\x{41e}\x{442}|\x{41f}\x{435}\x{440}\x{435}|\x{420}\x{43e}\x{437})\x{434}|\x{416}\x{43c}|\x{41f})\x{44b}\x{445}$/i 2 56 58
Condition100%3/3
$lastname =~ /\x{44b}\x{445}$/i and not $lastname =~ /^(\x{411}\x{443}\x{43b}\x{442}|(|\x{41e}\x{442}|\x{41f}\x{435}\x{440}\x{435}|\x{420}\x{43e}\x{437})\x{434}|\x{416}\x{43c}|\x{41f})\x{44b}\x{445}$/i
!ll&&!rl&&r
5242
MC/DC100%2/2
$lastname =~ /\x{44b}\x{445}$/i and not $lastname =~ /^(\x{411}\x{443}\x{43b}\x{442}|(|\x{41e}\x{442}|\x{41f}\x{435}\x{440}\x{435}|\x{420}\x{43e}\x{437})\x{434}|\x{416}\x{43c}|\x{41f})\x{44b}\x{445}$/i
$lastname =~ /\x{44b}\x{445}$/i not $lastname =~ /^(\x{411}\x{443}\x{43b}\x{442}|(|\x{41e}\x{442}|\x{41f}\x{435}\x{440}\x{435}|\x{420}\x{43e}\x{437})\x{434}|\x{416}\x{43c}|\x{41f})\x{44b}\x{445}$/i
Truth table100%3/3
A and not(B)
A= $lastname =~ /\x{44b}\x{445}$/iB= not $lastname =~ /^(\x{411}\x{443}\x{43b}\x{442}|(|\x{41e}\x{442}|\x{41f}\x{435}\x{440}\x{435}|\x{420}\x{43e}\x{437})\x{434}|\x{416}\x{43c}|\x{41f})\x{44b}\x{445}$/i
ABresult
0X0
100
111
332 && $lastname !~ /^(Булт|(|От|Пере|Роз)д|Жм|П)ых$/i;
333  
334 last
335 56 ▶ if $lastname =~ /(кар|[гжкнхшщь])их$/i
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /(\x{43a}\x{430}\x{440}|[\x{433}\x{436}\x{43a}\x{43d}\x{445}\x{448}\x{449}\x{44c}])\x{438}\x{445}$/i and not $lastname =~ /^(\x{41c}\x{438}\x{43d}|\x{41c}\x{44e}\x{43d}\x{43d})\x{438}\x{445}$/ 5 51 56
Condition100%3/3
$lastname =~ /(\x{43a}\x{430}\x{440}|[\x{433}\x{436}\x{43a}\x{43d}\x{445}\x{448}\x{449}\x{44c}])\x{438}\x{445}$/i and not $lastname =~ /^(\x{41c}\x{438}\x{43d}|\x{41c}\x{44e}\x{43d}\x{43d})\x{438}\x{445}$/
!ll&&!rl&&r
5015
MC/DC100%2/2
$lastname =~ /(\x{43a}\x{430}\x{440}|[\x{433}\x{436}\x{43a}\x{43d}\x{445}\x{448}\x{449}\x{44c}])\x{438}\x{445}$/i and not $lastname =~ /^(\x{41c}\x{438}\x{43d}|\x{41c}\x{44e}\x{43d}\x{43d})\x{438}\x{445}$/
$lastname =~ /(\x{43a}\x{430}\x{440}|[\x{433}\x{436}\x{43a}\x{43d}\x{445}\x{448}\x{449}\x{44c}])\x{438}\x{445}$/i not $lastname =~ /^(\x{41c}\x{438}\x{43d}|\x{41c}\x{44e}\x{43d}\x{43d})\x{438}\x{445}$/
Truth table100%3/3
A and not(B)
A= $lastname =~ /(\x{43a}\x{430}\x{440}|[\x{433}\x{436}\x{43a}\x{43d}\x{445}\x{448}\x{449}\x{44c}])\x{438}\x{445}$/iB= not $lastname =~ /^(\x{41c}\x{438}\x{43d}|\x{41c}\x{44e}\x{43d}\x{43d})\x{438}\x{445}$/
ABresult
0X0
100
111
336 && $lastname !~ /^(Мин|Мюнн)их$/;
337 # TODO Add more German exceptions
338 # See http://wiki-de.genealogy.net/Kategorie:Familienname_mit_gleicher_Endung
339  
340 # Feminine lastnames
341 last
342 51 ▶ 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 46 51
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
4605
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
343 5 && $lastname =~ s/а$/qw(ой ой у ой ой)[$case]/e;
344 # TODO Does not process usual worls: Podkova, Sova etc
345 # TODO Decide/search what can I do with ambigous names:
346 # Kalina, Mashina, Smorodina etc
347  
348 # Rest of masculine lastnames
349 46 ▶ if ( $gender == FEMININE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gender == 0) { } 4 42 46
350 # As adjectives
351 0 ▶ 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 4 4
352 0 ▶ 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 4 4
353 }
354 else { # MASCULINE
355  
356 # Exceptions
357 42 $lastname =~ s/^Христос$/Христ/;
358 42 $lastname =~ s/([аеёиоуыэюя]л)ец$/$1ьц/i;
359 42 $lastname =~ s/([аеёиоуыэюя][бвгджзкмнйпрстфхцчшщ])ец$/$1ц/i;
360 42 $lastname =~ s/([аеёиоуыэюя])ец$/$1йц/;
361 42 $lastname =~ s/(З)аяц$/$1айц/;
362  
363 # Possessive
364 last
365 42 ▶ 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 38 42
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
3804
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
366 && ( $lastname .= qw(а у а ым е)[$case] );
367  
368 # Adjective
369 38 ▶ 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 37 38
370 0 ▶ 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 37 37
371 0 ▶ 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 37 37
372 37 ▶ 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 36 37
373  
374 # Other
375 36 ▶ last if $lastname =~ s/([гжйкхчшщ])а$/$1.qw(и е у ой е)[$case]/e;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ 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 34 36
376 34 ▶ 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 33 34
377 33 ▶ 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 32 33
378  
379 32 ▶ last if $lastname =~ /ая$/;
Branch: 1 branch
BranchTrueFalseTotal
if $lastname =~ /\x{430}\x{44f}$/ 1 31 32
380 0 ▶ 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 31 31
381 0 ▶ 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 31 31
382 0 ▶ 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 31 31
383 31 $lastname .= qw(а у а ом е)[$case];
384 } # if
385 } # Lastnames
386  
387 62 return ( $lastname, $firstname, $patronym );
388 } # sub _inflect_given_name
389  
390  
391 =head2 inflect_given_name
392  
393 Detects gender by given name and inflect parts of this name.
394  
395 Expects for up to 4 arguments:
396 I<case>, I<lastname>, I<firstname>, I<patronym>
397  
398 Available I<cases> are: C<NOMINATIVE>, C<GENITIVE>, C<DATIVE>,
399 C<ACCUSATIVE>, C<INSTRUMENTAL>, C<PREPOSITIONAL>.
400  
401 It returns list which contains
402 inflected I<lastname>, I<firstname>, I<patronym>
403  
404 =cut
405  
406 63 ▶sub inflect_given_name {
Subroutine inflect_given_name: called CC=2 SCAR=6.9
Pod documented
407 63 my $case = shift;
408 63 ▶ return @_ if $case eq NOMINATIVE;
Branch: 1 branch
BranchTrueFalseTotal
if $case eq -1 1 62 63
409 62 my @name = _inflect_given_name(
410 detect_gender_by_given_name( @_ ), $case, @_
411 );
412 } # sub inflect_given_name
413  
414  
415 # Exceptions:
416  
417 # Masculine names which ends to vowels “a” and “ya”
418 69 ▶sub _MASCULINE_NAMES () {
Subroutine _MASCULINE_NAMES: called CC=1 SCAR=0.0
419 69 return qw(
420 Аба Азарья Акива Аккужа Аникита Алёша Али Альберто Андрюха Андрюша
421 Арчи Аса
422 Байгужа Боря Бруно Вафа Вано Ваня Вася Витя Вова Володя
423 Габдулла Габидулла Гаврила Гаврило Гадельша Гайнулла Гайса Гайфулла
424 Галилео Галимша Галиулла Гарри Гата Гдалья Гийора Гиля Гога Гоша Гошеа
425 Данила Данило Данко Дарко Джанни Джеффри Джонни Джордано Джошуа Джиханша Дима
426 Жора Зайнулла Закария Зия Зосима Зхарья Зыя Зяма
427 Идельгужа Иегуда Иехуда Иешуа Изя Илия Ильмурза Илья Илюха Илюша
428 Иона Исайя Иуда Иудушка Йегошуа Йегуда Йехуда Йедидья Йося
429 Карагужа Коля Коленька Костя Кузьма Кузенька Кузя
430 Лео Лёва Лёвушка Лёха Лёша Лёшенька Луи Лука Ларри
431 Марио Марданша Метью Микола Мирза Миха Михайло Миша Мишка Мойша Моня
432 Муртаза Муса Мусса Мустафа Мэтью Нафаня Никита Никола Николя Нэта
433 Нэхэмья Овадья Отто Петя Птахья Рахматулла Риза Рома
434 Савва Садко Сафа Серёга Серёжа Сила Симха Сэадья
435 Тао Тео Тоби Товия Толя Томми
436 Федя Фима Фока Фома Фредди
437 Хамза Хананья Харви Харли Хосе Хью Хьюго Цфанья Чарли
438 Шалва Шахна Шломо Шота Шрага
439 Эзра Элайджа Элиягу Элияху Элиша Элькана Энзо Энрике Энрико Эрнесто
440 Юмагужа Юра Ярулла Яхья Яша
441 )
442 }
443  
444 # Feminine names which ends to consonants
445 81 ▶sub _FEMININE_NAMES () {
Subroutine _FEMININE_NAMES: called CC=1 SCAR=0.0
446 81 return qw(
447 Абигейл Айгуль Айгюль Айзиряк Айнур Айрис Алсу
448 Альфинур Амели Анне Асылгюль
449 Бадар Бадиян Банат Бедер Бибикамал Бибинур Брижит Бриджит
450 Гайниджамал Гайникамал Гарриет Гаухар Гиффат Грейс
451 Гузель Гулендем Гульбадиян Гульдар Гульджамал Гульджихан Гульехан
452 Гульзар Гульжан Гулькей Гульназ Гульнар Гульнур Гульсем Гульсесек
453 Гульсибар Гульчачак Гульшат Гульшаян Гульюзум Гульямал Гюзель Гюльчатай
454 Дейзи Джамал Джанет Джаухар Дженет Джихан Дильбар Диляфруз Дэйзи
455 Жанет Жульет Жюльет
456 Зайнаб Зайнап Зейнаб Зубарджат Зуберьят Изабель Ильсёяр Ингрид
457 Камяр Карасес Карин Катрин Кейт Кэролайн Кэт Кэтрин Кямар
458 Лаурелин Лили Любовь Люси Ляйсан
459 Магинур Магруй Маргарет Марго Марлен Марьям Мери Мерилин Минджихан
460 Минлегюль Миньеган Мэри
461 Наркас Натали Нинель Нурджиган Нелли Нэлли Одри Патти Пэм
462 Райхан Раушан Рахель Рахиль Рейчел Рут Руфь Рэйчел
463 Сагадат Сагдат Сарбиназ Сарвар Сафин Сахибджамал Скарлет Софи Софико
464 Суваржат Сулпан Сумбуль Сурур Сюмбель Сясак Тамар Тансулпан
465 Умегульсум Уммегюльсем
466 Фарваз Фархинур Фиби Фирдаус Флоренс Хаджар Хажар Харриет Хаят Хуршид
467 Чечек Чулпан Шамсинур
468 Эбигейл Эбигейль Эвелин Эдит Элизабет Элен Элис Элли Эмили Энн
469 Эстер Эсфирь Этель
470 Юдифь Юдит Юндуз Ямал
471 )
472 }
473  
474 # Ambiguous names which can be masculine and feminine
475 50 ▶sub _AMBIGUOUS_NAMES () {
Subroutine _AMBIGUOUS_NAMES: called CC=1 SCAR=0.0
476 50 return qw(
477 Валя Женя Мина Мишель Паша Саша Шура
478 )
479 }
480  
481 =head1 AUTHOR
482  
483 Alexander Sapozhnikov, C<< <shoorick at cpan.org> >>
484  
485 =head1 BUGS
486  
487 Please report any bugs or feature requests
488 to C<bug-lingua-ru-inflect at rt.cpan.org>, or through the web interface
489 at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lingua-RU-Inflect>.
490 I will be notified, and then
491 you'll automatically be notified of progress on your bug as I make changes.
492  
493 =head1 SUPPORT
494  
495 You can find documentation for this module with the perldoc command.
496  
497 perldoc Lingua::RU::Inflect
498  
499 You can also look for information at:
500  
501 =over 4
502  
503 =item * RT: CPAN's request tracker
504  
505 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Lingua-RU-Inflect>
506  
507 =item * AnnoCPAN: Annotated CPAN documentation
508  
509 L<http://annocpan.org/dist/Lingua-RU-Inflect>
510  
511 =item * CPAN Ratings
512  
513 L<http://cpanratings.perl.org/d/Lingua-RU-Inflect>
514  
515 =item * Search CPAN
516  
517 L<http://search.cpan.org/dist/Lingua-RU-Inflect/>
518  
519 =item * Public repository at github
520  
521 L<https://github.com/shoorick/lingua-ru-inflect>
522  
523 =back
524  
525 =head1 SEE ALSO
526  
527 Russian translation of this documentation available
528 at F<RU/Lingua/RU/Inflect.pod>
529  
530 =head1 ACKNOWLEDGEMENTS
531  
532 L<http://www.imena.org/declension.html>
533 and L<http://new.gramota.ru/spravka/letters/71-rubric-482>
534 (in Russian) for rules of declension.
535  
536 L<https://www.behindthename.com/> for directory of names.
537  
538 =head1 COPYRIGHT & LICENSE
539  
540 Copyright 2009-2018 Alexander Sapozhnikov.
541  
542 This program is free software; you can redistribute it and/or modify it
543 under the terms of either: the GNU General Public License as published
544 by the Free Software Foundation; or the Artistic License.
545  
546 See http://dev.perl.org/licenses/ for more information.
547  
548 =cut
549  
550 5 1;
↑ Summary