blib/lib/Geo/Names/Russian.pm

filter: Statementstmt 90.5% 105 / 116 Branchbran 85.4% 41 / 48 Conditioncond 83.3% 60 / 72 MC/DCmcdc 52.9% 18 / 34 Subroutinesub 92.8% 13 / 14 Podpod 100% 3 / 3 totaltotal 83.6% 240 / 287 CC 57 SCAR 33.9
CC
57
Cov
87%
streetname_split
43.3
streetname_keystring
15.2
housenumber_keystring
6.0
CRAP 29.6
↑ Summary
1 #
2 # $Id:$
3 #
4  
5 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 package Geo::Names::Russian;
12 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 $Geo::Names::Russian::VERSION = '0.02';
14 }
15 # ABSTRACT: parse and split russian geographical names
16  
17  
18 =head1 NAME
19  
20 Geo::Names::Russian - parse and split russian geographical names
21  
22 =head1 VERSION
23  
24 version 0.02
25  
26 =head1 SYNOPSIS
27  
28 use Geo::Names::Russian qw{ :all };
29  
30 for my $street ( @streetnames )
31 $count{ streetname_keystring( $street ) } ++;
32 }
33  
34 =cut
35  
36  
37 2 ▶use base qw{ Exporter };
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 our @EXPORT_OK = qw{
40 streetname_split
41 streetname_keystring
42 housenumber_keystring
43 };
44  
45 2 our %EXPORT_TAGS = (
46 all => \@EXPORT_OK,
47 );
48  
49  
50  
51 2 ▶use List::MoreUtils qw{ any first_index };
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53  
54  
55 2 my @statuses = (
56 [ 'улица' => 'ул' ],
57 [ 'переулок' => 'пер(?:еул)?|пу' ],
58 [ 'проспект' => 'пр(?:-к?т|осп)' ],
59 [ 'проезд' => 'пр(?:-з?д)?' ],
60 [ 'площадь' => 'пл' ],
61 [ 'шоссе' => 'ш' ],
62 [ 'тупик' => 'туп' ],
63 [ 'бульвар' => 'б(?:ул|ульв|-р)' ],
64 [ 'набережная' => 'наб' ],
65 [ 'аллея' => 'ал' ],
66 [ 'мост' => 'м' ],
67 [ 'тракт' => 'тр' ],
68 [ 'просек' => 'прос' ],
69 [ 'линия' => 'лин' ],
70 [ 'дорога' => 'дор' ],
71 [ 'квартал' => 'кв(?:арт|-?л)?' ],
72 [ 'микрорайон' => 'мк?рн?' ],
73 [ 'территория' => 'тер' ],
74 [ 'посёлок' => 'пос(?:[её]лок)?|р?п'],
75 [ 'городок' => 'гор' ],
76 [ 'станция' => 'ст(?:анц)?' ],
77 [ 'хутор' => 'х(?:ут)' ],
78 [ 'разъезд' => 'р(?:аз)-д|рзд' ],
79 [ 'казарма' => 'каз' ],
80 [ 'парк' => 'парк' ],
81 [ 'деревня' => 'дер' ],
82 );
83  
84 2 for my $rec ( @statuses ) {
85 52 $rec->[1] = qr{ ^ (?: $rec->[0] | $rec->[1] ) \.? $ }ixms;
86 }
87  
88  
89 2 my @addition_words = (
90 [ 'Ниж' => 'Н\.?|НИЖН(?:\.|ИЙ|ЕЕ|ЯЯ)' ],
91 [ 'Сред' => 'СР\.?|СРЕДН(?:\.|ИЙ|ЕЕ|ЯЯ)'],
92 [ 'Верх' => 'В\.?|ВЕРХН?(?:\.|ИЙ|ЕЕ|ЯЯ)'],
93 [ 'Стар' => 'СТ\.?|СТАР(?:ЫЙ|АЯ|ОЕ|\.)' ],
94 [ 'Нов' => 'НОВ(?:АЯ|ЫЙ|ОЕ|\.)' ],
95 [ 'Мал' => 'М\.?|МАЛ(?:АЯ|ЫЙ|ОЕ|\.)' ],
96 [ 'Бол' => 'Б\.?|БОЛЬШ(?:АЯ|ОЙ|ОЕ|\.)' ],
97 );
98  
99 2 for my $rec ( @addition_words ) {
100 14 $rec->[1] = qr{ ^ (?: $rec->[0] \.? | $rec->[1] ) $ }ixms;
101 }
102  
103  
104 2 my @prof_words = qw{
105 академика профессора
106 архитектора
107 композитора
108 летчика лётчика
109 милиционера
110 командира комиссара политрука
111 снайпера танкиста
112 сержанта лейтенанта капитана
113 подполковника полковника
114 адмирала генерала маршала
115 };
116  
117 =head1 FUNCTIONS
118  
119 =head2 streetname_split
120  
121 Splits streetname into meaningful parts
122  
123 my $street = '2-я Тверская-Ямская ул.';
124 my ( $status, $name, $addition, $number, $km ) = streetname_split( $street );
125 # ( 'улица', 'Тверская-Ямская', '', '2-я', '' )
126  
127 =cut
128  
129 25 ▶sub streetname_split {
Subroutine streetname_split: called CC=42 SCAR=37.7
Pod documented
130  
131 25 my ( $name ) = @_;
132 25 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 25 25
133  
134  
135 25 $name =~ s/ ( No? | № ) \s* (?=\d) /$1/gix;
136  
137 # делим строку на слова
138 25 my @words = grep {$_} split / \s+ | (?<=[.,]) \s* /x, $name;
139  
140 # прицепляем инициалы к фамилии
141 25 for my $i ( reverse 0 .. $#words-1 ) {
142 50 ▶ next unless $words[$i] =~ / ^ \p{IsUpper} \.? $ /xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $words[$i] =~ / ^ \p{IsUpper} \.? $ /msx 43 7 50
143 7 ▶ next if $words[$i+1] && $words[$i+1] =~ / (?: [ыи]й | я ) $ /xms; # тут вряд ли инициалы
Branch: 1 branch
BranchTrueFalseTotal
if $words[$i + 1] and $words[$i + 1] =~ / (?: [\x{44b}\x{438}]\x{439} | \x{44f} ) $ /msx 2 5 7
Condition66%2/3
$words[$i + 1] and $words[$i + 1] =~ / (?: [\x{44b}\x{438}]\x{439} | \x{44f} ) $ /msx
!ll&&!rl&&r
052
MC/DC50%1/2
$words[$i + 1] and $words[$i + 1] =~ / (?: [\x{44b}\x{438}]\x{439} | \x{44f} ) $ /msx
$words[$i + 1] $words[$i + 1] =~ / (?: [\x{44b}\x{438}]\x{439} | \x{44f} ) $ /msx
Truth table66%2/3
A and B
A= $words[$i + 1]B= $words[$i + 1] =~ / (?: [\x{44b}\x{438}]\x{439} | \x{44f} ) $ /msx
ABresult
0X0
100
111
144 5 ▶ $words[$i] .= q{.} unless $words[$i] =~ /\.$/xms;
Branch: 1 branch
BranchTrueFalseTotal
unless $words[$i] =~ /\.$/msx 0 5 5
145 5 $words[$i] .= splice @words, $i+1, 1;
146 }
147 # и переносим их в конец
148 25 for my $word ( @words ) {
149 70 $word =~ s/ ^ ( (?:\p{Alpha}\.)+ ) ( \p{Alpha}{3,} ) $ /$2 $1/xms;
150 }
151  
152 # вытаскиваем километр
153 25 my $km = q{};
154 25 my $km_re = qr{ km | км | километр }xi;
155 25 for my $i ( 1 .. $#words ) {
156 45 ▶ if ( @words > 2 && $words[$i-1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /xms && $words[$i] =~ / ^ $km_re $ /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 2 and $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msx and $words[$i] =~ / ^ $km_re $ /msx) 3 42 45
Condition100%6/6
@words > 2 and $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msx and $words[$i] =~ / ^ $km_re $ /msx
!ll&&!rl&&r
29133
@words > 2 and $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msx
!ll&&!rl&&r
101916
MC/DC100%3/3
@words > 2 and $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msx and $words[$i] =~ / ^ $km_re $ /msx
@words > 2 $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msx $words[$i] =~ / ^ $km_re $ /msx
Truth table100%4/4
A and B and C
A= @words > 2B= $words[$i - 1] =~ / ^ \d+ (?: -? \S{1,3} )? $ /msxC= $words[$i] =~ / ^ $km_re $ /msx
ABCresult
0XX0
10X0
1100
1111
157 3 $km = join q{ }, splice @words, $i-1, 2;
158 3 last;
159 }
160 42 ▶ if ( my @res = $words[$i] =~ / ^ (\d+) ($km_re) $ /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@res) = $words[$i] =~ / ^ (\d+) ($km_re) $ /msx) 1 41 42
161 1 $km = join q{ }, @res;
162 1 splice @words, $i, 1;
163 1 last;
164 }
165 }
166  
167 # вычленяем статус
168 25 my $status;
169 25 ▶ if ( @words > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 1) 24 1 25
170 24 for my $rec ( @statuses ) {
171 378 ▶ my $i = first_index { $_ =~ $rec->[1] } @words;
Subroutine __ANON__: called CC=1 SCAR=0.0
172 378 ▶ next if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 366 12 378
173 12 $status = $rec->[0];
174 12 splice @words, $i, 1;
175 12 last;
176 }
177 }
178
179 # вытаскиваем правильно заданный номер
180 25 my $number = q{};
181 25 for my $i ( 0 .. $#words ) {
182 42 ▶ last if @words < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @words < 2 5 37 42
183 next unless
184 37 ▶ ( !$status || $status =~ /[аяь]$/ixms ) && $words[$i] =~ m{ ^ \d{1,2} -? а?я $ }ixms # женский род
Branch: 1 branch
BranchTrueFalseTotal
unless !$status || $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx or $status and $status =~ /[\x{435}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx or $status and $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx 32 5 37
Condition83%20/24
!$status || $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx or $status and $status =~ /[\x{435}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx or $status and $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx
l!l&&r!l&&!r
3232
!$status || $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx or $status and $status =~ /[\x{435}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx
l!l&&r!l&&!r
3034
!$status || $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx
!ll&&!rl&&r
4303
not $status or $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx
l!l&&r!l&&!r
2674
$status and $status =~ /[\x{435}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx
!ll&&!rl&&r
3400
$status and $status =~ /[\x{435}]$/imsx
!ll&&!rl&&r
2680
$status and $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx
!ll&&!rl&&r
3022
$status and $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx
!ll&&!rl&&r
2644
MC/DC33%3/9
!$status || $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx or $status and $status =~ /[\x{435}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx or $status and $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx and $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx
not $status $status =~ /[\x{430}\x{44f}\x{44c}]$/imsx $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsx $status $status =~ /[\x{435}]$/imsx $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsx $status $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsx $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx
Truth table12%5/41
not(A) or B and C or D and E and F or G and H and I
A= not $statusB= $status =~ /[\x{430}\x{44f}\x{44c}]$/imsxC= $words[$i] =~ / ^ \d{1,2} -? \x{430}?\x{44f} $ /imsxD= $statusE= $status =~ /[\x{435}]$/imsxF= $words[$i] =~ / ^ \d{1,2} -? \x{43e}?\x{435} $ /imsxG= $statusH= $status =~ /[^\x{435}\x{430}\x{44f}\x{44c}]$/imsxI= $words[$i] =~ / ^ \d{1,2} -? [\x{44b}\x{438}\x{43e}]?\x{439} $ /imsx
ABCDEFGHIresult
1X1XXXXXX1
011XXXXXX1
00X111XXX1
1X0111XXX1
010111XXX1
00X0XX1111
00X10X1111
00X1101111
1X00XX1111
1X010X1111
1X01101111
0100XX1111
01010X1111
0101101111
00X0XX0XX0
00X0XX10X0
00X0XX1100
00X10X0XX0
00X10X10X0
00X10X1100
00X1100XX0
00X11010X0
00X1101100
1X00XX0XX0
1X00XX10X0
1X00XX1100
1X010X0XX0
1X010X10X0
1X010X1100
1X01100XX0
1X011010X0
1X01101100
0100XX0XX0
0100XX10X0
0100XX1100
01010X0XX0
01010X10X0
01010X1100
0101100XX0
01011010X0
0101101100
185 || $status && $status =~ /[е]$/ixms && $words[$i] =~ m{ ^ \d{1,2} -? о?е $ }ixms # средний
186 || $status && $status =~ /[^еаяь]$/ixms && $words[$i] =~ m{ ^ \d{1,2} -? [ыио]?й $ }ixms; # мужской
187 5 $number = lc $words[$i];
188 5 splice @words, $i, 1;
189 5 last;
190 }
191  
192 # пробуем вытащить кривой номер
193 25 ▶ if ( @words > 1 && !$number
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 1 and not $number and $words[0] =~ / ^ \d{1,2} $ /msx and $words[-1] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx) 2 23 25
Condition100%9/9
@words > 1 and not $number and $words[0] =~ / ^ \d{1,2} $ /msx and $words[-1] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
!ll&&!rl&&r
2122
@words > 1 and not $number and $words[0] =~ / ^ \d{1,2} $ /msx
!ll&&!rl&&r
10114
@words > 1 and not $number
!ll&&!rl&&r
7315
MC/DC100%4/4
@words > 1 and not $number and $words[0] =~ / ^ \d{1,2} $ /msx and $words[-1] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
@words > 1 not $number $words[0] =~ / ^ \d{1,2} $ /msx $words[-1] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
Truth table100%5/5
A and not(B) and C and D
A= @words > 1B= not $numberC= $words[0] =~ / ^ \d{1,2} $ /msxD= $words[-1] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
ABCDresult
0XXX0
10XX0
110X0
11100
11111
194 && $words[0] =~ / ^ \d{1,2} $ /xms
195 && $words[-1] =~ / (?: [ая]я | [ыи]й ) $ /xms ) {
196 2 $number = shift @words;
197 }
198 25 ▶ if ( @words > 1 && !$number
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 1 and not $number and $words[-1] =~ / ^ \d{1,2} $ /msx and $words[-2] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx) 0 25 25
Condition66%6/9
@words > 1 and not $number and $words[-1] =~ / ^ \d{1,2} $ /msx and $words[-2] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
!ll&&!rl&&r
2500
@words > 1 and not $number and $words[-1] =~ / ^ \d{1,2} $ /msx
!ll&&!rl&&r
12130
@words > 1 and not $number
!ll&&!rl&&r
9313
MC/DC0%0/4
@words > 1 and not $number and $words[-1] =~ / ^ \d{1,2} $ /msx and $words[-2] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
@words > 1 not $number $words[-1] =~ / ^ \d{1,2} $ /msx $words[-2] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
Truth table60%3/5
A and not(B) and C and D
A= @words > 1B= not $numberC= $words[-1] =~ / ^ \d{1,2} $ /msxD= $words[-2] =~ / (?: [\x{430}\x{44f}]\x{44f} | [\x{44b}\x{438}]\x{439} ) $ /msx
ABCDresult
0XXX0
10XX0
110X0
11100
11111
199 && $words[-1] =~ / ^ \d{1,2} $ /xms
200 && $words[-2] =~ / (?: [ая]я | [ыи]й ) $ /xms ) {
201 0 $number = pop @words;
202 }
203  
204 # вытаскиваем вспомогательные имена
205 25 my @additions;
206 25 for my $i ( reverse 0 .. $#words ) {
207 44 ▶ last if @words <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if @words <= 1 11 33 44
208 33 ▶ next unless any { $words[$i] =~ $_->[1] } @addition_words;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless &any(sub { $words[$i] =~ /$_->[1]/imsx; } , @addition_words) 27 6 33
209 6 push @additions, splice @words, $i, 1;
210 }
211  
212 # и профессию
213 25 ▶ my $i = first_index { my $w = lc $_; any { $w eq $_ } @prof_words } @words;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
214 25 ▶ if ( @words > 1 && $i >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 1 and $i >= 0) 2 23 25
Condition100%3/3
@words > 1 and $i >= 0
!ll&&!rl&&r
1582
MC/DC100%2/2
@words > 1 and $i >= 0
@words > 1 $i >= 0
Truth table100%3/3
A and B
A= @words > 1B= $i >= 0
ABresult
0X0
100
111
215 2 unshift @additions, splice @words, $i, 1;
216 }
217  
218 # статус по дефолту, если не нашли
219 25 ▶ $status ||= $words[-1] =~ /[ыи]й $/ix ? 'переулок' : 'улица';
Branch: 1 branch
BranchTrueFalseTotal
$words[-1] =~ /[\x{44b}\x{438}]\x{439} $/xi ? : 2 11 13
Condition66%2/3
$status ||= $words[-1] =~ /[\x{44b}\x{438}]\x{439} $/xi ? "\x{43f}\x{435}\x{440}\x{435}\x{443}\x{43b}\x{43e}\x{43a}" : "\x{443}\x{43b}\x{438}\x{446}\x{430}"
l!l&&r!l&&!r
12130
MC/DC0%0/2
$status ||= $words[-1] =~ /[\x{44b}\x{438}]\x{439} $/xi ? "\x{43f}\x{435}\x{440}\x{435}\x{443}\x{43b}\x{43e}\x{43a}" : "\x{443}\x{43b}\x{438}\x{446}\x{430}"
$status $words[-1] =~ /[\x{44b}\x{438}]\x{439} $/xi ? "\x{43f}\x{435}\x{440}\x{435}\x{443}\x{43b}\x{43e}\x{43a}" : "\x{443}\x{43b}\x{438}\x{446}\x{430}"
Truth table66%2/3
A ||= B
A= $statusB= $words[-1] =~ /[\x{44b}\x{438}]\x{439} $/xi ? "\x{43f}\x{435}\x{440}\x{435}\x{443}\x{43b}\x{43e}\x{43a}" : "\x{443}\x{43b}\x{438}\x{446}\x{430}"
ABresult
1X1
011
000
220  
221 25 return( $status, join( q{ }, @words ), join( q{ }, @additions ), $number, $km );
222 }
223  
224  
225 =head2 streetname_keystring
226  
227 Returns unified keystring for street
228  
229 my $street = '2-й пр. Марьиной Рощи';
230 my $key = streetname_keystring( $street );
231 # 'МАРЬИНОЙ РОЩИ 2 ПРОЕЗД'
232  
233 =cut
234  
235 12 ▶sub streetname_keystring {
Subroutine streetname_keystring: called CC=15 SCAR=27.2
Pod documented
236 12 my ($street, $suburb) = @_;
237  
238 12 ▶ ( $suburb ||= q{} ) =~ s/ ^ (дер|г|пос) [\.\s]+ //ix;
Condition50%1/2
$suburb ||= ""
l!l
012
MC/DC0%0/1
$suburb ||= ""
$suburb
Truth table50%1/2
A
A= $suburb
Aresult
11
00
239 12 ▶ return uc $suburb unless $street;
Branch: 1 branch
BranchTrueFalseTotal
unless $street 0 12 12
240  
241 12 my ( $status, $name, $addition, $number, $km ) = streetname_split( $street );
242  
243 12 ▶ ( $number ||= q{} ) =~ s/ - \S+ //xms;
Condition100%2/2
$number ||= ""
l!l
48
MC/DC100%1/1
$number ||= ""
$number
Truth table100%2/2
A
A= $number
Aresult
11
00
244 12 $name =~ s/ (?<=\d) - \S+ //xms;
245 12 $name =~ s/ ^ (?: No? | № ) (?=\d) //xms;
246 12 $name =~ s/ (?<=\p{IsAlpha}) \s+ (?=\p{IsUpper}\.) /_/gxms;
247 12 $name =~ s/ ^ им (?: ени )? \.? \s+ (?= \S ) //xms;
248  
249 12 ▶ if ( my ($n) = $km =~ / ^ (\d+) /xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($n) = $km =~ / ^ (\d+) /msx) 2 10 12
250 2 $km = "${n}км";
251 }
252  
253 12 ▶ if ( $addition ||= q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addition ||= "") 4 8 12
Condition100%2/2
$addition ||= ""
l!l
48
MC/DC100%1/1
$addition ||= ""
$addition
Truth table100%2/2
A
A= $addition
Aresult
11
00
254 4 for my $rec ( @addition_words ) {
255 16 ▶ next unless $addition =~ $rec->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $addition =~ /$rec->[1]/imsx 13 3 16
256 3 $addition = $rec->[0];
257 3 last;
258 }
259 }
260  
261 12 my $result = uc join( q{ }, $name, $addition, $status );
262 12 ▶ $result .= uc " $number" if $number || $km || $suburb;
Branch: 1 branch
BranchTrueFalseTotal
if $number or $km or $suburb 6 6 12
Condition83%5/6
$number or $km or $suburb
l!l&&r!l&&!r
606
$number or $km
l!l&&r!l&&!r
426
MC/DC66%2/3
$number or $km or $suburb
$number $km $suburb
Truth table75%3/4
A or B or C
A= $numberB= $kmC= $suburb
ABCresult
1XX1
01X1
0011
0000
263 12 ▶ $result .= uc " $km" if $km || $suburb;
Branch: 1 branch
BranchTrueFalseTotal
if $km or $suburb 2 10 12
Condition66%2/3
$km or $suburb
l!l&&r!l&&!r
2010
MC/DC50%1/2
$km or $suburb
$km $suburb
Truth table66%2/3
A or B
A= $kmB= $suburb
ABresult
1X1
011
000
264 12 ▶ $result .= uc " $suburb" if $suburb;
Branch: 1 branch
BranchTrueFalseTotal
if $suburb 0 12 12
265 12 $result =~ s/Ё/Е/gi;
266 12 return $result;
267 }
268  
269 =head2 housenumber_keystring
270  
271 Returns unified keystring for house
272  
273 my $house = '1А к3 с5';
274 my $key = housenumber_keystring( $house );
275 # '1АК3С5'
276  
277 =cut
278  
279 0 ▶sub housenumber_keystring {
Subroutine housenumber_keystring: not called CC=2 SCAR=17.9
Pod documented
280  
281 0 my ( $name ) = @_;
282  
283 0 ▶ return q{} if $name eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "" 0 0 0
284  
285 0 my $key = uc $name;
286 0 $key =~ s/[\. ]//g;
287 0 $key =~ s/КОРП(?:УС)/К/gi;
288 0 $key =~ s/СТР/С/gi;
289 0 $key =~ s/k/К/gi;
290 0 $key =~ s/c/С/gi;
291  
292 0 $key =~ s/^вл?\.?\s*(\d.*)/$1/i;
293  
294 0 return $key;
295 }
296  
297  
298  
299  
300 2 1;
↑ Summary