]> granicus.if.org Git - postgis/commitdiff
#1074, #1109 - Fix for compound named streets that have a portion that is a street...
authorRegina Obe <lr@pcorp.us>
Thu, 7 Jul 2011 12:41:13 +0000 (12:41 +0000)
committerRegina Obe <lr@pcorp.us>
Thu, 7 Jul 2011 12:41:13 +0000 (12:41 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7616 b70326c6-7e19-0410-871a-916f4a2858ee

extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql
extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress
extras/tiger_geocoder/tiger_2010/regress/normalize_address_regress.sql

index eaa5cbb98fa7c1431105e6856e381ace368223b5..7c8a0eed4cd1ca23fd78bffc034ee952f6c457a0 100644 (file)
@@ -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
index 3919aec373245e06b0c60a67790ebe86d4e61eee..adcdd1d7268457fd68b80c2d6984f894eda7b56d 100644 (file)
@@ -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
index 2293d273feee4d37a1e05b1eae0192605fc838cc..714aeb461b8c85e2b073f0b9bcdca912c9a19225 100644 (file)
@@ -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