From: Regina Obe Date: Thu, 7 Jul 2011 12:41:13 +0000 (+0000) Subject: #1074, #1109 - Fix for compound named streets that have a portion that is a street... X-Git-Tag: 2.0.0alpha1~1226 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17cc24f7eef9ab360f95181c64d3c4869b0f28d5;p=postgis #1074, #1109 - Fix for compound named streets that have a portion that is a street type git-svn-id: http://svn.osgeo.org/postgis/trunk@7616 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql b/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql index eaa5cbb98..7c8a0eed4 100644 --- a/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql +++ b/extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql @@ -310,14 +310,21 @@ BEGIN ELSIF tempInt > 1 THEN tempInt := 0; -- the last matching abbrev in the string is the most likely one - FOR rec IN SELECT abbrev, substring(fullStreet, '(?i)' || ws || '?(' - || name || ')(?:' || ws || '|$)') AS given, is_hw FROM street_type_lookup + FOR rec IN SELECT * FROM + (SELECT abbrev, substring(fullStreet, '(?i)' || ws || '?(' + || name || ')(?:' || ws || '|$)') AS given, is_hw , + ROW_NUMBER() OVER( ORDER BY position(name IN trim(fullStreet)) ) As n_type, + ROW_NUMBER() OVER() As nrecs + FROM street_type_lookup WHERE fullStreet ILIKE '%' || name || '%' AND trim(upper(fullStreet)) != name AND texticregexeq(fullStreet, '(?i)' || ws || '(' || name -- we only consider street types that are regular and not at beginning of name or are highways (since those can be at beg or end) -- we take the one that is the longest e.g Country Road would be more correct than Road - || ')(?:' || ws || '|$)') AND ((NOT is_hw AND position(name IN trim(fullStreet)) > 2) OR is_hw) ORDER BY length(name) DESC LIMIT 1 LOOP + || ')(?:' || ws || '|$)') AND ((NOT is_hw AND position(name IN trim(fullStreet)) > 2) OR is_hw) ) As foo + -- If it's a highway, we want the first highway that is street type + -- if its a regular, we want the last type in string, if tie, just return the longest + ORDER BY CASE WHEN is_hw THEN (nrecs - n_type) ELSE n_type END DESC, length(given) DESC LIMIT 1 LOOP -- If we have found an internal address, make sure the type -- precedes it. /** TODO: I don't think we need a loop anymore since we are just returning one and the one in the last position diff --git a/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress b/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress index 3919aec37..adcdd1d72 100644 --- a/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress +++ b/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress @@ -25,4 +25,4 @@ #1076i|4533||33|Co Rd|||MINNEAPOLIS|MN|55407|t #1109a|4373||LAKE|Dr|||ROBBINSDALE|MN|55422|t #1109b|4373||LAKE|Dr|||ROBBINSDALE|MN|55422|t -#1109b|4373||LAKE|Dr|||ROBBINSDALE|MN|55422|t +#1074a|3420||RHODE ISLAND|Ave|S||ST. LOUIS PARK|MN|55426|t diff --git a/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress.sql b/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress.sql index 2293d273f..714aeb461 100644 --- a/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress.sql +++ b/extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress.sql @@ -47,7 +47,6 @@ SELECT '#1076g' As ticket, * FROM normalize_address('3900 Route 6, Eastham, Mass -- Street that has same name as type -- SELECT '#1076h' As ticket, * FROM normalize_address('4533 PARK AVE S, MINNEAPOLIS, MN 55407'); - -- same street with alternate county name SELECT '#1076i' As ticket, * FROM normalize_address('4533 County Road 33, MINNEAPOLIS, MN 55407'); @@ -58,7 +57,7 @@ SELECT '#1109a' As ticket, * from normalize_address('4373 LAKE DRIVE, ROBBINSDAL -- this failed -- SELECT '#1109b' As ticket, * from normalize_address('4373 LAKE DR, ROBBINSDALE, MN 55422'); --- this failed -SELECT '#1109b' As ticket, * from normalize_address('4373 LAKE DR, ROBBINSDALE, MN 55422'); +-- another type (Is) that is part of street name but a compound street name +SELECT '#1074a' As ticket, * fROM normalize_address('3420 RHODE ISLAND AVE S, ST. LOUIS PARK, MN 55426'); \timing