Exemplo n.º 1
0
        internal static IEnumerable<FindEndPoint> CloseBldLevelFound(IEnumerable<FindEndPoint> parents, Location loc, string zip)
        {
            var ret = new List<FindEndPoint>();
            var blds = new List<ObjGeo>();
            parents = parents.ToList();
            if (parents.Count() > 0)
                blds = DbHelper.CreateCommand("select * from tblKLADR where GeoType=@lvl5 and ParentCode=@code")
                    .AddParameter("@lvl5", GeoLevelType.Building)
                    .ExpandParameterToList("@code", parents.Select(p => p.FoundGeo.Code)).Select<ObjGeo>().ToList();

            if (!string.IsNullOrEmpty(zip))
            {
                foreach (var bldGeo in blds.Where(bld => bld.Index == zip))
                {
                    var bldRating = loc.BuildingValidate(bldGeo);
                    var point = parents.First(p => p.FoundGeo.Code == bldGeo.ParentCode);
                    var newPoint = new FindEndPoint() { FoundGeo = bldGeo, ParentEndPoint = point, ResolveRating = point.ResolveRating | bldRating };
                    ret.Add(newPoint);
                }
            }
            else
            {
                foreach (var bldGeo in blds.Where(bld => loc.BuildingValidate(bld) == ResolveRating.Clear))
                {
                    var point = parents.First(p => p.FoundGeo.Code == bldGeo.ParentCode);
                    var newPoint = new FindEndPoint() { FoundGeo = bldGeo, ParentEndPoint = point, ResolveRating = point.ResolveRating };
                    ret.Add(newPoint);
                }
            }

            return ret;
        }
Exemplo n.º 2
0
        internal static Location ParseLocation(string originalString)
        {
            Location found = new Location();
            StringBuilder b = new StringBuilder(originalString);
            if (b.Length > 0)
            {
                // ищем а/я
                Match m = PostBoxRx.Match(b.ToString());
                if (m.Groups["postbox"].Success)
                {
                    found.Site = m.Groups["postbox"].Value;
                    found.SiteType = SiteType.PostOfficeBox;
                    b.Replace(m.Value, string.Empty);
                }

                // ищем в/ч
                m = MilitaryBaseRx.Match(b.ToString());
                if (m.Groups["milbase"].Success)
                {
                    found.Site = m.Groups["milbase"].Value;
                    found.SiteType = SiteType.MilitaryBase;
                    b.Replace(m.Value, string.Empty);
                }

                string s = SpaceRx.Replace(b.ToString(), " ").Trim();
                b.Length = 0;
                b.Append(s);

                int cursor = 0;
                m = BldRx.Match(b.ToString(cursor, b.Length - cursor));
                if (m.Groups["bld"].Success)
                {
                    found.Building = m.Groups["bld"].Value.ToUpper();
                    for (cursor += m.Value.Length; cursor < b.Length && b[cursor] == ' '; cursor++) ;
                }
                else
                {
                    b.Length = 0;
                }

                m = BlockRx.Match(b.ToString(cursor, b.Length - cursor));
                if (m.Groups["block"].Success)
                {
                    found.Block = m.Groups["block"].Value.Replace(" ", "");//.ToUpper();
                    if (m.Groups["bt"].Success)
                        found.BlockType = m.Groups["bt"].Value;
                    for (cursor += m.Value.Length; cursor < b.Length && b[cursor] == ' '; cursor++) ;
                }

                m = FlatRx.Match(b.ToString(cursor, b.Length - cursor));

                if (m.Groups["flat"].Success)
                {
                    found.Site = m.Groups["flat"].Value;
                    found.SiteType = SiteType.Flat;
                    for (cursor += m.Value.Length; cursor < b.Length && b[cursor] == ' '; cursor++) ;
                    if (m.Groups["flattype"].Success)
                    {
                        string flattype = m.Groups["flattype"].Value;
                        switch (flattype)
                        {
                            case "к":
                            case "ком":
                            case "комн":
                            case "комната":
                                found.SiteType = SiteType.Room;
                                break;
                            case "лит":
                            case "литера":
                                found.SiteType = SiteType.Letter;
                                break;
                        }
                    }
                }
            }

            return found;
        }
Exemplo n.º 3
0
        public Addr Parse()
        {
            Match m = KozedubAddressRx.Match(this.SourceAddressString);
            _livingPlace = ParseLivingPlace(AddressParser.QuotatRx.Replace(string.Format("{0} {1}", m.Groups["Bld"].Value, m.Groups["Flat"].Value), ""));
            _postalCode = m.Groups["Index"].Value;
            ParseLvl0(m.Groups["Lvl0"].Value);
            ParseLvl14(m.Groups["Lvl1"].Value, GeoLevelType.Region);
            ParseLvl14(m.Groups["Lvl2"].Value, GeoLevelType.City);
            ParseLvl14(m.Groups["Lvl3"].Value, GeoLevelType.Place);
            ParseLvl14(m.Groups["Lvl4"].Value, GeoLevelType.Street);
            ParseLvl5();

            IEnumerable<FindEndPoint> foundList = currentFoundState.Where(p => p.ChildEndPoints.Count() == 0);
            AddressParser.FinallyCheck(foundList, this._postalCode);

            foreach (var point in foundList)
                point.Site = _livingPlace;

            AddressFindList = foundList.OrderBy(p => p.ResolveRating).Select(p => AddressParser.MapToAddr(p)).ToList();
            return foundList.Any(p => p.ResolveRating == ResolveRating.Clear) ? AddressFindList.ElementAt(0) : null;
        }