/// <summary>
        /// Get Address Line 1 from Postal Address
        /// Address Line 1 is split into:
        /// PrimaryHighAddress            
        /// StreetPreDirection
        /// StreetName            
        /// StreetSuffix
        /// StreetPostDirection
        /// </summary>
        /// <param name="postalAddress">Postal Address</param>
        private void GetAddress1Fields(PostalAddress postalAddress)
        {
            if (StdAddress == null)
                StdAddress = new StandardAddress();

            Regex lregex = new Regex(@"(?<streetno>(\d{1,5}))\s+(?<streetpre>(("+ Constants.StreetDirections +@")\s+)?)(?<streetname>(\S+(?:\s+\S+)*?)\s+)(?<streetsuffix>(("+ Constants.StreetSuffixCommonUsage + @"))(\s+)?)(?<streetpost>(("+ Constants.StreetDirections + @")+)?)");
            Match lregexMatch = lregex.Match(postalAddress.AddressLine1);

            if (lregexMatch.Success)
            {
                StdAddress.PrimaryHighAddress = lregexMatch.Groups["streetno"].Value.Trim();
                StdAddress.PrimaryLowAddress = lregexMatch.Groups["streetno"].Value.Trim();

                //TODO: Apply Standardization like Suffix for Street Pre and Post Direction.
                StdAddress.StreetPreDirection = lregexMatch.Groups["streetpre"].Value.Trim();
                StdAddress.StreetName = lregexMatch.Groups["streetname"].Value.Trim();

                // Get Standard Suffix.
                if (!string.IsNullOrEmpty(lregexMatch.Groups["streetsuffix"].Value))
                    StdAddress.StreetSuffix = GetStandardStreetSuffix(lregexMatch.Groups["streetsuffix"].Value);
                else
                    StdAddress.StreetSuffix = string.Empty;

                StdAddress.StreetPostDirection = lregexMatch.Groups["streetpost"].Value.Trim();
            }
        }
        /// <summary>
        /// Convert Standard Address to Postal Address
        /// </summary>
        /// <param name="standardAddress">Standard Address</param>
        /// <returns>Postal Address</returns>
        public PostalAddress ConvertStandardAddressToPostal(StandardAddress standardAddress)
        {
            PostalAddress postalAddress = new PostalAddress();

            postalAddress.BuildingOrFirmName = standardAddress.BuildingOrFirmName;

            // Address Line 1
            // <Address Number> <Street Pre Direction> <Street Name> <Street Suffix> <Street Post Direction>
            string buildingAddressLine1 = string.Empty;
            buildingAddressLine1 = Helper.AppendStringWithChar(buildingAddressLine1, standardAddress.PrimaryHighAddress, enmAppendCharacter.Space);
            buildingAddressLine1 = Helper.AppendStringWithChar(buildingAddressLine1, standardAddress.StreetPreDirection, enmAppendCharacter.Space);
            buildingAddressLine1 = Helper.AppendStringWithChar(buildingAddressLine1, standardAddress.StreetName, enmAppendCharacter.Space);
            buildingAddressLine1 = Helper.AppendStringWithChar(buildingAddressLine1, standardAddress.StreetSuffix, enmAppendCharacter.Space);
            buildingAddressLine1 = Helper.AppendStringWithChar(buildingAddressLine1, standardAddress.StreetPostDirection, enmAppendCharacter.Space);
            postalAddress.AddressLine1 = buildingAddressLine1;

            // Address Line 2
            // <Secondary Address Type> <Secondary Address>
            string buildingAddressLine2 = string.Empty;
            buildingAddressLine2 = Helper.AppendStringWithChar(buildingAddressLine2, standardAddress.SecondaryAddressType, enmAppendCharacter.Space);
            buildingAddressLine2 = Helper.AppendStringWithChar(buildingAddressLine2, standardAddress.SecondaryHighAddress, enmAppendCharacter.Space);
            postalAddress.AddressLine2 = buildingAddressLine2;

            postalAddress.City = standardAddress.CityStateKey; // TODO: Need to retrieve from city-state mapping
            postalAddress.State = standardAddress.StateCode;
            postalAddress.Zip5 = standardAddress.ZipCode;
            postalAddress.Zip4 = standardAddress.Zip4AddonHigh;

            postalAddress.UspsAddressId = standardAddress.UspsFileAddressId;

            return postalAddress;
        }
        /// <summary>
        /// Convert Postal Address to Standard Address
        /// </summary>
        /// <param name="postalAddress">Postal Address</param>
        /// <returns>Standard Address</returns>
        public StandardAddress ConvertPostalAddressToStandardAddress(PostalAddress postalAddress)
        {
            StdAddress = new StandardAddress();

            GetAddress1Fields(postalAddress);
            GetAddress2Fields(postalAddress);
            GetCityStateFields(postalAddress);
            GetZipFields(postalAddress);

            return StdAddress;
        }
