Exemplo n.º 1
0
 public void GenerateCandidates()
 {
     try
     {
         Logging.LogMethodCall(ClassName);
         Matches.Clear();
         if (string.IsNullOrWhiteSpace(Address))
         {
             MessageBox.Show("You must enter an address to search for.  Please try again.");
         }
         else
         {
             StandardizeResult sr = StandardizeAddress(Address);
             if (!string.IsNullOrWhiteSpace(Zone))
             {
                 sr.Zone = Zone.Trim().ToUpper();
             }
             Matches = new ObservableCollection <GeocodeCandidate>(GenerateCandidates(sr));
             if (Matches.Count <= 0)
             {
                 MessageBox.Show("No results found.  Please try again.");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Exemplo n.º 2
0
        private StandardizeResult StandardizeAddress(string address)
        {
            Logging.LogMethodCall(ClassName, () => new Dictionary <String, Object> {
                { nameof(address), address }
            });
            var    ret       = new StandardizeResult();
            string tmpString = null;

            try
            {
                ret.OriginalAddress = address;
                var regx = new Regex(" +");
                ret.OriginalAddress = regx.Replace(address, " ").Trim();

                string[] strSplit   = ret.OriginalAddress.ToUpper().Split(' ');
                int      startIndex = 0;
                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;
                    }
                }
                for (int i = startIndex; i <= strSplit.Length - 1; i++)
                {
                    try
                    {
                        if (strSplit[i].Contains(','))
                        {
                            string[] strZoneSplit = strSplit[i].Split(',');
                            if (strZoneSplit.Length > 1)
                            {
                                ret.Zone = strZoneSplit[1].Trim();
                            }
                        }
                        else
                        {
                            ret.StreetName += " " + strSplit[i];
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        break;
                    }
                }
                ret.StreetName        = ret.StreetName.Trim();
                ret.StreetNameSoundex = GenerateSoundexCode(ret.StreetName);
            }
            catch (Exception ex)
            {
                Logging.LogMessage(Logging.LogType.Error, "error on standardize address - " + address, ex);
            }
            return(ret);
        }
Exemplo n.º 3
0
        private List <GeocodeCandidate> GenerateCandidates(StandardizeResult AddressIn)
        {
            Logging.LogMethodCall(ClassName, () => new Dictionary <String, Object> {
                { nameof(AddressIn), AddressIn }
            });
            var ret = new List <GeocodeCandidate>();

            try
            {
                foreach (GeocodeDataset ds in GeocoderDatasets)
                {
                    if (ds.RecordFamilies.ContainsKey(AddressIn.StreetNameSoundex))
                    {
                        foreach (GeocodeRecord r in ds.RecordFamilies[AddressIn.StreetNameSoundex])
                        {
                            var c = new GeocodeCandidate();
                            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 -= ComputeMinDifference(r.AddressStandardized.StreetName, AddressIn.StreetName);
                            }
                            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;
                                int index = 0;
                                for (index = 0; index < ret.Count - 1; index++)
                                {
                                    if (ret[index].Score < c.Score)
                                    {
                                        break;
                                    }
                                }
                                if (index >= ret.Count)
                                {
                                    ret.Add(c);
                                }
                                else
                                {
                                    ret.Insert(index, c);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.LogMessage(Logging.LogType.Error, "error generating candidates for - " + AddressIn.OriginalAddress, ex);
            }
            return(ret);
        }