Normal/Type/Address.pm

filter: Statementstmt 100% 33 / 33 Branchbran 66.6% 8 / 12 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 78.7% 52 / 66 CC 11 SCAR 22.4
CC
11
Cov
83%
transform
13.2
BEGIN
1.0
BEGIN
1.0
CRAP 9.4
↑ Summary Normal/Type/Business.pm »
1 package String::Normal::Type::Address;
2 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use String::Normal::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use String::Normal::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $address_stem;
8 9 our $address_stop;
9  
10 2 ▶sub transform {
Subroutine transform: called CC=11 SCAR=25.8
Pod documented
11 2 my ($self,$value) = @_;
12  
13 2 ▶ $value =~ s/\([^)]*\)/ /g if $value =~ /^[^(]|[^)]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^[^(]|[^)]$/ 2 0 2
14  
15 2 $value = String::Normal::Type::_scrub_value( $value );
16  
17 # tokenize and stem
18 2 my @tokens = ();
19 2 for my $token (split ' ', $value) {
20 7 ▶ $token = defined( $address_stem->{$token} ) ? $address_stem->{$token} : $token;
Branch: 1 branch
BranchTrueFalseTotal
defined $String::Normal::Type::Address::address_stem->{$token} ? : 2 5 7
21 # TODO: this form of stop wording will need to be further addressed
22 7 ▶ if (@tokens > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens > 2) 1 6 7
23 1 ▶ last if $token eq 'apt' or $token eq 'ste';
Branch: 1 branch
BranchTrueFalseTotal
if $token eq "apt" or $token eq "ste" 1 0 1
Condition33%1/3
$token eq "apt" or $token eq "ste"
l!l&&r!l&&!r
010
MC/DC0%0/2
$token eq "apt" or $token eq "ste"
$token eq "apt" $token eq "ste"
Truth table33%1/3
A or B
A= $token eq "apt"B= $token eq "ste"
ABresult
1X1
011
000
24 }
25 6 push @tokens, $token;
26 }
27  
28 # remove all middle stop words
29 my @filtered = map {
30 2 ▶ my $count = $address_stop->{middle}{$_} || '';
Condition50%1/2
$String::Normal::Type::Address::address_stop->{'middle'}{$_} || ''
l!l
06
MC/DC0%0/1
$String::Normal::Type::Address::address_stop->{'middle'}{$_} || ''
$String::Normal::Type::Address::address_stop->{'middle'}{$_}
Truth table50%1/2
A
A= $String::Normal::Type::Address::address_stop->{'middle'}{$_}
Aresult
11
00
31 6 ▶ (length $count and @tokens >= $count) ? () : $_;
Branch: 1 branch
BranchTrueFalseTotal
length $count && @tokens >= $count ? : 0 6 6
Condition33%1/3
length $count and @tokens >= $count
!ll&&!rl&&r
600
MC/DC0%0/2
length $count and @tokens >= $count
length $count @tokens >= $count
Truth table33%1/3
A and B
A= length $countB= @tokens >= $count
ABresult
0X0
100
111
32 } @tokens;
33  
34 # revert if we filtered words down to less than 2 tokens
35 2 ▶ @filtered = @tokens if @filtered < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @filtered < 2 0 2 2
36  
37 2 return join ' ', @filtered;
38 }
39  
40 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 1 my $self = shift;
42 1 $address_stem = String::Normal::Config::AddressStem::_data( @_ );
43 1 $address_stop = String::Normal::Config::AddressStop::_data( @_ );
44 1 return bless {@_}, $self;
45 }
46  
47 9 1;
48  
49 =head1 NAME
50  
51 String::Normal::Type::Address;
52  
53 =head1 DESCRIPTION
54  
55 This package defines substitutions to be performed on Address types.
56  
57 =head1 METHODS
58  
59 =over 4
60  
61 =item C<new( %params )>
62  
63 my $address = String::Normal::Type::Address->new;
64  
65 Creates an Address type. Accepts the following named parameters:
66  
67 =back
68  
69 =over 8
70  
71 =item * C<address_stem>
72  
73 Path to text file to override default address stemming.
74  
75 =item * C<address_stop>
76  
77 Path to text file to override default address stop words.
78  
79 =back
80  
81 =over 4
82  
83 =item C<transform( $value )>
84  
85 my $new_value = $address->transform( $value );
86  
87 Transforms a value according to the rules of a Address type.
88  
89 =back
90  
91 =head1 AUTHOR
92  
93 Jeff Anderson, C<< <jeffa at cpan.org> >>
94  
95 =head1 LICENSE AND COPYRIGHT
96  
97 Copyright 2024 Jeff Anderson.
98  
99 This program is free software; you can redistribute it and/or modify it
100 under the terms of the the Artistic License (2.0). You may obtain a
101 copy of the full license at:
102  
103 L<http://www.perlfoundation.org/artistic_license_2_0>
104  
105 Any use, modification, and distribution of the Standard or Modified
106 Versions is governed by this Artistic License. By using, modifying or
107 distributing the Package, you accept this license. Do not use, modify,
108 or distribute the Package, if you do not accept this license.
109  
110 If your Modified Version has been derived from a Modified Version made
111 by someone other than you, you are nevertheless required to ensure that
112 your Modified Version complies with the requirements of this license.
113  
114 This license does not grant you the right to use any trademark, service
115 mark, tradename, or logo of the Copyright Holder.
116  
117 This license includes the non-exclusive, worldwide, free-of-charge
118 patent license to make, have made, use, offer to sell, sell, import and
119 otherwise transfer the Package with respect to any patent claims
120 licensable by the Copyright Holder that are necessarily infringed by the
121 Package. If you institute patent litigation (including a cross-claim or
122 counterclaim) against any party alleging that the Package constitutes
123 direct or contributory patent infringement, then this Artistic License
124 to you shall terminate on the date that such litigation is filed.
125  
126 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
127 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
128 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
129 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
130 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
131 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
132 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
133 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134  
135 =cut
↑ Summary Normal/Type/Business.pm »