Esempio n. 4
0
        /// <summary>        
        /// Validates the Address
        /// Standardizes and returns matching standard address.
        /// </summary>
        /// <param name="address1">Address 1</param>
        /// <param name="address2">Address 2</param>
        /// <param name="city">City</param>
        /// <param name="state">State</param>
        /// <param name="zipCode">Zip Code</param>
        /// <param name="zipplusfour">Zip +4</param>
        /// <returns>Standardized Address</returns>
        public Collection<PostalAddress> ValidateAddress(string address1, string address2, string city, string state, string zipCode, string zipplusfour)
        {
            Collection<PostalAddress> standardized = new Collection<PostalAddress>();

            // Create the Address object.
            PostalAddress addressInput = new PostalAddress() { AddressLine1 = address1, AddressLine2 = address2, City = city, State = state, Zip5 = zipCode, Zip4 = zipplusfour };
            StandardAddressParser stdParser = new StandardAddressParser();
            StandardAddress nonstdAddress = stdParser.ConvertPostalAddressToStandardAddress(addressInput);

            // Get Standard Matches.
            MatchDataService matchService = new MatchDataService(Constants.ConnectionString);
            Collection<StandardAddress> matches = matchService.GetMatchingAddressFromDB(nonstdAddress);

            // Convert matches to Postal Address
            PostalAddressParser postalParser = new PostalAddressParser();
            standardized = postalParser.ConvertStandardAddressToPostalAddress(matches);

            return standardized;
        }
        /// <summary>
        /// Get Address 2 Fields
        /// Address Line 2 is split up into:
        /// SecondaryHighAddress, SecondaryLowAddress (both are same mostly)
        /// SecondaryAddressType
        /// </summary>
        /// <param name="postalAddress">Postal Address</param>
        private void GetAddress2Fields(PostalAddress postalAddress)
        {
            if (StdAddress == null)
                StdAddress = new StandardAddress();

            Regex lregex = new Regex(@"(?:(?<addrtype>("+ Constants.AddressTypes + @"))?(?:(?:\s+|-)(?<doorno>\d+)))$");
            Match lregexMatch = lregex.Match(postalAddress.AddressLine2);

            if (lregexMatch.Success)
            {
                StdAddress.SecondaryAddressType = lregexMatch.Groups["addrtype"].Value;
                StdAddress.SecondaryHighAddress = lregexMatch.Groups["doorno"].Value;
                StdAddress.SecondaryLowAddress = lregexMatch.Groups["doorno"].Value;
            }
        }
        /// <summary>
        /// Get Zip Code and Zip+4
        /// Zip 5 is Zip Code
        /// Zip 4 is Zip4AddonHigh and Zip4AddonLow
        /// </summary>
        /// <param name="postalAddress">Postal Address</param>
        private void GetZipFields(PostalAddress postalAddress)
        {
            if (StdAddress == null)
                StdAddress = new StandardAddress();

            StdAddress.ZipCode = postalAddress.Zip5;
            StdAddress.Zip4AddonHigh = postalAddress.Zip4;
            StdAddress.Zip4AddonLow = postalAddress.Zip4;
        }
 private void GetCityStateFields(PostalAddress postalAddress)
 {
 }