Skip to content

Commit

Permalink
Use G:C:Abbreviate in Local.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 8, 2020
1 parent 9055097 commit 6d05635
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 4 additions & 2 deletions lib/Geo/Coder/Free.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ sub new {
$alternatives->{$key} = join(', ', @{$value});
}
}
$abbreviations ||= Geo::Coder::Abbreviations->new();

my $rc = {
maxmind => Geo::Coder::Free::MaxMind->new(%param),
alternatives => $alternatives
Expand Down Expand Up @@ -312,6 +310,8 @@ sub run {
sub _normalize($) {
my $street = shift;

$abbreviations ||= Geo::Coder::Abbreviations->new();

$street = uc($street);
if($street =~ /(.+)\s+(.+)\s+(.+)/) {
my $a;
Expand All @@ -332,6 +332,8 @@ sub _normalize($) {
sub _abbreviate($) {
my $type = uc(shift);

$abbreviations ||= Geo::Coder::Abbreviations->new();

if(my $rc = $abbreviations->abbreviate($type)) {
return $rc;
}
Expand Down
10 changes: 3 additions & 7 deletions lib/Geo/Coder/Free/Local.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

use Geo::Location::Point;
use Geo::Coder::Free;
use Geo::StreetAddress::US;
use Lingua::EN::AddressParse;
use Locale::CA;
Expand Down Expand Up @@ -153,13 +154,8 @@ sub geocode {
my %addr = ( 'location' => $l );
my $street = $c{'street_name'};
if(my $type = $c{'street_type'}) {
$type = uc($type);
if($type eq 'STREET') {
$street = "$street ST";
} elsif($type eq 'ROAD') {
$street = "$street RD";
} elsif($type eq 'AVENUE') {
$street = "$street AVE";
if(my $a = Geo::Coder::Free::_abbreviate($type)) {
$street .= " $a";
} else {
$street .= " $type";
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ sub geocode {
}
if($ap) {
my $l = $location;
if($l =~ /(.+), (England|UK)$/) {
if($l =~ /(.+), (England|UK)$/i) {
$l = "$1, GB";
}
if(my $error = $ap->parse($l)) {
Expand All @@ -305,11 +305,11 @@ sub geocode {
} else {
my %c = $ap->components();
# ::diag(Data::Dumper->new([\%c])->Dump());
my %addr;
my %addr = ( 'location' => $l );
$street = $c{'street_name'};
if(my $type = $c{'street_type'}) {
if(my $a = Geo::Coder::Free::_abbreviate($type)) {
$street = "$street $a";
$street .= " $a";
} else {
$street .= " $type";
}
Expand Down
2 changes: 1 addition & 1 deletion t/local.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl -wT
#!perl -w

use warnings;
use strict;
Expand Down

0 comments on commit 6d05635

Please sign in to comment.