1#------------------------------------------------------------------------------ 2# Test script for Lingua::EN::::AddressParse.pm 3# Author : Kim Ryan 4#------------------------------------------------------------------------------ 5 6use strict; 7use Lingua::EN::AddressParse; 8use Test::Simple tests => 15; 9 10 11 12my $input; 13 14my %args = 15( 16 country => 'Australia', 17 auto_clean => 1, 18 force_case => 1, 19 abbreviate_subcountry => 1 20); 21 22my $address = Lingua::EN::AddressParse->new(%args); 23 24$input = "12A/74-76 OLD AMINTA CRESCENT HASALL GROVE NEW SOUTH WALES 2761 AUSTRALIA"; 25$address->parse($input); 26my %props = $address->properties; 27 28my %comps = $address->components; 29 30ok 31( 32 ( 33 34 $comps{sub_property_identifier} eq '12A' and 35 $comps{property_identifier} eq '74-76' and 36 $comps{street_name} eq 'Old Aminta' and 37 $comps{street_type} eq 'Crescent' and 38 $comps{suburb} eq 'Hasall Grove' and 39 $comps{subcountry} eq 'NSW' and 40 $comps{post_code} eq '2761' and 41 $comps{country} eq 'AUSTRALIA' and 42 $props{type} eq 'suburban' 43 ), 44 "Australian suburban address with sub property" 45); 46 47$input = "Unit 4 12 Queen's Park Road Queens Park NSW 2022 "; 48$address->parse($input); 49%comps = $address->components; 50ok 51( 52 ( 53 $comps{property_identifier} eq '12' and 54 $comps{sub_property_type} eq 'Unit' and 55 $comps{sub_property_identifier} eq '4' and 56 $comps{street_name} eq "Queen\'s Park" and 57 $comps{street_type} eq 'Road' and 58 $comps{suburb} eq 'Queens Park' and 59 $comps{subcountry} eq 'NSW' and 60 $comps{post_code} eq '2022' 61 ), 62 "Australian suburban address with two word street" 63); 64 65$input = "12 The Avenue Parkes NSW 2522 "; 66$address->parse($input); 67%comps = $address->components; 68ok 69( 70 ( 71 $comps{property_identifier} eq '12' and 72 $comps{street_name} eq "The Avenue" and 73 $comps{suburb} eq 'Parkes' and 74 $comps{subcountry} eq 'NSW' and 75 $comps{post_code} eq '2522' 76 ), 77 "Suburban address with street noun" 78); 79 80$input = "12 Broadway Parkes NSW 2522"; 81$address->parse($input); 82%comps = $address->components; 83ok 84( 85 ( 86 $comps{property_identifier} eq '12' and 87 $comps{street_name} eq "Broadway" and 88 $comps{suburb} eq 'Parkes' and 89 $comps{subcountry} eq 'NSW' and 90 $comps{post_code} eq '2522' 91 ), 92 "Suburban address with single word street" 93); 94 95 96$input = '"OLD REGRET" WENTWORTH FALLS NSW 2780'; 97$address->parse($input); 98%comps = $address->components; 99ok 100( 101 ( 102 $comps{property_name} eq '"Old Regret"' and 103 $comps{suburb} eq 'Wentworth Falls' and 104 $comps{subcountry} eq 'NSW' and 105 $comps{post_code} eq '2780' 106 ), 107 "Australian rural address" 108); 109 110$input = 'PO BOX 71 TOONGABBIE PRIVATE BOXES NSW 2146'; 111$address->parse($input); 112%comps = $address->components; 113ok 114( 115 ( 116 $comps{post_box} eq 'PO BOX 71' and 117 $comps{suburb} eq 'Toongabbie' and 118 $comps{subcountry} eq 'NSW' and 119 $comps{post_code} eq '2146' and 120 $comps{po_box_type} eq 'Private Boxes' 121 ), 122 "Australian PO Box" 123); 124 125 126$input = "12 SMITH ST ULTIMO NSW 2007 : ALL POSTAL DELIVERIES"; 127$address->parse($input); 128%props = $address->properties; 129ok($props{non_matching} eq "ALL POSTAL DELIVERIES ", "Australian Non matching"); 130 131 132 133# Test other countries 134 135%args = ( country => 'US'); 136$address = Lingua::EN::AddressParse->new(%args); 137 138$input = "12 AMINTA CRESCENT S # 24E BEVERLEY HILLS CA 90210-1234"; 139$address->parse($input); 140%comps = $address->components; 141ok 142( 143 ( 144 $comps{property_identifier} eq '12' and 145 $comps{sub_property_identifier} eq '24E' and 146 $comps{sub_property_type} eq '#' and 147 $comps{street_name} eq 'Aminta' and 148 $comps{street_type} eq 'Crescent' and 149 $comps{street_direction_suffix} eq 'S' and 150 $comps{suburb} eq 'Beverley Hills' and 151 $comps{subcountry} eq 'CA' and 152 $comps{post_code} eq '90210-1234' 153 ), 154 "US suburban address" 155); 156 157$input = "12 US HIGHWAY 19 N BEVERLEY HILLS CA 90210-1234"; 158$address->parse($input); 159%comps = $address->components; 160ok 161( 162 ( 163 $comps{property_identifier} eq '12' and 164 $comps{street_name} eq 'US Highway 19 N' and 165 $comps{suburb} eq 'Beverley Hills' and 166 $comps{subcountry} eq 'CA' and 167 $comps{post_code} eq '90210-1234' 168 ), 169 "US government road address" 170); 171 172 173%args = ( country => 'Canada' ); 174 175$address = Lingua::EN::AddressParse->new(%args); 176 177$input = "12 AMINTA CRESCENT BEVERLEY HILLS BRITISH COLUMBIA K1B 4L7"; 178$address->parse($input); 179%comps = $address->components; 180ok 181( 182 ( 183 $comps{property_identifier} eq '12' and 184 $comps{street_name} eq 'Aminta' and 185 $comps{street_type} eq 'Crescent' and 186 $comps{suburb} eq 'Beverley Hills' and 187 $comps{subcountry} eq 'BRITISH COLUMBIA' and 188 $comps{post_code} eq 'K1B 4L7' 189 ), 190 "Canadian suburban address" 191); 192 193 194%args = ( country => 'United Kingdom', auto_clean => 1); 195# note pre cursor only detected if auto_clean is on 196$address = Lingua::EN::AddressParse->new(%args); 197 198$input = "C/O MR A B SMITH XYZ P/L: 12 AMINTA CRESCENT NEWPORT IOW SW1A 9ET"; 199$address->parse($input); 200%comps = $address->components; 201 202%comps = $address->components; 203ok 204( 205 ( 206 $comps{pre_cursor} eq 'C/O Mr A B Smith Xyz P/L:' and 207 $comps{property_identifier} eq '12' and 208 $comps{street_name} eq 'Aminta' and 209 $comps{street_type} eq 'Crescent' and 210 $comps{suburb} eq 'Newport' and 211 $comps{subcountry} eq 'IOW' and 212 $comps{post_code} eq 'SW1A 9ET' 213 ), 214 "UK suburban address with pre cursor" 215); 216 217$input = "12 AMINTA CRESCENT NEWPORT IOW SW1A 9ET"; 218$address->parse($input); 219%comps = $address->components; 220 221%comps = $address->components; 222ok 223( 224 ( 225 $comps{property_identifier} eq '12' and 226 $comps{street_name} eq 'Aminta' and 227 $comps{street_type} eq 'Crescent' and 228 $comps{suburb} eq 'Newport' and 229 $comps{subcountry} eq 'IOW' and 230 $comps{post_code} eq 'SW1A 9ET' 231 ), 232 "UK suburban address" 233); 234 235$input = "Building 2A Level 24 12 AMINTA CRESCENT NEWPORT IOW SW1A 9ET"; 236$address->parse($input); 237%comps = $address->components; 238 239%comps = $address->components; 240ok 241( 242 ( 243 $comps{property_identifier} eq '12' and 244 $comps{building} eq 'Building 2a' and 245 $comps{level} eq 'Level 24' and 246 $comps{street_name} eq 'Aminta' and 247 $comps{street_type} eq 'Crescent' and 248 $comps{suburb} eq 'Newport' and 249 $comps{subcountry} eq 'IOW' and 250 $comps{post_code} eq 'SW1A 9ET' 251 ), 252 "UK address with building and level" 253); 254 255 256$input = "12 ZTL CRESCENT NEWPORT IOW SW1A 9ET"; 257$address->parse($input); 258ok 259( 260 ( 261 $address->{warning_desc} eq ';no vowel sound in street word : ZTL' 262 ), 263 "no vowel sound in street" 264); 265 266$input = "12 A 24 AMINTA CRESCENT NEWPORT IOW SW1A 9ET"; 267$address->parse($input); 268%comps = $address->components; 269 270%comps = $address->components; 271ok 272( 273 ( 274 $comps{property_identifier} eq '24' and 275 $comps{sub_property_identifier} eq '12A' and 276 $comps{street_name} eq 'Aminta' and 277 $comps{street_type} eq 'Crescent' and 278 $comps{suburb} eq 'Newport' and 279 $comps{subcountry} eq 'IOW' and 280 $comps{post_code} eq 'SW1A 9ET' 281 ), 282 "sub property auto clean" 283); 284 285 286