1#!/usr/local/bin/perl 2 3# Demo script for Lingua::EN::AddressParse.pm 4 5use strict; 6use Lingua::EN::AddressParse; 7 8my %args = 9( 10 country => 'AU', 11 auto_clean => 0, 12 force_case => 1, 13 abbreviated_subcountry_only => 0 14); 15 16 17my $address = Lingua::EN::AddressParse->new(%args); 18open(REPORT_FH,">report.txt") or die; 19 20open(ERROR_FH,">error.txt") or die; 21 22my ($errors,$total); 23while ( <DATA> ) 24{ 25 # last if $. == 3; 26 chomp($_); 27 my $address_in = $_; 28 29 $total++; 30 my $error = $address->parse($address_in); 31 32 my %comps = $address->components; 33 my %props = $address->properties; 34 35 if ( $error and $props{type} eq 'unknown' ) 36 { 37 $errors++; 38 print(ERROR_FH "$address_in: $props{non_matching}\n"); 39 } 40 else 41 { 42 my $line = sprintf("%-8.8s : %-10.10s %-10.10s %-20.20s %-10.10s %-2.2s %-15.15s %-15.15s %-15.15s %-20.20s %-15.15s %-10.10s %-14.14s %-30.30s\n", 43 $props{type}, 44 $comps{sub_property_identifier},$comps{property_identifier}, 45 $comps{street},$comps{street_type},$comps{street_direction}, 46 $comps{property_name},$comps{post_box},$comps{road_box}, 47 $comps{suburb},$comps{subcountry},$comps{post_code},$comps{country},$props{non_matching}); 48 print(REPORT_FH $line); 49 } 50} 51my $now = localtime(time); 52 53print(REPORT_FH "\n\nTIME : $now \n"); 54printf(REPORT_FH "BATCH DATA QUALITY: %5.2f percent\n",( 1- ($errors / $total)) *100 ); 55 56close(REPORT_FH); 57close(ERROR_FH); 58 59#------------------------------------------------------------------------------ 60__DATA__ 6112 2nd Street Toongabbie NSW 2146 6274 B ST TOONGABBIE NSW 2146 6322 Lower 3rd St Toongabbie NSW 2146 6412 74 3rd Rd Toongabbie NSW 2146 6574 12th Avenue South West Rocks NSW 2146 6674 12th St Toongabbie NSW 2146 6774 Queen's Park Road Toongabbie NSW 2146 6874 Queen's Park Toongabbie NSW 2146 69147 OLD CHARLESTOWN ROAD KOTARA HEIGHTS NEW SOUTH WALES 2289 AUSTRALIA 7022A GRAND RIDGE ROAD CARDIFF VIC 3285 AUSTRALIA 71"OLD REGRET" WENTWORTH FALLS NT 882 7214A WANDARRA CRESCENT ST JOHNS WOOD SW 200 732/3-5 GLEN ALPINE WAY ST VERMONT VIC 3133 7474 ST THOMAS LANE ST. IVES WEST NSW 2075 75Level 2 12 THE CIRCUIT WERRIBEE HILLS VICTORIA 3030 7660 Mount Baw Baw Road Mt Baw Baw VIC 3871 77UNIT 1 61 THE GRAND PARADE CORLETTE NSW 2315 78Unit 4 26 george street french's forest nsw 2286 79RMS 75 MOUNT VICTORIA NSW 2761 80RMB 75 XYZ HIGHWAY MOUNT VICTORIA NSW 2761 81RMB 75 MOUNT VICTORIA NSW 2761 82PO BOX 71B VICTORIA VALLEY VICTORIA 3146 83LOT 2C THE ESPLANADE CARDIFF NSW 2285 84BAD ADDRESS GARDWELL 4849 8512 SMITH ST ULTIMO NSW 2007 : ALL POSTAL DELIVERIES 861234 11th St Minneapolis NSW 5407 876505 Glen Road Woodbury NSW 5525 883363 Coachman Rd Eagan NSW 5521