Repository: GreenBuildingRegistry/usaddress-scourgify

Issue:
Valid occupancy types replaced by 'UNIT'
HI there, I appreciate your work on normalizing the US Address library!
 
I notice the following issue:

```
>>> from scourgify import normalize_address_record
>>> normalize_address_record('12345 Somewhere Street Apt 1, Town, MA 12345')
{'address_line_1': '12345 SOMEWHERE ST', 'address_line_2': 'UNIT 1', 'city': 'TOWN', 'state': 'MA', 'postal_code': '12345'}
```

I believe it has to do with the following bit of code in `scourgify.normalize.normalize_occupancy_type`:

```
    default = default if default is not None else 'UNIT'
    occupancy_type_label = 'OccupancyType'
    occupancy_type = parsed_addr.pop(occupancy_type_label, None)
    occupancy_type_abbr = OCCUPANCY_TYPE_ABBREVIATIONS.get(occupancy_type)
    occupancy_id = parsed_addr.get('OccupancyIdentifier')
    if ((occupancy_id and not occupancy_id.startswith('#'))
            and not occupancy_type_abbr):
        occupancy_type_abbr = default

    ...
```

When I step debug, the returned `occupancy_type` is `'APT'`. However, the `occupancy_type_abbr` is set as `None` considering the `OCCUPANCY_TYPE_ABBREVIATIONS` are currently in the format `<full_name> -> <abbreviation>`

I suggest the following fix:

```
    if occupancy_type in OCCUPANCY_TYPE_ABBREVIATIONS.values():
        occupancy_type_abbr = occupancy_type
    else:
        occupancy_type_abbr = OCCUPANCY_TYPE_ABBREVIATIONS.get(occupancy_type)
```

Then you can cover both cases.


Comments:

Patch:
diff --git a/scourgify/normalize.py b/scourgify/normalize.py
index 4270b68..8827088 100644
--- a/scourgify/normalize.py
+++ b/scourgify/normalize.py
@@ -535,7 +535,8 @@ def normalize_occupancy_type(parsed_addr, default=None):
     default = default if default is not None else 'UNIT'
     occupancy_type_label = 'OccupancyType'
     occupancy_type = parsed_addr.pop(occupancy_type_label, None)
-    occupancy_type_abbr = OCCUPANCY_TYPE_ABBREVIATIONS.get(occupancy_type)
+    occupancy_type_abbr = occupancy_type if occupancy_type in OCCUPANCY_TYPE_ABBREVIATIONS.values() \
+        else OCCUPANCY_TYPE_ABBREVIATIONS.get(occupancy_type)
     occupancy_id = parsed_addr.get('OccupancyIdentifier')
     if ((occupancy_id and not occupancy_id.startswith('#'))
             and not occupancy_type_abbr):


Test patch:
diff --git a/scourgify/tests/test_address_normalization.py b/scourgify/tests/test_address_normalization.py
index ac8ea09..66a9c42 100644
--- a/scourgify/tests/test_address_normalization.py
+++ b/scourgify/tests/test_address_normalization.py
@@ -263,6 +263,34 @@ class TestAddressNormalization(TestCase):
         result = normalize_addr_dict(hashtag_unit, addr_map=dict_map)
         self.assertDictEqual(expected, result)
 
+        expected = dict(
+            address_line_1='123 NOWHERE ST',
+            address_line_2='APT 345',
+            city='BORING',
+            state='OR',
+            postal_code='97009'
+        )
+
+        abbreviation = dict(
+            address1='123 Nowhere St',
+            address2='Apt 345',
+            city='Boring',
+            state='OR',
+            zip='97009'
+        )
+        result = normalize_addr_dict(abbreviation, addr_map=dict_map)
+        self.assertDictEqual(expected, result)
+
+        full_name = dict(
+            address1='123 Nowhere St',
+            address2='Apartment 345',
+            city='Boring',
+            state='OR',
+            zip='97009'
+        )
+        result = normalize_addr_dict(full_name, addr_map=dict_map)
+        self.assertDictEqual(expected, result)
+
 
 class TestAddressNormalizationUtils(TestCase):
     """Unit tests for scourgify utils"""