コード例 #1
0
        public void CanParseMilitaryAddress()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("PSC BOX 453, APO AE 99969");

            Assert.AreEqual("APO", address.City);
            Assert.AreEqual(null, address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("AE", address.State);
            Assert.AreEqual(null, address.Street);
            Assert.AreEqual("PSC BOX 453", address.StreetLine);
            Assert.AreEqual(null, address.Suffix);
            Assert.AreEqual("99969", address.Zip);
        }
コード例 #2
0
        public void CanParsePostOfficeBoxAddress()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("P.O. BOX 4857, New York, NY 10001");

            Assert.AreEqual("NEW YORK", address.City);
            Assert.AreEqual(null, address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("NY", address.State);
            Assert.AreEqual(null, address.Street);
            Assert.AreEqual("PO BOX 4857", address.StreetLine);
            Assert.AreEqual(null, address.Suffix);
            Assert.AreEqual("10001", address.Zip);
        }
コード例 #3
0
        public void CanParseTypicalAddressWithoutPunctuationAfterStreetLine()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("1005 N Gravenstein Highway Sebastopol, CA 95472");

            Assert.AreEqual("SEBASTOPOL", address.City);
            Assert.AreEqual("1005", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual("N", address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("CA", address.State);
            Assert.AreEqual("GRAVENSTEIN", address.Street);
            Assert.AreEqual("1005 N GRAVENSTEIN HWY", address.StreetLine);
            Assert.AreEqual("HWY", address.Suffix);
            Assert.AreEqual("95472", address.Zip);
        }
コード例 #4
0
        public void CanParseFractionalAddress()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("123 1/2 MAIN ST, RICHMOND, VA 23221");

            Assert.AreEqual("RICHMOND", address.City);
            Assert.AreEqual("123 1/2", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("VA", address.State);
            Assert.AreEqual("MAIN", address.Street);
            Assert.AreEqual("123 1/2 MAIN ST", address.StreetLine);
            Assert.AreEqual("ST", address.Suffix);
            Assert.AreEqual("23221", address.Zip);
        }
コード例 #5
0
        public void CanParseAddressWithRangelessSecondaryUnit()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("1050 Broadway Penthouse, New York, NY 10001");

            Assert.AreEqual("NEW YORK", address.City);
            Assert.AreEqual("1050", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual("PH", address.SecondaryUnit);
            Assert.AreEqual("NY", address.State);
            Assert.AreEqual("BROADWAY", address.Street);
            Assert.AreEqual("1050 BROADWAY PH", address.StreetLine);
            Assert.AreEqual(null, address.Suffix);
            Assert.AreEqual("10001", address.Zip);
        }
コード例 #6
0
        public void CanParseAddressWithCardinalStreetName()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("500 SOUTH STREET VIRGINIA BEACH VIRGINIA 23452");

            Assert.AreEqual("VIRGINIA BEACH", address.City);
            Assert.AreEqual("500", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("VA", address.State);
            Assert.AreEqual("SOUTH", address.Street);
            Assert.AreEqual("500 SOUTH ST", address.StreetLine);
            Assert.AreEqual("ST", address.Suffix);
            Assert.AreEqual("23452", address.Zip);
        }
コード例 #7
0
        public void CanParseAddressWithRangedUnitAttachedToNumber()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("403D BERRYFIELD LANE CHESAPEAKE VA 23224");

            Assert.AreEqual("CHESAPEAKE", address.City);
            Assert.AreEqual("403", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual("D", address.SecondaryNumber);
            Assert.AreEqual("APT", address.SecondaryUnit);
            Assert.AreEqual("VA", address.State);
            Assert.AreEqual("BERRYFIELD", address.Street);
            Assert.AreEqual("403 BERRYFIELD LN APT D", address.StreetLine);
            Assert.AreEqual("LN", address.Suffix);
            Assert.AreEqual("23224", address.Zip);
        }
コード例 #8
0
        public void CanParseAddressWithSpacedAlphanumericRange()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("N645 W23001 BLUEMOUND ROAD, ROLLING MEADOWS, IL, 12345");

            Assert.AreEqual("ROLLING MEADOWS", address.City);
            Assert.AreEqual("N645W23001", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("IL", address.State);
            Assert.AreEqual("BLUEMOUND", address.Street);
            Assert.AreEqual("N645W23001 BLUEMOUND RD", address.StreetLine);
            Assert.AreEqual("RD", address.Suffix);
            Assert.AreEqual("12345", address.Zip);
        }
コード例 #9
0
        public void CanParseQueensStyleAddress()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("123-465 34th St New York NY 12345");

            Assert.AreEqual("NEW YORK", address.City);
            Assert.AreEqual("123-465", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual(null, address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("NY", address.State);
            Assert.AreEqual("34TH", address.Street);
            Assert.AreEqual("123-465 34TH ST", address.StreetLine);
            Assert.AreEqual("ST", address.Suffix);
            Assert.AreEqual("12345", address.Zip);
        }
コード例 #10
0
        public void CanParseGridStyleAddress()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("842 E 1700 S, Salt Lake City, UT 84105");

            Assert.AreEqual("SALT LAKE CITY", address.City);
            Assert.AreEqual("842", address.Number);
            Assert.AreEqual("S", address.Postdirectional);
            Assert.AreEqual("E", address.Predirectional);
            Assert.AreEqual(null, address.SecondaryNumber);
            Assert.AreEqual(null, address.SecondaryUnit);
            Assert.AreEqual("UT", address.State);
            Assert.AreEqual("1700", address.Street);
            Assert.AreEqual("842 E 1700 S", address.StreetLine);
            Assert.AreEqual(null, address.Suffix);
            Assert.AreEqual("84105", address.Zip);
        }
コード例 #11
0
        public void CanParseAddressWithoutPunctuation()
        {
            var parser  = new AddressParser();
            var address = parser.ParseAddress("999 West 89th Street Apt A New York NY 10024");

            Assert.AreEqual("NEW YORK", address.City);
            Assert.AreEqual("999", address.Number);
            Assert.AreEqual(null, address.Postdirectional);
            Assert.AreEqual("W", address.Predirectional);
            Assert.AreEqual("A", address.SecondaryNumber);
            Assert.AreEqual("APT", address.SecondaryUnit);
            Assert.AreEqual("NY", address.State);
            Assert.AreEqual("89TH", address.Street);
            Assert.AreEqual("999 W 89TH ST APT A", address.StreetLine);
            Assert.AreEqual("ST", address.Suffix);
            Assert.AreEqual("10024", address.Zip);
        }
コード例 #12
0
        static void Main(string[] args)
        {
            var parser = new AddressParser();
            var loop   = false;

            Console.WriteLine("Address Parser Driver");
            Console.WriteLine(new string('-', 40));
            Console.WriteLine();
            Console.WriteLine("Example Input:");
            Console.WriteLine("125 Main St, Richmond VA 23221");
            Console.WriteLine();

            do
            {
                Console.WriteLine("Type an address and press <ENTER>:");
                var input = Console.ReadLine();

                var result = parser.ParseAddress(input);
                if (result == null)
                {
                    Console.WriteLine("ERROR. Input could not be parsed.");
                }
                else
                {
                    Console.WriteLine("RESULT: {0}", result);

                    var properties = result
                                     .GetType()
                                     .GetProperties()
                                     .OrderBy(x => x.Name);
                    foreach (var property in properties)
                    {
                        Console.WriteLine(
                            "{0,30} : {1}",
                            property.Name,
                            property.GetValue(result, null));
                    }
                }

                Console.WriteLine();
                Console.Write("Try again? [Y/N] ");

                loop = Console.ReadLine().ToUpperInvariant() == "Y";
            }while (loop);
        }
コード例 #13
0
 public void CanParseAddressWithAlphanumericRange()
 {
     Approvals.Verify(Parser.ParseAddress("N6W23001 BLUEMOUND ROAD, ROLLING MEADOWS, IL, 12345"));
 }
コード例 #14
0
 private string extractCity(string city)
 {
     return(_parser.ParseAddress("Addr", "12345", city).City);
 }
コード例 #15
0
ファイル: TruliaBot.cs プロジェクト: naikhpratik/Odin-Master
        //Back up in case there is no JSON on page.
        private Property BotProperty()
        {
            Property      prop           = new Property();
            AddressParser addrParser     = new AddressParser();
            var           summaryContent = _doc.QuerySelector(".summaryContent");

            //Parse Address
            var address      = summaryContent.QuerySelector("div.pan").InnerText;
            var cityStateZip = summaryContent.QuerySelector("div.mts").InnerText;

            var addr = addrParser.ParseAddress(address + ", " + cityStateZip);

            prop.Street1    = addr.StreetLine;
            prop.Street2    = addr.SecondaryUnit + addr.SecondaryNumber;
            prop.City       = addr.City;
            prop.State      = addr.State;
            prop.PostalCode = addr.Zip;

            //Parse Bed/Bad/Sqft
            Regex numReg      = new Regex(@"[+-]?(\d*\.)?\d+");
            var   detailsList = _doc.QuerySelectorAll("div[data-auto-test-id='home-details-overview'] li");

            foreach (var detail in detailsList)
            {
                var text = detail.InnerText.ToUpper().CleanNumeric();
                if (text.Contains("BED"))
                {
                    int temp;
                    if (Int32.TryParse(numReg.Match(text).Value, out temp))
                    {
                        prop.NumberOfBedrooms = temp;
                    }
                }
                else if (text.Contains("BATH"))
                {
                    decimal temp;
                    if (Decimal.TryParse(numReg.Match(text).Value, out temp))
                    {
                        prop.NumberOfBathrooms = temp;
                    }
                }
                else if (text.Contains("SQFT") && !text.Contains("/"))
                {
                    int temp;
                    if (Int32.TryParse(numReg.Match(text).Value, out temp))
                    {
                        prop.SquareFootage = temp;
                    }
                }
            }

            //Parse Price
            var priceTag = summaryContent.QuerySelector("span.h3");

            if (priceTag != null)
            {
                decimal temp;
                if (Decimal.TryParse(priceTag.InnerText.CleanNumeric(), out temp))
                {
                    prop.Amount = temp;
                }
            }
            prop.SourceUrl = _url;
            return(prop);
        }
コード例 #16
0
ファイル: TruliaBot.cs プロジェクト: naikhpratik/Odin-Master
        //Back up in case there is no JSON on page.
        private Property BotRental()
        {
            Property      prop       = new Property();
            AddressParser addrParser = new AddressParser();
            var           propDetail = _doc.QuerySelector("#propertyDetails");

            //Parse Address
            AddressParseResult addr;
            var streetTag = propDetail.QuerySelector("span[itemprop='streetAddress']");

            if (streetTag != null)
            {
                var street = streetTag.InnerText;
                var city   = propDetail.QuerySelector("span[itemprop='addressLocality']").InnerText;
                var state  = propDetail.QuerySelector("span[itemprop='addressRegion']").InnerText;
                var zip    = propDetail.QuerySelector("span[itemprop='postalCode']").InnerText;

                var fullAddress = street + ", " + city + ", " + state + " " + zip;
                addr = addrParser.ParseAddress(fullAddress);
            }
            else
            {
                Regex zipReg      = new Regex(@"\w{2}\s+([0-9]{5})");
                var   headlineStr = propDetail.QuerySelector(".headlineDoubleSub").InnerText.Replace("\n", "");
                var   zip         = zipReg.Match(headlineStr).Groups[1].Value;
                var   addrStr     = headlineStr.StringEndingAt(zip);

                addr = addrParser.ParseAddress(addrStr);
            }

            prop.Street1    = addr.StreetLine;
            prop.Street2    = addr.SecondaryUnit + addr.SecondaryNumber;
            prop.City       = addr.City;
            prop.State      = addr.State;
            prop.PostalCode = addr.Zip;

            //Parse Bed/Bath
            Regex numReg      = new Regex(@"[+-]?(\d*\.)?\d+");
            var   bedBathList = propDetail.QuerySelectorAll(".listBulleted > li");

            foreach (var bedBath in bedBathList)
            {
                var text = bedBath.InnerText.ToUpper().CleanNumeric();
                if (text.Contains("BED"))
                {
                    int temp;
                    if (Int32.TryParse(numReg.Match(text).Value, out temp))
                    {
                        prop.NumberOfBedrooms = temp;
                    }
                }
                else if (text.Contains("BATH"))
                {
                    decimal temp;
                    if (Decimal.TryParse(numReg.Match(text).Value, out temp))
                    {
                        prop.NumberOfBathrooms = temp;
                    }
                }
            }

            //Parse Price
            var priceTag = _doc.QuerySelector(".priceModule");

            if (priceTag != null)
            {
                var     priceText = priceTag.InnerText;
                decimal tempDec;
                if (Decimal.TryParse(numReg.Match(priceText).Value.CleanNumeric(), out tempDec))
                {
                    prop.Amount = tempDec;
                }
            }

            prop.SourceUrl = _url;
            return(prop);
        }