Esempio n. 1
0
        private static string[] LoadNYStateStreets(Data data)
        {
            //string[] streets = File.ReadAllLines("allStreets.csv");
            string[] streets = File.ReadAllLines("state_of_new_york_revised.csv").ToArray();
            return(streets.Distinct().ToArray());

            string[] streetsRevised = new string[streets.Length + 1];

            List <string> streetsCleaned = new List <string>();

            for (int i = 0; i < streets.Length; i++)
            {
                string street = streets[i];
                street = AddressUtility.CleanSpacesAndPunctuation(street);
                street = AddressUtility.CleanAddressFormat(street, data.AbbreviationsShortened);
                street = AddressUtility.NormalizeSuffix(street, data).FullStreetName;
                streetsCleaned.Add(street);
                streetsRevised[i] = street;
                //Console.Write($"{streets[i]} => {street},     ");
            }

            File.WriteAllLines("state_of_new_york_revised.csv", streetsRevised);

            return(streetsCleaned.Distinct().ToArray());
        }
Esempio n. 2
0
        private static string CorrectAddress(Data data, ref Address address, string correctedString)
        {
            Address correctStreet = AddressUtility.NormalizeSuffix(correctedString, data);

            address.StreetName   = correctStreet.StreetName;
            address.Suffix       = correctStreet.Suffix;
            address.MatchQuality = MatchQuality.Alternate;
            return($"{address.StreetName} {address.Suffix}");
        }
Esempio n. 3
0
        private static List <StateOfNewYorkAddressRange> LoadNYCityAddresses(Data data)
        {
            string[] addresses = File.ReadAllLines("city_of_new_york_revised.csv").Skip(1).ToArray();
            //string[] addressesRevised = new string[addresses.Length + 1];
            //addressesRevised[0] = addresses[0];
            //int counter = 1;

            List <StateOfNewYorkAddressRange> ret = new List <StateOfNewYorkAddressRange>();

            foreach (string address in addresses)
            {
                string[] bits = address.Split(',').Select(n => n.Trim()).ToArray();

                string addressBit = bits[3];
                string numberBit  = bits[2];
                int    zip        = -1;
                int.TryParse(bits[8], out zip);
                string city = bits[5];
                string nonNumberNumberAddress = "";



                //// Clean up addressBit
                //addressBit = AddressUtility.CleanSpacesAndPunctuation(addressBit);
                //addressBit = AddressUtility.CleanAddressFormat(addressBit, data.AbbreviationsShortened);
                Address cleanAddress = AddressUtility.NormalizeSuffix(addressBit, data);
                ////Console.Write($"{bits[3]} => {cleanAddress.FullStreetName},     ");
                //addressesRevised[counter++] = string.Join(",", bits.Take(3)) + $",{cleanAddress.FullStreetName}," + string.Join(",",bits.Skip(4));

                //if(cleanAddress.FullStreetName != addressBit)
                //{
                //    Console.WriteLine($"{addressBit} => {cleanAddress.FullStreetName}");
                //}

                // Parse numberBit
                int startNumber = -1, endNumber = -1;

                if (Regex.IsMatch(numberBit, @"^\d+-\d+$"))
                {
                    int[] numberBitBits = numberBit.Split('-').Select(n => int.Parse(n)).ToArray();

                    int start = 0, end = 0;

                    if (numberBitBits[0] > numberBitBits[1])
                    {
                        start = numberBitBits[1];
                        end   = numberBitBits[0];
                    }
                    else
                    {
                        start = numberBitBits[0];
                        end   = numberBitBits[1];
                    }

                    startNumber = start;
                    endNumber   = end;
                }
                else if (Regex.IsMatch(numberBit, @"^\d+$"))
                {
                    startNumber = int.Parse(numberBit);
                    endNumber   = int.Parse(numberBit);
                }
                else if (numberBit.Length > 0)
                {
                    nonNumberNumberAddress = numberBit;
                }

                lock (ret)
                {
                    if (!string.IsNullOrEmpty(nonNumberNumberAddress))
                    {
                        ret.Add(new StateOfNewYorkAddressRange
                        {
                            StreetNumber   = new StreetNumberRange(nonNumberNumberAddress),
                            City           = city,
                            StreetName     = cleanAddress.StreetName,
                            ZipCode        = zip,
                            Suffix         = cleanAddress.Suffix,
                            FullStreetName = cleanAddress.FullStreetName,
                        });
                    }
                    else
                    {
                        ret.Add(new StateOfNewYorkAddressRange
                        {
                            StreetNumber   = new StreetNumberRange(startNumber, endNumber),
                            City           = city,
                            StreetName     = cleanAddress.StreetName,
                            ZipCode        = zip,
                            Suffix         = cleanAddress.Suffix,
                            FullStreetName = cleanAddress.FullStreetName,
                        });
                    }
                }
            }

            //File.WriteAllLines("city_of_new_york_revised.csv", addressesRevised);


            return(ret);
        }