Skip to content

Commit

Permalink
More of the POC
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Apr 7, 2024
1 parent 48ed36a commit 4b6969f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/Geo/Coder/Free.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use Geo::Coder::Abbreviations;
use Geo::Coder::Free::MaxMind;
use Geo::Coder::Free::OpenAddresses;
use List::MoreUtils;
use Locale::US;
use Carp;

=head1 NAME
Expand Down Expand Up @@ -198,18 +199,23 @@ sub geocode {
if(wantarray) {
my @rc = $self->{'openaddr'}->geocode(\%params);
if((my $scantext = $params{'scantext'}) && (my $region = $params{'region'})) {
$scantext =~ s/\W+/ /g;
$scantext =~ s/[^\w']+/ /g;
my @a = List::MoreUtils::uniq(split(/\s/, $scantext));
my $iterator = Array::Iterator->new({ __array__ => \@a });
while(my $w = $iterator->get_next()) {
next if(exists($common_words{lc($w)}));
if($w =~ /^[a-z]{2,}$/i) {
my $peek = $iterator->peek();
last if(!defined($peek));
my $peekpeek = $peek->peek();
last if(!defined($peekpeek));
my $s = "$w $peek $peekpeek";
::diag($s);
my $s;
if((length($peek) == 2) && (Locale::US->new()->{code2state}{uc($peek)})) {
$s = "$w $peek US";
} else {
my $peekpeek = $iterator->peek(2);
last if(!defined($peekpeek));
$s = "$w $peek $peekpeek";
}
# ::diag($s);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Geo/Coder/Free/OpenAddresses.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ sub geocode
if(my $scantext = $param{'scantext'}) {
return if(length($scantext) < 6);
# FIXME: wow this is inefficient
$scantext =~ s/\W+/ /g;
$scantext =~ s/[^\w']+/ /g;
my @words = split(/\s/, $scantext);
my $count = scalar(@words);
my $offset = 0;
Expand Down

0 comments on commit 4b6969f

Please sign in to comment.