private void FindMatchIn(AddressPartResult postalCode)
 {
     if (IsInCorrectLocation(postalCode))
     {
         FindAndMatchLength(postalCode);
     }
 }
Esempio n. 2
0
 protected override void FindPossibleMatch(AddressPartResult part)
 {
     if (EndsWithStreetType(part.Value))
     {
         possibilities.Add(part);
     }
 }
 private static void CapitalizeDirectionalAbbreviation(AddressPartResult result)
 {
     if (result.Value.Length == 2)
     {
         result.Value = result.Value.ToUpper();
     }
 }
Esempio n. 4
0
        private bool IsAPossibleMatch(AddressPartResult match)
        {
            var streetType  = parsedAddress.StreetType;
            var number      = parsedAddress.Number;
            var fraction    = parsedAddress.NumberFraction;
            var directional = parsedAddress.DirectionalPrefix;

            var alphabetic       = IsAlphabetic(match.Value);
            var ordinal          = IsNumberOrdinal(match.Value);
            var beforeStreetType = match.IsBefore(streetType);
            var afterNumber      = match.IsAfter(number);
            var afterFraction    = fraction.IsNotSet() || match.IsAfter(fraction);
            var afterDir         = directional.IsNotSet() || match.IsAfter(directional);

            if ((alphabetic || ordinal) &&
                beforeStreetType &&
                afterNumber &&
                afterFraction &&
                afterDir)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        private bool IsAPossibleMatch(AddressPartResult match)
        {
            SetInstanceVariablesFromContainer();

            //var isAlphabetic = IsAlphabetic(match.Value);
            var isAlphaNumeric           = IsNumericOrAlphaNumeric(match.Value);
            var isOneOrTwoLetters        = IsOneOrTwoLetters(match.Value);
            var isHyphenatedAlphaNumeric = IsHyphenatedAlphaNumeric(match.Value);
            var afterStreetType          = match.IsAfter(streetType);
            var afterDir         = directionalSuffix.IsNotSet() || match.IsAfter(directionalSuffix);
            var afterUnitType    = unitType.IsNotSet() || match.IsAfter(unitType);
            var beforeState      = state.IsNotSet() || match.IsBefore(state);
            var beforePostalCode = postalCode.IsNotSet() || match.IsBefore(postalCode);

            if ((isAlphaNumeric || isOneOrTwoLetters || isHyphenatedAlphaNumeric) &&
                afterStreetType &&
                afterDir &&
                afterUnitType &&
                beforeState &&
                beforePostalCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 6
0
 protected override void FindPossibleMatch(AddressPartResult result)
 {
     if (IsAPossibleMatch(result))
     {
         possibleMatches.Add(result);
     }
 }
Esempio n. 7
0
 private bool IsTwoAfterStreetTypeAndUnitType(AddressPartResult part)
 {
     // A state is never immediately after the street type or unit type
     return(IsTwoAfterStreetType(part) &&
            (parsedAddress.UnitType.IsNotSet() ||
             part.IsAtLeastNAfter(1, parsedAddress.UnitType)));
 }
        private bool IsAPossibleMatch(AddressPartResult match)
        {
            SetInstanceVariablesFromContainer();

            var isAlphabetic     = IsAlphabetic(match.Value);
            var afterStreetType  = match.IsAfter(streetType);
            var afterDir         = directionalSuffix.IsNotSet() || match.IsAfter(directionalSuffix);
            var afterUnitType    = unitType.IsNotSet() || match.IsAtLeastNAfter(2, unitType);
            var beforeState      = state.IsNotSet() || match.IsBefore(state);
            var beforePostalCode = postalCode.IsNotSet() || match.IsBefore(postalCode);

            if (isAlphabetic &&
                afterStreetType &&
                afterDir &&
                afterUnitType &&
                beforeState &&
                beforePostalCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static bool IsLastItemIn(
            this AddressPartResult part,
            IList <AddressPartResult> list)
        {
            var partIndex = list.IndexOf(part);

            return(partIndex == (list.Count - 1));
        }
Esempio n. 10
0
 protected override void FindPossibleMatch(AddressPartResult result)
 {
     if (IsAfterStreetType(result) &&
         IsAPossibleMatch(result.Value))
     {
         possibleMatches.Add(result);
     }
 }
Esempio n. 11
0
 protected override void FindPossibleMatch(AddressPartResult result)
 {
     if (IsAPossibleMatch(result))
     {
         CapitalizeStateAbbreviation(result);
         possibleMatches.Add(result);
     }
 }
Esempio n. 12
0
        private void FindFullPrefixMatch()
        {
            fullPrefix = fullPrefixMatches.Single();

            if (ANumberIsAfterPrefix(fullPrefix))
            {
                SetStreetTypeTo(fullPrefix);
            }
        }
Esempio n. 13
0
        protected override void FindPossibleMatch(AddressPartResult result)
        {
            if (IsAPossibleMatch(result))
            {
                CapitalizeUnitNumberLetters(result);

                possibleMatches.Add(result);
            }
        }
Esempio n. 14
0
 protected override void FindPossibleMatch(AddressPartResult result)
 {
     if (IsNumber(result.Value) ||
         IsNumberThenLetter(result.Value) ||
         IsNumberHyphenSomething(result.Value))
     {
         possibleMatches.Add(result);
     }
 }
Esempio n. 15
0
        private void FindTwoPartPrefixMatch()
        {
            firstPrefix  = firstPrefixMatches.First();
            secondPrefix = secondPrefixMatches.First();

            if (firstPrefix.IsBefore(secondPrefix))
            {
                FindANumberAfterSecondPrefix();
            }
        }
Esempio n. 16
0
        private bool ANumberIsAfterPrefix(AddressPartResult prefix)
        {
            if (prefix.IsLastItemIn(container.AddressPartResults))
            {
                return(false);
            }

            var afterPrefix = prefix.GetItemAfterMeIn(container.AddressPartResults);

            return(IsNumber(afterPrefix.Value));
        }
Esempio n. 17
0
        private AddressPartResult CombineFirstAndSecondResult(
            AddressPartResult first,
            AddressPartResult second)
        {
            var result = new AddressPartResult()
            {
                Value = first.Value + " " + second.Value,
                Index = second.Index,
            };

            return(result);
        }
Esempio n. 18
0
        private void FindPhysicalAddressNumber()
        {
            var match = possibleMatches.First();

            if (IsNumberThenLetter(match.Value))
            {
                var split      = SplitNumberAtLetter(match.Value);
                var numberHalf = new AddressPartResult()
                {
                    Value = split[0],
                    Index = match.Index,
                };

                parsedAddress.Number = numberHalf;

                var letterHalf = new AddressPartResult()
                {
                    Value = split[1],
                    Index = match.Index
                };

                parsedAddress.NumberFraction = letterHalf;
            }
            else if (IsNumberHyphenSomething(match.Value))
            {
                var split = match.Value.Split('-');
                if (split.Length != 2)
                {
                    throw new AddressParsingException("Cannot split the following at hyphen: " + match.Value);
                }

                var numberHalf = new AddressPartResult()
                {
                    Value = split[0],
                    Index = match.Index,
                };

                parsedAddress.Number = numberHalf;

                var letterHalf = new AddressPartResult()
                {
                    Value = split[1],
                    Index = match.Index
                };

                parsedAddress.NumberFraction = letterHalf;
            }
            else if (IsNumber(match.Value))
            {
                parsedAddress.Number = match;
            }
        }
 protected override void FindPossibleMatch(AddressPartResult part)
 {
     if (MatchesAbbreviatedStreetType(part.Value))
     {
         possibleAbbreviatedStreetTypes.Add(part);
         allPossibleStreetTypes.Add(part);
     }
     else if (MatchesFullStreetType(part.Value))
     {
         possibleFullStreetTypes.Add(part);
         allPossibleStreetTypes.Add(part);
     }
 }
        public static AddressPartResult GetItemAfterMeIn(
            this AddressPartResult part,
            IList <AddressPartResult> list)
        {
            if (!part.IsLastItemIn(list))
            {
                var nextIndex = part.Index + 1;

                return(list[nextIndex]);
            }
            else
            {
                return(null);
            }
        }
        public static AddressPartResult GetItemAfter(
            this IList <AddressPartResult> list,
            AddressPartResult part)
        {
            var nextIndex = list.IndexOf(part) + 1;

            if (nextIndex < list.Count)
            {
                return(list[nextIndex]);
            }
            else
            {
                return(null);
            }
        }
        public static bool IsAtLeastNBefore(
            this AddressPartResult firstPart,
            int thisMany,
            AddressPartResult beforeThis)
        {
            if (AreEitherNotSet(firstPart, beforeThis))
            {
                return(false);
            }

            int first  = firstPart.Index + thisMany - 1;
            int second = beforeThis.Index;

            return(first < second);
        }
        public static bool IsAtLeastNAfter(
            this AddressPartResult firstPart,
            int thisMany,
            AddressPartResult afterThis)
        {
            if (AreEitherNotSet(firstPart, afterThis))
            {
                return(false);
            }

            int first  = firstPart.Index;
            int second = afterThis.Index + thisMany - 1;

            return(first > second);
        }
Esempio n. 24
0
 protected override void FindPossibleMatch(AddressPartResult result)
 {
     if (MatchesFullPrefix(result.Value))
     {
         fullPrefixMatches.Add(result);
     }
     else if (MatchesFirstPartOfPrefix(result.Value))
     {
         firstPrefixMatches.Add(result);
     }
     else if (MatchesSecondPartOfPrefix(result.Value))
     {
         secondPrefixMatches.Add(result);
     }
 }
Esempio n. 25
0
        protected override bool IsAPossibleMatch(AddressPartResult match)
        {
            var streetType = parsedAddress.StreetType;

            var patternMatches      = MatchesDirection(match.Value);
            var twoBeforeStreetType = match.IsAtLeastNBefore(2, streetType);

            if (patternMatches && twoBeforeStreetType)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool IsAPossibleMatch(AddressPartResult match)
        {
            SetInstanceVariablesFromContainer();

            var isFourDigits  = IsFourDigits(match.Value);
            var afterPostCode = match.IsAfter(postalCode);

            if (isFourDigits && afterPostCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 private void FindAndMatchLength(AddressPartResult postalCode)
 {
     if (IsNormalLength(postalCode))
     {
         container.ParsedAddress.PostalCode = postalCode;
     }
     else if (HasZipExt(postalCode))
     {
         SetPostalCodeAndExt(postalCode);
     }
     else
     {
         var message = "PostalCode wrong length: " + postalCode.Value;
         throw new AddressParsingException(message);
     }
 }
        private void SetPostalCodeAndExt(AddressPartResult postalCode)
        {
            var firstHalf = new AddressPartResult()
            {
                Value = postalCode.Value.Substring(0, 5),
                Index = postalCode.Index,
            };

            var secondHalf = new AddressPartResult()
            {
                Value = postalCode.Value.Substring(6, 4),
                Index = postalCode.Index,
            };

            container.ParsedAddress.PostalCode    = firstHalf;
            container.ParsedAddress.PostalCodeExt = secondHalf;
        }
Esempio n. 29
0
        private bool IsAPossibleMatch(AddressPartResult match)
        {
            SetInstanceVariablesFromContainer();

            var isFraction          = IsFraction(match.Value);
            var afterNumber         = match.IsAfter(number);
            var twoBeforeStreetType = match.IsAtLeastNBefore(2, streetType);

            if (isFraction && afterNumber && twoBeforeStreetType)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void ConvertPartsToResults()
        {
            var parts = container.AddressParts;
            var index = 0;

            foreach (var part in parts)
            {
                var result = new AddressPartResult()
                {
                    Value = part,
                    Index = index,
                };

                container.AddressPartResults.Add(result);

                index++;
            }
        }