def test_normalizedAddressString(self):
        result = parse_address.parse('123 EA Fifer Place ')

        self.assertEqual(result.normalizedAddressString, '123 E FIFER PL')

        result = parse_address.parse(' 123 east 400 w  ')

        self.assertEqual(result.normalizedAddressString, '123 E 400 W')
    def test_doubleSpaces(self):
        result = parse_address.parse('  123  ea main  st')

        self.assertEqual(result.houseNumber, '123')
        self.assertEqual(result.prefixDirection, 'E')
        self.assertEqual(result.streetName, 'MAIN')
        self.assertEqual(result.suffixType, 'ST')
    def cleanAddresses():
        print(' * Cleaning Addresses')

        def NullOrEmpty(value):
            if value is None:
                return True

            value = value.strip()
            return len(value) < 1

        def NotNumericAddress(value):
            if not value[0].isdigit():
                return True

        with arcpy.da.UpdateCursor(newParcels, ['PARCEL_ADD']) as rows:

            for row in rows:
                if NullOrEmpty(row[0]):
                    continue

                if NotNumericAddress(row[0]):
                    row[0] = ""

                else:
                    address = parse_address.parse(row[0])
                    row[0] = address.normalizedAddressString

                row[0] = row[0].strip().upper().replace("  ",
                                                        " ").replace(".", "")

                rows.updateRow(row)
    def test_stripPeriods(self):
        result = parse_address.parse('  123 ea main st.')

        self.assertEqual(result.houseNumber, '123')
        self.assertEqual(result.prefixDirection, 'E')
        self.assertEqual(result.streetName, 'MAIN')
        self.assertEqual(result.suffixType, 'ST')
        self.assertEqual(result.suffixDirection, None)
        self.assertEqual(result.normalizedAddressString, '123 E MAIN ST')
    def test_noPreDir(self):
        result = parse_address.parse('1901 Sidewinder Dr')

        self.assertEqual(result.houseNumber, '1901')
        self.assertEqual(result.prefixDirection, None)
        self.assertEqual(result.streetName, 'SIDEWINDER')
        self.assertEqual(result.suffixType, 'DR')
        self.assertEqual(result.suffixDirection, None)
        self.assertEqual(result.normalizedAddressString, '1901 SIDEWINDER DR')
