Ejemplo n.º 1
0
        private double MatchStreetName(StreetAddress c1, StreetAddress c2, double weightNumber, double weightStrName)
        {
            double score = 0;

            if (c1.Number != null && c2.Number != null)
            {
                score += weightNumber * base.Distance(c1.Number, c2.Number);
            }

            double maxScoreStr = 0;

            if (c1.Name != null && c2.Name != null)
            {
                //Try perfect match
                if (c1.Suffix != null && c2.Suffix != null)
                {
                    maxScoreStr = base.Distance(c1.Name, c2.Name) * 0.8;
                    if (maxScoreStr != 0)
                    {
                        maxScoreStr += base.Distance(c1.Suffix, c2.Suffix) * 0.2;
                    }
                }

                //Try removing either of suffixes, adding the other to the street name
                if (c1.Suffix != null)
                {
                    maxScoreStr = TryMatch(String.Format("{0} {1}", c1.Name, c1.Suffix), c2.Name, maxScoreStr, 1.0);
                }
                if (c2.Suffix != null)
                {
                    maxScoreStr = TryMatch(String.Format("{0} {1}", c2.Name, c2.Suffix), c1.Name, maxScoreStr, 1.0);
                }

                //Try ignoring suffixes, but dump value by 0.3
                maxScoreStr = TryMatch(c1.Name, c2.Name, maxScoreStr, (c1.Suffix == null && c2.Suffix == null) ? 1.0 : 0.7);
            }
            else
            {
                //No street in one of addresses or both, test each with prefix of the other
                if (c1.Name != null && c2.Suffix != null)
                {
                    maxScoreStr = TryMatch(String.Format("{0} {1}", c1.Name, c1.Suffix), c2.Suffix, maxScoreStr, 0.7);
                    maxScoreStr = TryMatch(c1.Name, c2.Suffix, maxScoreStr, 0.7);
                }
                if (c2.Name != null && c1.Suffix != null)
                {
                    maxScoreStr = TryMatch(String.Format("{0} {1}", c2.Name, c2.Suffix), c1.Suffix, maxScoreStr, 0.7);
                    maxScoreStr = TryMatch(c2.Name, c1.Suffix, maxScoreStr, 0.7);
                }
                if (c1.Name == null && c2.Name == null && c1.Suffix != null && c2.Suffix != null)
                {
                    maxScoreStr = TryMatch(c1.Suffix, c2.Suffix, maxScoreStr, 0.1);
                }
            }

            if (maxScoreStr != 0)
            {
                score += maxScoreStr * weightStrName;
            }

            //Try to ignore number, and just compare strings of number + street + suffix. This will be adjusted by 0.6
            score = Math.Max(score, base.Distance(c1.toStringNoL2(), c2.toStringNoL2()) * (weightNumber + weightStrName) * 0.6);

            return(score);
        }