Skip to content

Commit

Permalink
Remove false match for Westmoreland County for now
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Oct 20, 2020
1 parent db565ba commit cee6c70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
15 changes: 11 additions & 4 deletions lib/Geo/Coder/Free/MaxMind.pm
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ sub geocode {
# ::diag(__LINE__);
$region = $admin2cache{$state};
} else {
# ::diag(__LINE__);
# ::diag(__PACKAGE__, ': ', __LINE__);
if(defined($county) && ($county eq 'London')) {
@admin2s = $self->{'admin2'}->selectall_hash(asciiname => $location);
} elsif(defined($county)) {
# ::diag(__LINE__, ": $county");
# ::diag(__PACKAGE__, ': ', __LINE__, ": $county");
@admin2s = $self->{'admin2'}->selectall_hash(asciiname => $county);
}
# ::diag(__LINE__, Data::Dumper->new([\@admin2s])->Dump());
Expand Down Expand Up @@ -370,8 +370,13 @@ sub geocode {
if((scalar(@regions) == 0) && !defined($region)) {
# e.g. Unitary authorities in the UK
# admin[12].db columns are labelled ['concatenated_codes', 'name', 'asciiname', 'geonameId']
# ::diag(__LINE__, ": $location");
# ::diag(__PACKAGE__, ': ', __LINE__, ": $location");
@admin2s = $self->{'admin2'}->selectall_hash(asciiname => $location);
if((scalar(@admin2s) == 0) && ($country =~ /^(Canada|United States|USA|US)$/) && ($location !~ /\sCounty/i)) {
$location .= ' County';
# ::diag(__PACKAGE__, ': ', __LINE__, ": $location");
@admin2s = $self->{'admin2'}->selectall_hash(asciiname => $location);
}
if(scalar(@admin2s) && defined($admin2s[0]->{'concatenated_codes'})) {
foreach my $admin2(@admin2s) {
my $concat = $admin2->{'concatenated_codes'};
Expand All @@ -385,6 +390,7 @@ sub geocode {
}
}
} elsif(defined($county)) {
# ::diag(__PACKAGE__, ': ', __LINE__, ": county $county");
# e.g. states in the US
if(!defined($self->{'admin1'})) {
$self->{'admin1'} = Geo::Coder::Free::DB::MaxMind::admin1->new(no_entry => 1) or die "Can't open the admin1 database";
Expand Down Expand Up @@ -451,6 +457,7 @@ sub geocode {
# ::diag(__LINE__, ': ', Data::Dumper->new([$options])->Dump());
# This case nonsense is because DBD::CSV changes the columns to lowercase, wherease DBD::SQLite does not
if(wantarray && !$region_only) {
# ::diag(__PACKAGE__, ': ', __LINE__);
my @rc = $self->{'cities'}->selectall_hash($options);
if(scalar(@rc) == 0) {
if((!defined($region)) && !defined($param{'region'})) {
Expand All @@ -462,7 +469,7 @@ sub geocode {
if($countrycode) {
@rc = $self->{'cities'}->selectall_hash('Region' => ($region || $param{'region'}), 'Country' => $countrycode);
if(scalar(@rc) == 0) {
# ::diag(__LINE__, ': no matches: ', Data::Dumper->new([$options])->Dump());
# ::diag(__PACKAGE__, ': ', __LINE__, ': no matches: ', Data::Dumper->new([$options])->Dump());
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ sub _get {
my ($self, @location) = @_;

my $location = join('', @location);
$location =~ s/^\s+//;
$location =~ s/,\s*//g;
# ::diag("_get: $location");
# ::diag(__PACKAGE__, ': ', __LINE__, ": _get: $location");
my $digest = substr Digest::MD5::md5_base64(uc($location)), 0, 16;

if(defined($unknown_locations{$digest})) {
Expand Down
10 changes: 5 additions & 5 deletions t/openaddr.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use warnings;
use strict;
use Test::Most tests => 52;
use Test::Most tests => 51;
use Test::Number::Delta;
use Test::Carp;
use Test::Deep;
Expand Down Expand Up @@ -73,8 +73,8 @@ OPENADDR: {
$location = $o_geo_coder->geocode('Boswell, Somerset, Pennsylvania, USA');
ok(defined($location));

$location = $geo_coder->geocode({location => 'Westmorland, New Brunswick, Canada'});
ok(defined($location));
# $location = $geo_coder->geocode({location => 'Westmorland, New Brunswick, Canada'});
# ok(defined($location));

$location = $geo_coder->geocode({location => 'Harrison Mills, British Columbia, Canada'});
ok(defined($location));
Expand Down Expand Up @@ -199,7 +199,7 @@ OPENADDR: {

} else {
diag('Author tests not required for installation');
skip('Author tests not required for installation', 50);
skip('Author tests not required for installation', 49);
}

# my $address = $geo_coder->reverse_geocode(latlng => '51.50,-0.13');
Expand All @@ -226,7 +226,7 @@ OPENADDR: {
}
} else {
diag('Set OPENADDR_HOME to enable openaddresses.io testing');
skip('Set OPENADDR_HOME to enable openaddresses.io testing', 51);
skip('Set OPENADDR_HOME to enable openaddresses.io testing', 50);
}
}
}

0 comments on commit cee6c70

Please sign in to comment.