]> granicus.if.org Git - postgis/commitdiff
#1076 hanlde of post direction with highways -- 1940 County Road C W, Roseville,...
authorRegina Obe <lr@pcorp.us>
Tue, 5 Jul 2011 17:49:14 +0000 (17:49 +0000)
committerRegina Obe <lr@pcorp.us>
Tue, 5 Jul 2011 17:49:14 +0000 (17:49 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7588 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 4a1849c05fdbcd7f5ebd03ceabcc368209106fbb..6465d1d1bd80fda928366a5697343418e04690c7 100644 (file)
@@ -304,6 +304,9 @@ BEGIN
     streetType := rec.given;
     result.streetTypeAbbrev := rec.abbrev;
     isHighway :=  rec.is_hw;
+    IF debug_flag THEN
+       RAISE NOTICE 'street Type: %, street Type abbrev: %', rec.given, rec.abbrev;
+    END IF;
   ELSIF tempInt > 1 THEN
     tempInt := 0;
     FOR rec IN SELECT abbrev, substring(fullStreet, '(?i)' || ws || '?('
@@ -328,6 +331,9 @@ BEGIN
         result.streetTypeAbbrev := rec.abbrev;
         isHighway := rec.is_hw;
         tempInt := position(rec.given IN fullStreet);
+        IF debug_flag THEN
+               RAISE NOTICE 'street Type: %, street Type abbrev: %', rec.given, rec.abbrev;
+        END IF;
       END IF;
     END LOOP;
   END IF;
@@ -352,7 +358,27 @@ BEGIN
     END IF;    
     IF tempString > '' AND result.location IS NOT NULL THEN
         reducedStreet := tempString;
-        result.streetName := trim(reducedStreet);
+        result.streetName := reducedStreet;
+        IF debug_flag THEN
+               RAISE NOTICE 'reduced Street: %', result.streetName;
+        END IF;
+        -- the post direction might be portion of fullStreet after reducedStreet
+               -- reducedStreet: 24  fullStreet: Country Road 24, N or fullStreet: Country Road 24 N
+               tempString := regexp_replace(fullStreet, streetType || ws || '+' || reducedStreet,'');
+               IF tempString > '' THEN
+                       IF debug_flag THEN
+                               RAISE NOTICE 'remove reduced street: % + streetType: % from fullstreet: %', reducedStreet, streetType, fullStreet;
+                       END IF;
+                       tempString := abbrev FROM direction_lookup WHERE
+                        tempString ILIKE '%' || name || '%'  AND texticregexeq(reducedStreet || ws || '+' || streetType, '(?i)(' || name || ')' || ws || '+|$')
+                               ORDER BY length(name) DESC LIMIT 1;
+                       IF tempString IS NOT NULL THEN
+                               result.postDirAbbrev = trim(tempString);
+                               IF debug_flag THEN
+                                       RAISE NOTICE 'postDirAbbre of highway: %', result.postDirAbbrev;
+                               END IF;
+                       END IF;
+               END IF;
     ELSE
         tempString := substring(fullStreet, streetType || ws ||
             E'+([0-9][^ ,.\t\r\n\f]*?)' || ws);
@@ -372,43 +398,43 @@ BEGIN
           reducedStreet := substring(fullStreet, '^(.*)' || ws || '+'
                         || streetType);
         END IF;
-        -- the post direction might be portion of fullStreet after reducedStreet
-        -- reducedStreet: Main  fullStreet: Main St, N or fullStreet: Main St N
-        tempString := trim(regexp_replace(fullStreet,  reducedStreet ||  ws || '+' || streetType,''));
-        IF tempString > '' THEN
-          tempString := abbrev FROM direction_lookup WHERE
-             tempString ILIKE '%' || name || '%'  AND texticregexeq(reducedStreet || ws || '+' || streetType, '(?i)(' || name || ')' || ws || '+|$')
-            ORDER BY length(name) DESC LIMIT 1;
-          IF tempString IS NOT NULL THEN
-            result.postDirAbbrev = trim(tempString);
-          END IF;
-        END IF;
-     
-    
-        IF debug_flag THEN
-            raise notice '% reduced street: %', clock_timestamp(), reducedStreet;
-        END IF;
-        
-        -- The pre direction should be at the beginning of the fullStreet string.
-        -- The post direction should be at the beginning of the location string
-        -- if there is no internal address
-        reducedStreet := trim(reducedStreet);
-        tempString := trim(regexp_replace(fullStreet,  ws || '+' || reducedStreet ||  ws || '+',''));
-        IF tempString > '' THEN
-            tempString := substring(reducedStreet, '(?i)(^' || name
-                || ')' || ws) FROM direction_lookup WHERE
-                 reducedStreet ILIKE '%' || name || '%'  AND texticregexeq(reducedStreet, '(?i)(^' || name || ')' || ws)
-                ORDER BY length(name) DESC LIMIT 1;
-        END IF;
-        IF tempString > '' THEN
-          preDir := tempString;
-          result.preDirAbbrev := abbrev FROM direction_lookup
-              where reducedStreet ILIKE '%' || name '%' AND texticregexeq(reducedStreet, '(?i)(^' || name || ')' || ws)
-              ORDER BY length(name) DESC LIMIT 1;
-          result.streetName := trim(substring(reducedStreet, '^' || preDir || ws || '(.*)'));
-        ELSE
-          result.streetName := trim(reducedStreet);
-        END IF;
+               -- the post direction might be portion of fullStreet after reducedStreet
+               -- reducedStreet: Main  fullStreet: Main St, N or fullStreet: Main St N
+               tempString := trim(regexp_replace(fullStreet,  reducedStreet ||  ws || '+' || streetType,''));
+               IF tempString > '' THEN
+                 tempString := abbrev FROM direction_lookup WHERE
+                        tempString ILIKE '%' || name || '%'  AND texticregexeq(reducedStreet || ws || '+' || streetType, '(?i)(' || name || ')' || ws || '+|$')
+                       ORDER BY length(name) DESC LIMIT 1;
+                 IF tempString IS NOT NULL THEN
+                       result.postDirAbbrev = trim(tempString);
+                 END IF;
+               END IF;
+
+               IF debug_flag THEN
+                       raise notice '% reduced street: %', clock_timestamp(), reducedStreet;
+               END IF;
+               
+               -- The pre direction should be at the beginning of the fullStreet string.
+               -- The post direction should be at the beginning of the location string
+               -- if there is no internal address
+               reducedStreet := trim(reducedStreet);
+               tempString := trim(regexp_replace(fullStreet,  ws || '+' || reducedStreet ||  ws || '+',''));
+               IF tempString > '' THEN
+                       tempString := substring(reducedStreet, '(?i)(^' || name
+                               || ')' || ws) FROM direction_lookup WHERE
+                                reducedStreet ILIKE '%' || name || '%'  AND texticregexeq(reducedStreet, '(?i)(^' || name || ')' || ws)
+                               ORDER BY length(name) DESC LIMIT 1;
+               END IF;
+               IF tempString > '' THEN
+                 preDir := tempString;
+                 result.preDirAbbrev := abbrev FROM direction_lookup
+                         where reducedStreet ILIKE '%' || name '%' AND texticregexeq(reducedStreet, '(?i)(^' || name || ')' || ws)
+                         ORDER BY length(name) DESC LIMIT 1;
+                 result.streetName := trim(substring(reducedStreet, '^' || preDir || ws || '(.*)'));
+               ELSE
+                 result.streetName := trim(reducedStreet);
+               END IF;
     END IF;
     IF texticregexeq(result.location, '(?i)' || result.internal || '$') THEN
       -- If the internal address is at the end of the location, then no
@@ -643,9 +669,12 @@ BEGIN
     END IF;
   END IF;
 
+  --get rid of extraneous spaces before we return
   result.address := to_number(addressString, '99999999999');
-  result.zip := zipString;
-
+  result.zip := trim(zipString);
+  result.streetName := trim(result.streetName);
+  result.location := trim(result.location);
+  result.postDirAbbrev := trim(result.postDirAbbrev);
   result.parsed := TRUE;
   RETURN result;
 END
index 40e5e6081dc2d125218af0d3aa08e446ca3d35d7..96a9a30808c2259b45e21afa0e2407e302eeec58 100644 (file)
@@ -82,8 +82,8 @@ T16|Federal Ln, Dedham, MA 02026|POINT(-71.18356 42.23829)|39
 #1076b|16725 24, Plymouth, MN 55447|16725 County Road 24, Plymouth, MN 55447|POINT(-93.49326 45.02186)|25
 #1076b|16725 24th Ave N, Plymouth, MN 55447|16725 County Road 24, Plymouth, MN 55447|POINT(-93.4927 45.00457)|27
 #1076c|13800 9, Andover, MN 55304|13800 County Hwy 9, Andover, MN 55304|POINT(-93.35733 45.22052)|30
-#1076d|13800 9, Andover, MN 55304|13800 9, Andover, MN 55304|POINT(-93.35733 45.22052)|10
+#1076d|13800 9, Andover, MN 55304|13800 9, Andover, MN 55304|POINT(-93.35733 45.22052)|0
 #1076e|3900 6, North Eastham, MA 02642|3900 Route 6, Eastham, Massachusetts 02642|POINT(-69.98743 41.85543)|15
-#1076f|1940 W C, Roseville, MN 55113|1940 County Road C W, Roseville, MN 55113|POINT(-93.18492 45.02058)|27
-#1076f|1940 C W, Roseville, MN 55113|1940 County Road C W, Roseville, MN 55113|POINT(-93.18492 45.02058)|27
+#1076f|1940 C W, Roseville, MN 55113|1940 County Road C W, Roseville, MN 55113|POINT(-93.18492 45.02058)|25
+#1076f|1940 W C, Roseville, MN 55113|1940 County Road C W, Roseville, MN 55113|POINT(-93.18492 45.02058)|29
 #1076g|15709 Rockford Rd, Plymouth, MN 55447|15709 Rockford Road, Plymouth, MN 55447|POINT(-93.47898 45.02726)|0
index 24e3cd1ec9db40ecbe164f9194b2d8d9d579b22c..6d25e7b0f90e688da79d459dd604bb29fc21ffaa 100644 (file)
@@ -17,7 +17,7 @@
 #1076a|16725||24|Co Rd|||Plymouth|MN|55447|t
 #1076b|16725||24|Co Rd|||Plymouth|MN|55447|t
 #1076c|13800||9|Co Hwy|||Andover|MN|55304|t
-#1076d|13800|| 9||||Andover|MN|55304|t
+#1076d|13800||9||||Andover|MN|55304|t
 #1076e|14||Forest|Rd|||Acton|MA||t
-#1076f|1940||C|Co Rd|||Roseville|MN|55113|t
+#1076f|1940||C|Co Rd|W||Roseville|MN|55113|t
 #1076g|3900||6|Rte|||Eastham|MA|02642|t