line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Abbreviations; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
300673
|
use warnings; |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
12
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
44
|
|
5
|
3
|
|
|
3
|
|
1645
|
use JSON; |
|
3
|
|
|
|
|
25065
|
|
|
3
|
|
|
|
|
11
|
|
6
|
3
|
|
|
3
|
|
1297
|
use LWP::Simple::WithCache; |
|
3
|
|
|
|
|
284624
|
|
|
3
|
|
|
|
|
166
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Geo::Coder::Abbreviations - Quick and Dirty Interface to https://github.com/mapbox/geocoder-abbreviations |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.05 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our %abbreviations; |
19
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
20
|
|
|
|
|
|
|
# This is giving 404 errors at the moment |
21
|
|
|
|
|
|
|
# our location = 'https://raw.githubusercontent.com/mapbox/geocoder-abbreviations/master/tokens/en.json'; |
22
|
3
|
|
|
3
|
|
26
|
use constant LOCATION => 'https://raw.githubusercontent.com/allison-strandberg/geocoder-abbreviations/master/tokens/en.json'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1180
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Provides an interface to https://github.com/mapbox/geocoder-abbreviations. |
27
|
|
|
|
|
|
|
One small function for now, I'll add others later. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 new |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Creates a Geo::Coder::Abbreviations object. |
34
|
|
|
|
|
|
|
It takes no arguments. |
35
|
|
|
|
|
|
|
If you have L installed it will load much faster, |
36
|
|
|
|
|
|
|
otherwise it will download the database from the Internet |
37
|
|
|
|
|
|
|
when the class is first instantiated. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
2
|
|
|
2
|
1
|
84
|
my $proto = shift; |
43
|
2
|
|
66
|
|
|
11
|
my $class = ref($proto) || $proto; |
44
|
|
|
|
|
|
|
|
45
|
2
|
100
|
|
|
|
9
|
return unless(defined($class)); |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
4
|
unless(scalar keys(%abbreviations)) { |
48
|
1
|
50
|
|
|
|
2
|
if(eval { require HTTP::Cache::Transparent; }) { |
|
1
|
|
|
|
|
163
|
|
49
|
0
|
|
|
|
|
0
|
require File::Spec; # That should be installed |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
File::Spec->import(); |
52
|
0
|
|
|
|
|
0
|
HTTP::Cache::Transparent->import(); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $cachedir; |
55
|
0
|
0
|
|
|
|
0
|
if(my $e = $ENV{'CACHEDIR'}) { |
56
|
0
|
|
|
|
|
0
|
$cachedir = File::Spec->catfile($e, 'http-cache-transparent'); |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
0
|
$cachedir = File::Spec->catfile(File::Spec->tmpdir(), 'cache', 'http-cache-transparent'); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
0
|
HTTP::Cache::Transparent::init({ |
62
|
|
|
|
|
|
|
BasePath => $cachedir, |
63
|
|
|
|
|
|
|
# Verbose => $opts{'v'} ? 1 : 0, |
64
|
|
|
|
|
|
|
NoUpdate => 60 * 60 * 24, |
65
|
|
|
|
|
|
|
MaxAge => 30 * 24 |
66
|
|
|
|
|
|
|
}) || die "$0: $cachedir: $!"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# TODO: Support other languages |
70
|
1
|
|
|
|
|
7
|
my $data = LWP::Simple::WithCache::get(LOCATION); |
71
|
|
|
|
|
|
|
|
72
|
1
|
50
|
|
|
|
515084
|
if(!defined($data)) { |
73
|
|
|
|
|
|
|
# die 'error downloading from ', LOCATION; |
74
|
0
|
|
|
|
|
0
|
$data = join('', grep(!/^\s*(#|$)/, )); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
%abbreviations = map { |
77
|
343
|
|
|
|
|
280
|
my %rc = (); |
78
|
343
|
100
|
100
|
|
|
517
|
if(defined($_->{'type'}) && ($_->{'type'} eq 'way')) { |
79
|
62
|
|
|
|
|
58
|
foreach my $token(@{$_->{'tokens'}}) { |
|
62
|
|
|
|
|
67
|
|
80
|
144
|
|
|
|
|
326
|
$rc{uc($token)} = uc($_->{'canonical'}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
343
|
|
|
|
|
407
|
%rc; |
84
|
1
|
|
|
|
|
4
|
} @{JSON->new()->utf8()->decode($data)}; |
|
1
|
|
|
|
|
682
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# %abbreviations = map { (defined($_->{'type'}) && ($_->{'type'} eq 'way')) ? (uc($_->{'full'}) => uc($_->{'canonical'})) : () } @{JSON->new()->utf8()->decode($data)}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
132
|
return bless { |
90
|
|
|
|
|
|
|
table => \%abbreviations |
91
|
|
|
|
|
|
|
}, $class; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 abbreviate |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Abbreviate a place. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use Geo::Coder::Abbreviations; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $abbr = Geo::Coder::Abbreviations->new(); |
101
|
|
|
|
|
|
|
print $abbr->abbreviate('Road'), "\n"; # prints 'RD' |
102
|
|
|
|
|
|
|
print $abbr->abbreviate('RD'), "\n"; # prints 'RD' |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub abbreviate { |
107
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $self->{'table'}->{uc(shift)}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SEE ALSO |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
L |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Nigel Horne, C<< >> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 BUGS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
You may need to ensure you don't translate "Cross Street" to "X ST". |
125
|
|
|
|
|
|
|
See t/abbreviations.t. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SUPPORT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
perldoc Geo::Coder::Abbreviations |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
You can also look for information at: |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * CPAN Ratings |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * Search CPAN |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Copyright 2020-2022 Nigel Horne. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This program is released under the following licence: GPL2 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; # End of Geo::Coder::Abbreviations |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# https://raw.githubusercontent.com/mapbox/geocoder-abbreviations/master/tokens/en.json is giving 404 errors at the moment |
164
|
|
|
|
|
|
|
# so here is a copy until it's back |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__DATA__ |