Permalink
Please sign in to comment.
Showing
with
1,585 additions
and 653 deletions.
- +1,585 −0 setup.rb
- +0 −236 tests/address.rb
- +0 −20 tests/benchmark.rb
- +0 −57 tests/constants.rb
- +0 −52 tests/data/address-sample.csv
- +0 −56 tests/data/db-test.csv
- +0 −4 tests/data/locations.csv
- +0 −137 tests/database.rb
- +0 −34 tests/generate.rb
- +0 −46 tests/numbers.rb
- +0 −11 tests/run.rb
236
tests/address.rb
| @@ -1,236 +0,0 @@ | ||
| -$LOAD_PATH.unshift '../lib' | ||
| - | ||
| -require 'test/unit' | ||
| -require 'set' | ||
| -require 'geocoder/us/address' | ||
| - | ||
| -include Geocoder::US | ||
| - | ||
| -class TestAddress < Test::Unit::TestCase | ||
| - def test_new | ||
| - addr = Address.new("1600 Pennsylvania Av., Washington DC") | ||
| - assert_equal "1600 Pennsylvania Av, Washington DC", addr.text | ||
| - end | ||
| - def test_clean | ||
| - fixtures = [ | ||
| - [ "cleaned text", "cleaned: text!" ], | ||
| - [ "cleaned-text 2", "cleaned-text: #2?" ], | ||
| - [ "it's working 1/2", "~it's working 1/2~" ], | ||
| - [ "it's working, yes", "it's working, yes...?" ], | ||
| - [ "it's working & well", "it's working & well?" ] | ||
| - ] | ||
| - fixtures.each {|output, given| | ||
| - assert_equal output, Address.new(given).text | ||
| - } | ||
| - end | ||
| - def test_expand_numbers | ||
| - num_list = ["5", "fifth", "five"] | ||
| - num_list.each {|n| | ||
| - addr = Address.new(n) | ||
| - assert_equal num_list, addr.expand_numbers(n).to_a.sort | ||
| - } | ||
| - end | ||
| - def test_city_parse | ||
| - places = [ | ||
| - [ "New York, NY", "New York", "NY", "" ], | ||
| - [ "NY", "", "NY", "" ], | ||
| - [ "New York", "New York", "NY", "" ], | ||
| - [ "Philadelphia", "Philadelphia", "", "" ], | ||
| - [ "Philadelphia PA", "Philadelphia", "PA", "" ], | ||
| - [ "Philadelphia, PA", "Philadelphia", "PA", "" ], | ||
| - [ "Philadelphia, Pennsylvania", "Philadelphia", "PA", "" ], | ||
| - [ "Philadelphia, Pennsylvania 19131", "Philadelphia", "PA", "19131" ], | ||
| - [ "Philadelphia 19131", "Philadelphia", "", "19131" ], | ||
| - [ "Pennsylvania 19131", "Pennsylvania", "PA", "19131" ], # kind of a misfeature | ||
| - [ "19131", "", "", "19131" ], | ||
| - [ "19131-9999", "", "", "19131" ], | ||
| - ] | ||
| - for fixture in places | ||
| - addr = Address.new fixture[0] | ||
| - [:city, :state, :zip].zip(fixture[1..3]).each {|key,val| | ||
| - result = addr.send key | ||
| - result = [result.downcase] unless result.kind_of? Array | ||
| - if result.empty? | ||
| - assert_equal val, "", key.to_s + " test no result " + fixture.join("/") | ||
| - else | ||
| - assert result.member?(val.downcase), key.to_s + " test " + result.inspect + fixture.join("/") | ||
| - end | ||
| - } | ||
| - end | ||
| - end | ||
| - | ||
| - def test_po_box | ||
| - addr_po = Address.new "PO Box 1111 Herndon VA 20171" | ||
| - assert addr_po.po_box?, true | ||
| - end | ||
| - | ||
| - | ||
| - | ||
| - def test_parse | ||
| - addrs = [ | ||
| - {:text => "1600 Pennsylvania Av., Washington DC 20050", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania Ave", | ||
| - :city => "Washington", | ||
| - :state => "DC", | ||
| - :zip => "20050"}, | ||
| - | ||
| - {:text => "1600 Pennsylvania, Washington DC", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania", | ||
| - :city => "Washington", | ||
| - :state => "DC"}, | ||
| - | ||
| - {:text => "1600 Pennsylvania Washington DC", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania Washington", | ||
| - :city => "Pennsylvania Washington", # FIXME | ||
| - :state => "DC"}, | ||
| - | ||
| - {:text => "1600 Pennsylvania Washington", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania", | ||
| - :city => "Washington", | ||
| - :state => "WA"}, # FIXME | ||
| - | ||
| - {:text => "1600 Pennsylvania 20050", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania", # FIXME | ||
| - :zip => "20050"}, | ||
| - | ||
| - {:text => "1600 Pennsylvania Av, 20050-9999", | ||
| - :number => "1600", | ||
| - :street => "Pennsylvania Ave", | ||
| - :zip => "20050"}, | ||
| - | ||
| - {:text => "1005 Gravenstein Highway North, Sebastopol CA", | ||
| - :number => "1005", | ||
| - :street => "Gravenstein Hwy N", | ||
| - :city => "Sebastopol", | ||
| - :state => "CA"}, | ||
| - | ||
| - {:text => "100 N 7th St, Brooklyn", | ||
| - :number => "100", | ||
| - :street => "N 7 St", | ||
| - :city => "Brooklyn"}, | ||
| - | ||
| - {:text => "100 N Seventh St, Brooklyn", | ||
| - :number => "100", | ||
| - :street => "N 7 St", | ||
| - :city => "Brooklyn"}, | ||
| - | ||
| - {:text => "100 Central Park West, New York, NY", | ||
| - :number => "100", | ||
| - :street => "Central Park W", | ||
| - :city => "New York", | ||
| - :state => "NY"}, | ||
| - | ||
| - {:text => "100 Central Park West, 10010", | ||
| - :number => "100", | ||
| - :street => "Central Park W", | ||
| - :zip => "10010"}, | ||
| - | ||
| - {:text => "1400 Avenue of the Americas, New York, NY 10019", | ||
| - :number => "1400", | ||
| - :street => "Ave of the Americas", | ||
| - :city => "New York", | ||
| - :state => "NY"}, | ||
| - | ||
| - {:text => "1400 Avenue of the Americas, New York", | ||
| - :number => "1400", | ||
| - :street => "Ave of the Americas", | ||
| - :city => "New York"}, | ||
| - | ||
| - {:text => "1400 Ave of the Americas, New York", | ||
| - :number => "1400", | ||
| - :street => "Ave of the Americas", | ||
| - :city => "New York"}, | ||
| - | ||
| - {:text => "1400 Av of the Americas, New York", | ||
| - :number => "1400", | ||
| - :street => "Ave of the Americas", | ||
| - :city => "New York"}, | ||
| - | ||
| - {:text => "1400 Av of the Americas New York", | ||
| - :number => "1400", | ||
| - :street => "Ave of the Americas", | ||
| - :city => "New York"}, | ||
| - | ||
| - ] | ||
| - for fixture in addrs | ||
| - text = fixture.delete(:text) | ||
| - addr = Address.new(text) | ||
| - for key, val in fixture | ||
| - result = addr.send key | ||
| - if result.kind_of? Array | ||
| - result.map! {|str| str.downcase} | ||
| - assert result.member?(val.downcase), "#{text} (#{key}) = #{result.inspect}" | ||
| - else | ||
| - assert_equal val, result, "#{text} (#{key}) = #{result.inspect}" | ||
| - end | ||
| - end | ||
| - end | ||
| - end | ||
| - | ||
| - def test_skip_parse | ||
| - addresses = [ | ||
| - {:street => "1233 Main St", :city => "Springfield", :region => "VA", :postal_code => "12345", :final_number => "1233", :parsed_street => "main st"}, | ||
| - {:street => "somewhere Ln", :city => "Somewhere", :region => "WI", :postal_code => "22222", :number => "402", :parsed_street => "somewhere ln", :final_number => "402"}, | ||
| - ] | ||
| - for preparsed_address in addresses | ||
| - address_for_geocode = Address.new preparsed_address | ||
| - assert_equal preparsed_address[:parsed_street],address_for_geocode.street[0] | ||
| - assert_equal preparsed_address[:final_number],address_for_geocode.number | ||
| - assert_equal preparsed_address[:city],address_for_geocode.city[0] | ||
| - assert_equal preparsed_address[:region],address_for_geocode.state | ||
| - assert_equal preparsed_address[:postal_code],address_for_geocode.zip | ||
| - end | ||
| - end | ||
| - | ||
| - def test_states_abbreviated_in_skip_parse | ||
| - addresses = [ | ||
| - {:street => "123 Main St", :city => "Springfield", :region => "Virginia", :postal_code => "12345",:state_abbrev => "VA"}, | ||
| - {:street => "402 Somewhere Ln", :city => "Somewhere", :region => "WI", :postal_code => "22222", :state_abbrev => "WI"}, | ||
| - ] | ||
| - for preparsed_address in addresses | ||
| - address_for_geocode = Address.new preparsed_address | ||
| - assert_equal preparsed_address[:state_abbrev],address_for_geocode.state | ||
| - end | ||
| - | ||
| - end | ||
| - | ||
| - def test_address_hash | ||
| - addresses = [ | ||
| - {:address => "Herndon, VA", :place_check => ["herndon"]}, | ||
| - {:address => "Arlington, VA", :place_check => ["arlington"]} | ||
| - ] | ||
| - for preparsed_address in addresses | ||
| - address_for_geocode = Address.new preparsed_address | ||
| - assert_equal preparsed_address[:place_check],address_for_geocode.city | ||
| - end | ||
| - end | ||
| - | ||
| - def test_partial_address | ||
| - addresses = [ | ||
| - {:street => "2200 Wilson Blvd", :postal_code => "22201"}, | ||
| - ] | ||
| - for preparsed_address in addresses | ||
| - address_for_geocode = Address.new preparsed_address | ||
| - assert_equal preparsed_address[:postal_code],address_for_geocode.zip | ||
| - end | ||
| - | ||
| - | ||
| - end | ||
| - | ||
| - def test_country_parse | ||
| - addresses = [ | ||
| - {:city => "Paris", :country => "FR"}, | ||
| - ] | ||
| - | ||
| - for preparsed_address in addresses | ||
| - address_for_geocode = Address.new preparsed_address | ||
| - assert_equal preparsed_address[:country],address_for_geocode.state | ||
| - end | ||
| - end | ||
| - | ||
| -end |
| @@ -1,20 +0,0 @@ | ||
| -#!/usr/bin/ruby | ||
| - | ||
| -require 'test/unit' | ||
| -require 'geocoder/us/database' | ||
| -require 'benchmark' | ||
| -include Benchmark # we need the CAPTION and FMTSTR constants | ||
| - | ||
| -db = Geocoder::US::Database.new("/mnt/tiger2008/geocoder.db") | ||
| - | ||
| -n = 50 | ||
| -s = "1005 Gravenstein Hwy N, Sebastopol CA 95472" | ||
| -a = Geocoder::US::Address.new(s) | ||
| - | ||
| -print db.geocode(s) | ||
| - | ||
| -Benchmark.bmbm do |x| | ||
| - x.report("parse max_penalty=0") { n.times{a.parse(0)} } | ||
| - x.report("parse max_penalty=1") { n.times{a.parse(1)} } | ||
| - x.report("geocode") { n.times{db.geocode(s)} } | ||
| -end |
| @@ -1,57 +0,0 @@ | ||
| -$LOAD_PATH.unshift '../lib' | ||
| - | ||
| -require 'test/unit' | ||
| -require 'geocoder/us/constants' | ||
| - | ||
| -include Geocoder::US | ||
| - | ||
| -class TestConstants < Test::Unit::TestCase | ||
| - def initialize (*args) | ||
| - @map = Map[ | ||
| - "Abbreviation" => "abbr", | ||
| - "Two words" => "2words", | ||
| - "Some three words" => "3words" | ||
| - ] | ||
| - super(*args) | ||
| - end | ||
| - def test_class_constructor | ||
| - assert_kind_of Map, @map | ||
| - assert_kind_of Hash, @map | ||
| - end | ||
| - def test_key | ||
| - assert @map.key?( "Abbreviation" ) | ||
| - assert @map.key?( "abbreviation" ) | ||
| - assert !(@map.key? "abbreviation?") | ||
| - assert @map.key?( "abbr" ) | ||
| - assert @map.key?( "Two words" ) | ||
| - assert @map.key?( "2words" ) | ||
| - end | ||
| - def test_fetch | ||
| - assert_equal "abbr", @map["Abbreviation"] | ||
| - assert_equal "abbr", @map["abbreviation"] | ||
| - assert_nil @map["abbreviation?"] | ||
| - assert_equal "abbr", @map["abbr"] | ||
| - assert_equal "2words", @map["Two words"] | ||
| - assert_equal "2words", @map["2words"] | ||
| - end | ||
| -# def test_partial | ||
| -# assert @map.partial?( "Abbreviation" ) | ||
| -# assert @map.partial?( "Two" ) | ||
| -# assert @map.partial?( "two" ) | ||
| -# assert !(@map.partial? "words") | ||
| -# assert @map.partial?( "Some" ) | ||
| -# assert !(@map.partial? "words") | ||
| -# assert @map.partial?( "Some three" ) | ||
| -# assert @map.partial?( "SOME THREE WORDS" ) | ||
| -# end | ||
| - def test_constants | ||
| - assert_kind_of Map, Directional | ||
| - assert_kind_of Map, Prefix_Qualifier | ||
| - assert_kind_of Map, Suffix_Qualifier | ||
| - assert_kind_of Map, Prefix_Type | ||
| - assert_kind_of Map, Suffix_Type | ||
| - assert_kind_of Map, Unit_Type | ||
| - assert_kind_of Map, Name_Abbr | ||
| - assert_kind_of Map, State | ||
| - end | ||
| -end |
| @@ -1,52 +0,0 @@ | ||
| -address,number,predir,prequal,pretyp,street,suftyp,sufqual,sufdir,unittyp,unit,city,state,zip,lon,lat,count,comment | ||
| -"93 NORTH 9TH STREET, BROOKLYN NY 11211",93,N,,,9th,St,,,,,Brooklyn,NY,11211,,,, | ||
| -"380 WESTMINSTER ST, PROVIDENCE RI 02903",380,,,,Westminster,St,,,,,Providence,RI,02903,,,, | ||
| -"177 MAIN STREET, LITTLETON NH 03561",177,,,,Main,St,,,,,Littleton,NH,03561,,,, | ||
| -"202 HARLOW ST, BANGOR ME 04401",202,,,,Harlow,St,,,,,Bangor,ME,04401,,,, | ||
| -"46 FRONT STREET, WATERVILLE, ME 04901",46,,,,Front,St,,,,,Waterville,ME,04901,,,, | ||
| -"22 SUSSEX ST, HACKENSACK NJ 07601",22,,,,Sussex,St,,,,,Hackensack,NJ,07601,,,, | ||
| -"75 OAK STREET, PATCHOGUE NY 11772",75,,,,Oak,St,,,,,Patchogue,NY,11772,,,, | ||
| -"1 CLINTON AVE, ALBANY NY 12207",1,,,,Clinton,Ave,,,,,Albany,NY,12207,,,, | ||
| -"7242 ROUTE 9, PLATTSBURGH NY 12901",7242,,,US Hwy,9,,,,,,Plattsburgh,NY,12901,,,, | ||
| -"520 5TH AVE, MCKEESPORT PA 15132",520,,,,5th,Ave,,,,,McKeesport,PA,15132,,,, | ||
| -"122 W 3RD STREET, GREENSBURG PA 15601",122,W,,,3rd,St,,,,,Greensburg,PA,15601,,,, | ||
| -"901 UNIVERSITY DR, STATE COLLEGE PA 16801",901,,,,University,Dr,,,,,"State College",PA,16801,,,, | ||
| -"240 W 3RD ST, WILLIAMSPORT PA 17701",240,W,,,3rd,St,,,,,Williamsport,PA,17701,,,, | ||
| -"41 N 4TH ST, ALLENTOWN PA 18102",41,N,,,4th,St,,,,,Allentown,PA,18102,,,, | ||
| -"2221 W. MARKET STREET, POTTSVILLE PA 17901",2221,W,,,Market,St,,,,,Pottsville,PA,17901,,,, | ||
| -"337 BRIGHTSEAT ROAD, LANDOVER MD 20785",337,,,,Brightseat,Rd,,,,,Hyattsville,MD,20785,,,,"canonical place" | ||
| -"101 CHESAPEAKE BLVD, ELKTON MD 21921",103,,,,Chesapeake,Blvd,,,,,Elkton,MD,21921,,,,"find nearest corner" | ||
| -"2875 SABRE ST, VIRGINIA BEACH VA 23452",2809,,,,Sabre,St,,,,,"Virginia Beach",VA,23452,,,,"find nearest corner" | ||
| -"324 COMMERCE ROAD, FARMVILLE VA 23901",324,,,,Commerce,St,,,,,Clarksville,VA,23927,,,,"nearby address; might be TIGER omission" | ||
| -"1480 EAST MAIN STREET, WYTHEVILLE VA 24382",1480,W,,,Main,St,,,,,Wytheville,VA,24382,,,,"nearby address; TIGER omission" | ||
| -"116 N JEFFERSON STREET, ROANOKE VA 24016",116,N,,,Jefferson,St,,,,,Roanoke,VA,24016,,,, | ||
| -"50 MCDOWELL STREET, WELCH WV 24801",50,,,,"Mc Dowell",St,,,,,Welch,WV,24801,,,, | ||
| -"146 EAST FIRST AVE, WILLIAMSON WV 25661",200,E,,,1st,Ave,,,,,Williamson,WV,25661,,,,"find nearest corner" | ||
| -"1925 E MAIN ST, ALBEMARLE NC 28001",1925,E,,,Main,St,,,,,Albemarle,NC,28001,,,, | ||
| -"1013 SPRING LANE, SANFORD NC 27330",1013,,,,Spring,Ln,,,,,Sanford,NC,27330,,,, | ||
| -"145 ROWAN STREET, FAYETTEVILLE NC 28301",145,,,,Rowan,St,,,,,Fayetteville,NC,28301,,,, | ||
| -"1420 MCCARTHY BLVD, NEW BERN NC 28562",1420,,,,McCarthy,Blvd,,,,,"New Bern",NC,28562,,,, | ||
| -"115 ENTERPRISE COURT, GREENWOOD SC 29649",115,,,,Enterprise,Ct,,,,,Greenwood,SC,29649,,,, | ||
| -"732 W 2ND ST, TIFTON GA 31794",732,,,,2nd,St,,W,,,Tifton,GA,31793,,,,"TIGER artifact" | ||
| -"97 WEST OAK AVE, PANAMA CITY FL 32401",97,,,,Oak,Ave,,,,,"Panama City",FL,32401,,,,"predir is TIGER artifact" | ||
| -"2276 WILTON DR, WILTON MANORS FL 33305",2276,,,,Wilton,Dr,,,,,"Fort Lauderdale",FL,33305,,,,"canonical place" | ||
| -"203 SOUTH WALNUT ST, FLORENCE AL 35630",203,S,,,Walnut,St,,,,,Florence,AL,35630,,,, | ||
| -"108 CENTER POINTE DR, CLARKSVILLE TN 37040",108,,,,"Center Pointe",Dr,,,,,Clarksville,TN,37040,,,, | ||
| -"1800 OLD TROY RD, UNION CITY TN 38261",1800,,Old,,Troy,Rd,,,,,"Union City",TN,38261,,,, | ||
| -"931 OLD SMITHVILLE HWY, MCMINNVILLE TN 37110",931,,Old,,Smithville,Rd,,,,,McMinnville,TN,37110,,,, | ||
| -"1301 GREENE STREET, MARIETTA OH 45750",1301,,,,Greene,St,,,,,Marietta,OH,45750,,,, | ||
| -"602 SOUTH MICHIGAN ST, SOUTH BEND IN 46601",602,S,,,Michigan,St,,,,,"South Bend",IN,46601,,,, | ||
| -"500 NORTH A STREET, RICHMOND IN 47374",500,N,,,A,St,,,,,Richmond,IN,47374,,,, | ||
| -"317 SOUTH DRAKE ROAD, KALAMAZOO MI 49009",317,S,,,Drake,Rd,,,,,Kalamazoo,MI,49009,,,, | ||
| -"105 Amity Way, Wayne PA 19087",105,,,,Amity,Dr,,,,,Wayne,PA,19087,,,, | ||
| -"305 W 45th St, New York NY 10036",305,W,,,45,St,,,,,"New York",NY,10036,,,, | ||
| -"11839 Federalist Way, Fairfax VA 22030",11839,,,,Federalist,Way,,,,,Fairfax,VA,22030,,,, | ||
| -"400 Monroe St, Hoboken, NJ 07030",400,,,,Monroe,St,,,,,Hoboken,NJ,07030,,,, | ||
| -"101 West End Avenue, New York NY 10023",101,W,,,End,Ave,,,,,"New York",NY,10023,,,,"predir is TIGER artifact" | ||
| -"2900 4TH AVE, BILLINGS MT 59101",2900,,,,4th,Ave,,N,,,Billings,MT,59101,,,,"returns 2 results" | ||
| -"158 N SCOTT STREET, JOLIET IL 60432",158,N,,,Scott,St,,,,,Joliet,IL,60432,,,, | ||
| -"1207 NETWORK CENTRE DR, EFFINGHAM IL 62401",1207,,,,"Network Centre",Dr,,,,,Effingham,IL,62401,,,, | ||
| -"3555 SOUTHERN HILLS DR, SIOUX CITY IA 51106",3555,,,,"Southern Hills",Dr,,,,,"Sioux City",IA,51106,,,, | ||
| -"300 E 3RD ST, NORTH PLATTE NE 69101",300,E,,,3rd,St,,,,,"North Platte",NE,69101,,,, | ||
| -"115 N WEBB RD, GRAND ISLAND NE 68803",115,N,,,Webb,Rd,,,,,"Grand Island",NE,68803,,,, | ||
| -"415 VALLEY VIEW DR, SCOTTSBLUFF NE 69361",501,,,,"Valley View",Dr,,,,,"Scottsbluff",NE,69361,,,,"find nearest corner" |
Oops, something went wrong.
0 comments on commit
c2b9444