Ejemplo n.º 6
0
    def test_streetTypeNames(self):
        result = parse_address.parse('123 E PARKWAY AVE')

        self.assertEqual(result.houseNumber, '123')
        self.assertEqual(result.prefixDirection, 'E')
        self.assertEqual(result.streetName, 'PARKWAY')
        self.assertEqual(result.suffixType, 'AVE')
        self.assertEqual(result.suffixDirection, None)
        self.assertEqual(result.normalizedAddressString, '123 E PARKWAY AVE')

        result = parse_address.parse('123 E PARKWAY TRAIL AVE')

        self.assertEqual(result.houseNumber, '123')
        self.assertEqual(result.prefixDirection, 'E')
        self.assertEqual(result.streetName, 'PARKWAY TRAIL')
        self.assertEqual(result.suffixType, 'AVE')
        self.assertEqual(result.suffixDirection, None)
        self.assertEqual(result.normalizedAddressString, '123 E PARKWAY TRAIL AVE')
    def test_steves(self):
        result = parse_address.parse("5301 w jacob hill cir")
        self.assertEqual('5301', result.houseNumber)
        self.assertEqual("JACOB HILL", result.streetName)
        self.assertEqual('CIR', result.suffixType)

        result = parse_address.parse("400 S 532 E")
        self.assertEqual('400', result.houseNumber)
        self.assertEqual("532", result.streetName)
        self.assertEqual('E', result.suffixDirection)

        result = parse_address.parse("5625 S 995 E")
        self.assertEqual('5625', result.houseNumber)
        self.assertEqual("995", result.streetName)
        self.assertEqual('E', result.suffixDirection)

        result = parse_address.parse("372 North 600 East")
        self.assertEqual('372', result.houseNumber)
        self.assertEqual("600", result.streetName)
        self.assertEqual('E', result.suffixDirection)

        result = parse_address.parse("30 WEST 300 NORTH")
        self.assertEqual('30', result.houseNumber)
        self.assertEqual("300", result.streetName)
        self.assertEqual('N', result.suffixDirection)

        result = parse_address.parse("126 E 400 N")
        self.assertEqual('126', result.houseNumber)
        self.assertEqual("400", result.streetName)
        self.assertEqual('N', result.suffixDirection)

        result = parse_address.parse("270 South 1300 East")
        self.assertEqual('270', result.houseNumber)
        self.assertEqual("1300", result.streetName)
        self.assertEqual('E', result.suffixDirection)

        result = parse_address.parse("126 W SEGO LILY DR")
        self.assertEqual('126', result.houseNumber)
        self.assertEqual("SEGO LILY", result.streetName)
        self.assertEqual('DR', result.suffixType)

        result = parse_address.parse("261 E MUELLER PARK RD")
        self.assertEqual('261', result.houseNumber)
        self.assertEqual("MUELLER PARK", result.streetName)
        self.assertEqual('RD', result.suffixType)

        result = parse_address.parse("17 S VENICE MAIN ST")
        self.assertEqual('17', result.houseNumber)
        self.assertEqual("VENICE MAIN", result.streetName)
        self.assertEqual('ST', result.suffixType)

        result = parse_address.parse("20 W Center St")
        self.assertEqual('20', result.houseNumber)
        self.assertEqual("CENTER", result.streetName)
        self.assertEqual('ST', result.suffixType)

        result = parse_address.parse("9314 ALVEY LN")
        self.assertEqual('9314', result.houseNumber)
        self.assertEqual("ALVEY", result.streetName)
        self.assertEqual('LN', result.suffixType)

        result = parse_address.parse("167 DALY AVE")
        self.assertEqual('167', result.houseNumber)
        self.assertEqual("DALY", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1147 MCDANIEL CIR")
        self.assertEqual('1147', result.houseNumber)
        self.assertEqual("MCDANIEL", result.streetName)
        self.assertEqual('CIR', result.suffixType)

        result = parse_address.parse("300 Walk St")
        self.assertEqual('300', result.houseNumber)
        self.assertEqual("WALK", result.streetName)
        self.assertEqual('ST', result.suffixType)

        result = parse_address.parse("5 Cedar Ave")
        self.assertEqual('5', result.houseNumber)
        self.assertEqual("CEDAR", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1238 E 1ST Avenue")
        self.assertEqual('1238', result.houseNumber)
        self.assertEqual("1ST", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1238 E FIRST Avenue")
        self.assertEqual('1238', result.houseNumber)
        self.assertEqual("FIRST", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1238 E 2ND Avenue")
        self.assertEqual('1238', result.houseNumber)
        self.assertEqual("2ND", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1238 E 3RD Avenue")
        self.assertEqual('1238', result.houseNumber)
        self.assertEqual("3RD", result.streetName)
        self.assertEqual('AVE', result.suffixType)

        result = parse_address.parse("1573 24TH Street")
        self.assertEqual('1573', result.houseNumber)
        self.assertEqual("24TH", result.streetName)
        self.assertEqual('ST', result.suffixType)

        # if you dont' have a street name but you have a prefix direction then the
        # prefix diretion is probably the street name.
        result = parse_address.parse("168 N ST")
        self.assertEqual('168', result.houseNumber)
        self.assertEqual("N", result.streetName)
        self.assertEqual('ST', result.suffixType)

        result = parse_address.parse("168 N N ST")
        self.assertEqual('168', result.houseNumber)
        self.assertEqual("N", result.streetName)
        self.assertEqual('ST', result.suffixType)

        result = parse_address.parse("401 N HWY 68")
        self.assertEqual('401', result.houseNumber)
        self.assertEqual("HIGHWAY 68", result.streetName)
        self.assertEqual(None, result.suffixType)

        result = parse_address.parse("401 N SR 68")
        self.assertEqual('401', result.houseNumber)
        self.assertEqual("HIGHWAY 68", result.streetName)
        self.assertEqual(None, result.suffixType)

        result = parse_address.parse("401 N US 89")
        self.assertEqual('401', result.houseNumber)
        self.assertEqual("HIGHWAY 89", result.streetName)
        self.assertEqual(None, result.suffixType)

        result = parse_address.parse("401 N U.S. 89")

        self.assertEqual('401', result.houseNumber)
        self.assertEqual("HIGHWAY 89", result.streetName)
        self.assertEqual(None, result.suffixType)

        result = parse_address.parse("478 S WEST FRONTAGE RD")
        self.assertEqual('478', result.houseNumber)
        self.assertEqual("WEST FRONTAGE", result.streetName)
        self.assertEqual('RD', result.suffixType)

        result = parse_address.parse("1048 W 1205 N")
        self.assertEqual('1048', result.houseNumber)
        self.assertEqual("1205", result.streetName)
        self.assertEqual(None, result.suffixType)
        self.assertEqual('N', result.suffixDirection)

        result = parse_address.parse("2139 N 50 W")
        self.assertEqual('2139', result.houseNumber)
        self.assertEqual("50", result.streetName)
        self.assertEqual(None, result.suffixType)
        self.assertEqual('W', result.suffixDirection)
    def test_suffixDirection(self):
        result = parse_address.parse('123 E 400 N')

        self.assertEqual(result.suffixDirection, 'N')
        self.assertIsNone(result.suffixType)
    def test_multiWordStreetName(self):
        result = parse_address.parse('123 S Main Hello Street')

        self.assertEqual(result.streetName, 'MAIN HELLO')
    def test_streetName(self):
        result = parse_address.parse(add)

        self.assertEqual(result.streetName, 'MAIN')
    def test_prefixDirection(self):
        result = parse_address.parse(add)

        self.assertEqual(result.prefixDirection, 'S')
    def test_whiteSpace(self):
        result = parse_address.parse(' 123 S Main Street ')

        self.assertEqual(result.houseNumber, '123')
 def test_none(self):
     result = parse_address.parse("2819 E Louise")
     self.assertEqual('2819 E LOUISE', result.normalizedAddressString)
    def test_houseNumber(self):
        result = parse_address.parse(add)

        self.assertEqual(result.houseNumber, '123')
    def test_returnNormalizedAddress(self):
        result = parse_address.parse('123 S Main Street')

        self.assertIsInstance(result, parse_address.NormalizedAddress)
    def cleanAddresses():

        print(' * Cleaning Addresses')

        exp = "{0} IS NOT NULL AND {1} IS NULL".format('PARCEL_ADD',
                                                       'PT_ADDRESS')
        print('NEW Where Clause is', exp)

        arcpy.MakeFeatureLayer_management(newParcels, 'newParcelsFl', exp)
        print(arcpy.GetCount_management('newParcelsFl'),
              ' records with Addresses from Parcels'
              )  # should be 2360 on 1/22/20

        def NullOrEmpty(value):
            if value is None:
                return True

            value = value.strip()
            return len(value) < 1

        def NotNumericAddress(value):
            if not value[0].isdigit():
                return True

        def DirWType(value):
            ex = [
                'NORTH CIR', 'SOUTH CIR', 'EAST CIR', 'WEST CIR', 'NORTH ST',
                'SOUTH ST', 'EAST ST', 'WEST ST'
            ]
            return any(value.find(e) > -1 for e in ex)

        def IsApartment(value):
            ex = ['#', '&', '-', 'UNIT', 'BLDG', '/', 'TRLR']
            return any(value.find(e) > -1 for e in ex)

        def IsHWY(value):
            ex = [
                'HWY', 'HIGHWAY', ' CR ', 'COUNTY ROAD', ' SR ', 'STATE ROAD',
                'STATE ROUTE', 'US HIGHWAY', 'U.S. HIGHWAY',
                'UTAH STATE HIGHWAY', 'STATE HIGHWAY'
            ]
            return any(value.find(e) > -1 for e in ex)

        def HasAliasStreet(value):
            return value.find('(') > -1

        def SkipName(value):
            skipNameList = ['TRUNKJUNK']  # JUNK
            return any(value.find(e) > -1 for e in skipNameList)

        with arcpy.da.UpdateCursor(
                'newParcelsFl', ['PARCEL_ADD', 'OrigAddress', 'OID@']) as rows:

            for row in rows:

                if NullOrEmpty(row[1]):
                    continue

                if NotNumericAddress(row[1]):
                    row[0] = ""

                if DirWType(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")

                if IsApartment(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].replace(" NORTH", " N").replace(
                        " SOUTH", " S").replace(" EAST",
                                                " E").replace(" WEST", " W")
                    row[0] = row[1].replace(" WY ", " WAY ").replace(
                        " AV ", " AVE ").replace(" CI ", " CIR ").replace(
                            " COVE ", " CV ").replace(" LA ", " LN ").replace(
                                " TRAIL ", " TRL ").replace(" CRT ", " CT ")

                if IsHWY(row[1]):
                    row[0] = row[1].replace(" COUNTY ROAD ", " CR ")
                    row[0] = row[1].replace(" STATE ROAD ", " SR ")
                    row[0] = row[1].replace(" STATE ROUTE ", " HWY ")
                    row[0] = row[1].replace(" US HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" U.S. HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" UTAH STATE HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" STATE HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if HasAliasStreet(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].replace("ROAD", "RD").replace(
                        "LANE", "LN").replace("DRIVE",
                                              "DR").replace("STREET", "ST")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if SkipName(row[1]):
                    row[0] = row[1].replace("ROAD", "RD").replace(
                        "LANE", "LN").replace("DRIVE", "DR").replace(
                            "STREET", "ST").replace("CIRCLE", "CIR")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if not (NullOrEmpty(row[1]) or NotNumericAddress(row[1])
                        or DirWType(row[1]) or IsApartment(row[1])
                        or IsHWY(row[1]) or HasAliasStreet(row[1])
                        or SkipName(row[1])):
                    address = parse_address.parse(row[1])
                    row[0] = address.normalizedAddressString

##                row[0] = row[0].strip().upper().replace("  "," ").replace(".","").replace(",","").replace(" RD RD"," RD")
                rows.updateRow(row)
    def test_noPrefixDirectionStreetName(self):
        result = parse_address.parse('123 Main Street')

        self.assertEqual(result.streetName, 'MAIN')
        self.assertIsNone(result.prefixDirection)
Ejemplo n.º 18
0
    def cleanAddresses():
        print(' * Cleaning Addresses')

        # might need some additions
        def NullOrEmpty(value):
            if value is None:
                return True

            value = value.strip()
            return len(value) < 1

        def NotNumericAddress(value):
            if not value[0].isdigit():
                return True

        def DirWType(value):
            ex1 = ['NORTH CIR', 'SOUTH CIR', 'EAST CIR', 'WEST CIR']
            return any(value.find(e) > -1 for e in ex1)

        def IsApartment(value):
            ex2 = ['#', '&', '-', 'UNIT', 'BLDG', '/', 'TRLR']
            return any(value.find(e) > -1 for e in ex2)

        def IsHWY(value):
            ex3 = [
                'HWY', 'HIGHWAY', ' CR ', 'COUNTY ROAD', ' SR ', 'STATE ROAD',
                'STATE ROUTE', 'US HIGHWAY', 'U.S. HIGHWAY',
                'UTAH STATE HIGHWAY', 'STATE HIGHWAY'
            ]
            return any(value.find(e) > -1 for e in ex3)

        def HasAliasStreet(value):
            return value.find('(') > -1

        def SkipName(value):
            skipNameList = skipNameList = [
                'E BLUE SKY DR N', 'N BLUE SKY DR E', 'E BLUE SKY DR S',
                'N CLARK PKWY N', 'W CLARK PKWY N', 'S COVE DR',
                'CEDAR KNOLLS WEST', 'CEDAR KNOLLS SOUTH', 'NORTH CEDAR',
                'SOUTH ARTIFACT', 'CENTER'
            ]  # Iron HAS ';;;' in many addrsses
            return any(value.find(e) > -1 for e in skipNameList)

        with arcpy.da.UpdateCursor(newParcels,
                                   ['PARCEL_ADD', 'OrigAddress']) as rows:

            for row in rows:
                if NullOrEmpty(row[1]):
                    continue

                if NotNumericAddress(row[1]):
                    row[0] = ""

                if DirWType(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")

                if IsApartment(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].replace(" NORTH", " N").replace(
                        " SOUTH", " S").replace(" EAST",
                                                " E").replace(" WEST", " W")
                    row[0] = row[1].replace(" WY ", " WAY ").replace(
                        " BOULEVARD ",
                        " BLVD ").replace(" AV ", " AVE ").replace(
                            " CI ",
                            " CIR ").replace(" COVE ",
                                             " CV ").replace(" LA ", " LN ")

                if IsHWY(row[1]):
                    row[0] = row[1].replace(" COUNTY ROAD ", " CR ")
                    row[0] = row[1].replace(" STATE ROAD ", " SR ")
                    row[0] = row[1].replace(" STATE ROUTE ", " HWY ")
                    row[0] = row[1].replace(" US HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" U.S. HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" UTAH STATE HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" STATE HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" HIGHWAY ", " HWY ")
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if HasAliasStreet(row[1]):
                    row[0] = row[1].replace(" NORTH ", " N ").replace(
                        " SOUTH ",
                        " S ").replace(" EAST ",
                                       " E ").replace(" WEST ", " W ")
                    row[0] = row[1].replace("ROAD", "RD").replace(
                        "LANE", "LN").replace("DRIVE",
                                              "DR").replace("STREET", "ST")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if SkipName(row[1]):
                    row[0] = row[1].replace(" WEST CEDAR KNOLLS SOUTH",
                                            " W CEDAR KNOLLS SOUTH").replace(
                                                " SOUTH CEDAR KNOLLS WEST",
                                                " S CEDAR KNOLLS WEST")
                    row[0] = row[1].replace(
                        " EAST CENTER", " E CENTER").replace(
                            " WEST CENTER", " W CENTER").replace(
                                " NORTH CENTER",
                                " N CENTER").replace(" SOUTH CENTER",
                                                     " S CENTER")
                    row[0] = row[1].replace("ROAD", "RD").replace(
                        "LANE", "LN").replace("DRIVE",
                                              "DR").replace("STREET", "ST")
                    row[0] = row[1].strip().upper().replace("  ", " ")

                if not (NullOrEmpty(row[1]) or NotNumericAddress(row[1])
                        or DirWType(row[1]) or IsApartment(row[1])
                        or IsHWY(row[1]) or HasAliasStreet(row[1])
                        or SkipName(row[1])):
                    address = parse_address.parse(row[1])
                    row[0] = address.normalizedAddressString

                else:
                    row[0] = row[0].upper()

                row[0] = row[0].strip().upper().replace("  ", " ").replace(
                    ".", "").replace(",", "").replace(" RD RD", " RD")
                rows.updateRow(row)