예제 #1
0
        public List <gtgGeocodeCandidate> GenerateCandidates(gtgStandardizeResult AddressIn)       //, ILog logFile)
        {
            //const string LOCAL = _MOD + "GenerateCandidates(gtgStandardizeResult, ILog) ";
            var ret = new List <gtgGeocodeCandidate>();

            try
            {
                //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Info,
                //                          String.Format("Entering {0}: AddressIn.OriginalAddress: {1}", LOCAL, AddressIn.OriginalAddress));

                foreach (gtgGeocodeDataset ds in GeocoderDatasets)
                {
                    if (ds.RecordFamilies.ContainsKey(AddressIn.StreetNameSoundex))
                    {
                        foreach (gtgGeocodeRecord r in ds.RecordFamilies[AddressIn.StreetNameSoundex].Addresses)
                        {
                            var c = new gtgGeocodeCandidate();
                            if (r.AddressStandardized.HouseNumber != AddressIn.HouseNumber)
                            {
                                c.Score -= 15;
                            }

                            if (r.AddressStandardized.PreDir != AddressIn.PreDir)
                            {
                                c.Score -= 5;
                            }

                            if (r.AddressStandardized.StreetName != AddressIn.StreetName)
                            {
                                c.Score -= Compute(r.AddressStandardized.StreetName, AddressIn.StreetName);//, logFile );
                            }
                            if (r.AddressStandardized.StreetType != AddressIn.StreetType)
                            {
                                c.Score -= 5;
                            }

                            if (r.AddressStandardized.SufDir != AddressIn.SufDir)
                            {
                                c.Score -= 5;
                            }

                            if (r.AddressStandardized.Unit != AddressIn.Unit)
                            {
                                c.Score -= 5;
                            }

                            if (r.AddressStandardized.Zone != AddressIn.Zone && !string.IsNullOrWhiteSpace(AddressIn.Zone))
                            {
                                c.Score -= 10;
                            }

                            if (c.Score >= ds.MinMatchScore)
                            {
                                c.Candidate = r;
                                ret.Add(c);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
            }
            return(ret);
        }
예제 #2
0
        public gtgStandardizeResult StandardizeAddress(string strAddress)        //, ILog logFile)
        {
            //const string LOCAL = _MOD + "StandardizeAddress(string, ILog) ";

            var    ret       = new gtgStandardizeResult();
            string tmpString = null;

            try
            {
                //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Info,
                //                          String.Format("Entering {0}: strAddress: {1}", LOCAL, strAddress));

                ret.OriginalAddress = strAddress;
                var regx = new Regex("(?:[^ ]),|, +| +");
                ret.OriginalAddress = regx.Replace(strAddress, delegate(Match m)
                {
                    var val = m.Value;
                    if (val.Equals("(?:[^ ]),)"))
                    {
                        return(" ,");
                    }

                    return(val.Equals(", +") ? "," : " ");
                });

                string[] strSplit = ret.OriginalAddress.Trim().ToUpper().Split(
                    new[]
                {
                    ' '
                });
                int   startIndex       = 0;
                int   endIndex         = strSplit.Length - 1;
                bool  bStreetTypeFound = false;
                float tmpFloat;

                if (float.TryParse(strSplit[0], out tmpFloat))
                {
                    ret.HouseNumber = tmpFloat;
                    tmpString       = ((strSplit.Length > 1) ? strSplit[1] : string.Empty);
                    switch (tmpString)
                    {
                    case "1/2":
                        ret.HouseNumber += 0.5f;
                        startIndex       = 2;
                        break;

                    case "1/4":
                        ret.HouseNumber += 0.25f;
                        startIndex       = 2;
                        break;

                    case "3/4":
                        ret.HouseNumber += 0.75f;
                        startIndex       = 2;
                        break;

                    default:
                        startIndex = 1;
                        break;
                    }
                }

                if (m_Direction.TryGetValue(
                        (strSplit.Length > startIndex) ? strSplit[startIndex] : string.Empty, out tmpString))
                {
                    ret.PreDir = tmpString;
                    startIndex++;
                }

                for (int j = endIndex; j >= startIndex; j--)
                {
                    try
                    {
                        if (!m_Street_Type.TryGetValue(strSplit[j], out tmpString))
                        {
                            continue;
                        }
                        ret.StreetType   = tmpString;
                        endIndex         = j - 1;
                        bStreetTypeFound = true;
                        break;
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                        //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
                    }
                }

                if (!bStreetTypeFound)
                {
                    for (int i = endIndex - 1; i >= startIndex; i--)
                    {
                        try
                        {
                            if (!m_Multi_Unit.TryGetValue(strSplit[i], out tmpString))
                            {
                                continue;
                            }
                            ret.Unit = tmpString;
                            endIndex = i - 1;
                            break;
                        }
                        catch (IndexOutOfRangeException) {}
                    }

                    for (int i = endIndex; i >= startIndex; i--)
                    {
                        try
                        {
                            if (!m_Direction.TryGetValue(strSplit[i], out tmpString))
                            {
                                continue;
                            }
                            ret.PreDir = tmpString;
                            endIndex   = i - 1;
                            break;
                        }
                        catch (IndexOutOfRangeException)
                        {
                            //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                            //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
                        }
                    }
                }

                for (int i = startIndex; i <= endIndex; i++)
                {
                    try
                    {
                        if (m_Abbreviation.TryGetValue(strSplit[i], out tmpString))
                        {
                            ret.StreetName = ret.StreetName + " " + tmpString;
                        }
                        else
                        {
                            ret.StreetName = ret.StreetName + " "
                                             + (m_Ordinal_Number.TryGetValue(strSplit[i], out tmpString) ? tmpString : strSplit[i]);
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                        //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
                        break;
                    }
                }

                ret.StreetName = ret.StreetName.Trim();
                foreach (var kp in m_Abbreviation_Multi_Word)
                {
                    ret.StreetName = ret.StreetName.Replace(kp.Key, kp.Value);
                }

                startIndex = endIndex + 1;
                endIndex   = strSplit.Length - 1;

                for (int i = startIndex; i <= endIndex; i++)
                {
                    try
                    {
                        if (!m_Direction.TryGetValue(strSplit[i], out tmpString))
                        {
                            continue;
                        }
                        ret.SufDir = tmpString;
                        startIndex = i + 1;
                        break;
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                        //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
                        break;
                    }
                }

                for (int i = startIndex; i <= endIndex; i++)
                {
                    try
                    {
                        if (!m_Multi_Unit.TryGetValue(strSplit[i], out tmpString))
                        {
                            continue;
                        }
                        ret.Unit = strSplit[i];
                        break;
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                        //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
                        break;
                    }
                }

                for (int i = startIndex; i <= endIndex; i++)
                {
                    try
                    {
                        if (!strSplit[i].Contains(","))
                        {
                            continue;
                        }
                        string[] strZoneSplit = strSplit[i].Split(
                            new[]
                        {
                            ','
                        });
                        if (strZoneSplit.Length > 1)
                        {
                            ret.Zone = strZoneSplit[1].Trim();
                        }
                        break;
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }
                ret.StreetNameSoundex = GenerateSoundexCode(ret.StreetName);//, logFile );
            }
            catch (Exception)
            {
                //UTIL.Utilities.LogMessage(logFile, UTIL.Utilities.LogType.Error,
                //                          String.Format(Constants.FMT_ERROR_IN, LOCAL), ex);
            }
            return(ret);
        }