line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Normal::Type::Address; |
2
|
9
|
|
|
9
|
|
34
|
use strict; |
|
9
|
|
|
|
|
12
|
|
|
9
|
|
|
|
|
201
|
|
3
|
9
|
|
|
9
|
|
29
|
use warnings; |
|
9
|
|
|
|
|
8
|
|
|
9
|
|
|
|
|
180
|
|
4
|
9
|
|
|
9
|
|
26
|
use String::Normal::Type; |
|
9
|
|
|
|
|
9
|
|
|
9
|
|
|
|
|
129
|
|
5
|
9
|
|
|
9
|
|
31
|
use String::Normal::Config; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
2441
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $address_stem; |
8
|
|
|
|
|
|
|
our $address_stop; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub transform { |
11
|
2
|
|
|
2
|
1
|
5
|
my ($self,$value) = @_; |
12
|
|
|
|
|
|
|
|
13
|
2
|
50
|
|
|
|
13
|
$value =~ s/\([^)]*\)/ /g if $value =~ /^[^(]|[^)]$/; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
|
|
7
|
$value = String::Normal::Type::_scrub_value( $value ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# tokenize and stem |
18
|
2
|
|
|
|
|
5
|
my @tokens = (); |
19
|
2
|
|
|
|
|
19
|
for my $token (split ' ', $value) { |
20
|
7
|
100
|
|
|
|
16
|
$token = defined( $address_stem->{$token} ) ? $address_stem->{$token} : $token; |
21
|
|
|
|
|
|
|
# TODO: this form of stop wording will need to be further addressed |
22
|
7
|
100
|
|
|
|
18
|
if (@tokens > 2) { |
23
|
1
|
50
|
33
|
|
|
13
|
last if $token eq 'apt' or $token eq 'ste'; |
24
|
|
|
|
|
|
|
} |
25
|
6
|
|
|
|
|
11
|
push @tokens, $token; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# remove all middle stop words |
29
|
|
|
|
|
|
|
my @filtered = map { |
30
|
2
|
|
50
|
|
|
5
|
my $count = $address_stop->{middle}{$_} || ''; |
|
6
|
|
|
|
|
25
|
|
31
|
6
|
50
|
33
|
|
|
27
|
(length $count and @tokens >= $count) ? () : $_; |
32
|
|
|
|
|
|
|
} @tokens; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# revert if we filtered words down to less than 2 tokens |
35
|
2
|
50
|
|
|
|
6
|
@filtered = @tokens if @filtered < 2; |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
17
|
return join ' ', @filtered; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
42
|
1
|
|
|
|
|
4
|
$address_stem = String::Normal::Config::AddressStem::_data( @_ ); |
43
|
1
|
|
|
|
|
5
|
$address_stop = String::Normal::Config::AddressStop::_data( @_ ); |
44
|
1
|
|
|
|
|
7
|
return bless {@_}, $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
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 |
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 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Path to text file to override default address stemming. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item * C |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Path to text file to override default address stop words. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over 4 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C |
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<< >> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Copyright 2017 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 |
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 |