Ejemplo n.º 1
0
        /// <summary>
        /// Ищем объект указанного уровня вместе с акронимами во входящей строке адреса
        /// </summary>
        private bool FindLevel(ref string restTail, AddressTemplate tmpl)
        {
            if (string.IsNullOrEmpty(restTail))
            {
                return(false);
            }

            string[] addrParts = restTail.Split(' ');

            //ищем акроним сначала
            int foundLen = 0;
            IEnumerable <ObjGeo> foundList = null;
            var acronyms = FindAcronym(tmpl.Level, 0, 1, addrParts, out foundLen);

            if (foundLen == 0)
            {
                //акронима сначала не нашли - ищем имя объекта
                foundList = FindName(tmpl.Level, 0, 1, addrParts, out foundLen);
                if (foundLen > 0)
                {
                    //если имя найдено - ищем акроним после имени
                    int foundLen2 = 0;
                    acronyms  = FindAcronym(tmpl.Level, 0 + foundLen, 1, addrParts, out foundLen2);
                    foundLen += foundLen2;
                }
            }
            else
            {
                //нашли акроним, далее ищем имя объекта с позиции после акронима
                int foundLen2 = 0;
                foundList = FindName(tmpl.Level, 0 + foundLen, 1, addrParts, out foundLen2);

                if (foundLen2 == 0)
                {
                    //если имени не нашли, то толку от найденного акронима нет.
                    //считаем, что вообще ничего не нашли
                }
                else
                {
                    foundLen += foundLen2;
                }
            }

            restTail = GetStringFromArray(addrParts, foundLen, addrParts.Length - foundLen);
            if (currentFoundState.ContainsKey(tmpl.ID) == false)
            {
                currentFoundState.Add(tmpl.ID, new List <FindEndPoint>());
            }

            if (currentFoundState.ContainsKey(tmpl.ParentID))
            {
                currentFoundState[tmpl.ID].AddRange(CloseLevelFound(currentFoundState[tmpl.ParentID], foundList, acronyms, tmpl, restTail));
            }
            else
            {
                currentFoundState[tmpl.ID].AddRange(CloseLevelFound(null, foundList, acronyms, tmpl, restTail));
            }

            return(currentFoundState[tmpl.ID].Any(point => point.FoundGeo != null && (int)point.FoundGeo.Level == tmpl.Level));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Разрбор строки на предмет номера дома-квартиры
        /// </summary>
        private Location ParseLivingPlace(string restTail, AddressTemplate tmpl)
        {
            Location found = ParseLocation(restTail);

            if (currentFoundState.ContainsKey(tmpl.ID) == false)
            {
                currentFoundState.Add(tmpl.ID, new List <FindEndPoint>());
            }

            if (currentFoundState.ContainsKey(tmpl.ParentID))
            {
                currentFoundState[tmpl.ID].AddRange(CloseBldLevelFound(currentFoundState[tmpl.ParentID], found, this.PostalCode));
            }

            return(found);
        }
Ejemplo n.º 3
0
        internal static IEnumerable<FindEndPoint> CloseLevelFound(IEnumerable<FindEndPoint> parents, IEnumerable<ObjGeo> foundList, IEnumerable<string> foundAcronym, AddressTemplate tmpl, string restTail)
        {
            var ret = new List<FindEndPoint>();
            if (foundList != null)
                foreach (var geo in foundList)
                {
                    ResolveRating rating = foundAcronym != null && foundAcronym.Any(s => s.Equals(geo.AcronymName, StringComparison.InvariantCultureIgnoreCase)) ? ResolveRating.Clear : ResolveRating.AcronymNotFound;

                    if (parents == null)
                    {
                        var point = new FindEndPoint() { FoundGeo = geo, ResolveRating = rating, RestTail = restTail };
                        ret.Add(point);
                    }
                    else
                    {
                        foreach (var point in parents)
                        {
                            rating |= EnsureParentChildConsistency(point.FoundGeo, geo);
                            if (rating < ResolveRating.Excess)
                            {
                                ObjGeo actualGeo = null;
                                //51 Признак актуальности - в актуальное , т.е. в 0
                                if (geo.Actual == 51)
                                {
                                    actualGeo = DbHelper.Select<ObjGeo>("select top 1 * from tblKLADR where OriginalCode in (select NewCode from tbl_KLADR_AltNames where OldCode=@code and Lvl=@lvl)"
                                        , DbHelper.CreateParameter("@code", geo.OriginalCode.Substring(0, geo.OriginalCode.Length - 2) + "00")
                                        , DbHelper.CreateParameter("@lvl", (int)geo.Level + 1)).FirstOrDefault();
                                }

                                var newPoint = new FindEndPoint() { FoundGeo = actualGeo ?? geo, ParentEndPoint = point, ResolveRating = rating | point.ResolveRating, RestTail = restTail };
                                ret.Add(newPoint);
                            }
                        }
                    }
                }

            ret.ForEach(point => point.Template = tmpl);
            return ret;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Разрбор строки на предмет номера дома-квартиры
        /// </summary>
        private Location ParseLivingPlace(string restTail, AddressTemplate tmpl)
        {
            Location found = ParseLocation(restTail);
            if (currentFoundState.ContainsKey(tmpl.ID) == false)
                currentFoundState.Add(tmpl.ID, new List<FindEndPoint>());

            if (currentFoundState.ContainsKey(tmpl.ParentID))
                currentFoundState[tmpl.ID].AddRange(CloseBldLevelFound(currentFoundState[tmpl.ParentID], found, this.PostalCode));

            return found;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Ищем объект указанного уровня вместе с акронимами во входящей строке адреса
        /// </summary>
        private bool FindLevel(ref string restTail, AddressTemplate tmpl)
        {
            if (string.IsNullOrEmpty(restTail))
                return false;

            string[] addrParts = restTail.Split(' ');

            //ищем акроним сначала
            int foundLen = 0;
            IEnumerable<ObjGeo> foundList = null;
            var acronyms = FindAcronym(tmpl.Level, 0, 1, addrParts, out foundLen);
            if (foundLen == 0)
            {
                //акронима сначала не нашли - ищем имя объекта
                foundList = FindName(tmpl.Level, 0, 1, addrParts, out foundLen);
                if (foundLen > 0)
                {
                    //если имя найдено - ищем акроним после имени
                    int foundLen2 = 0;
                    acronyms = FindAcronym(tmpl.Level, 0 + foundLen, 1, addrParts, out foundLen2);
                    foundLen += foundLen2;
                }
            }
            else
            {
                //нашли акроним, далее ищем имя объекта с позиции после акронима
                int foundLen2 = 0;
                foundList = FindName(tmpl.Level, 0 + foundLen, 1, addrParts, out foundLen2);

                if (foundLen2 == 0)
                {
                    //если имени не нашли, то толку от найденного акронима нет. 
                    //считаем, что вообще ничего не нашли
                }
                else
                {
                    foundLen += foundLen2;
                }
            }

            restTail = GetStringFromArray(addrParts, foundLen, addrParts.Length - foundLen);
            if (currentFoundState.ContainsKey(tmpl.ID) == false)
                currentFoundState.Add(tmpl.ID, new List<FindEndPoint>());

            if (currentFoundState.ContainsKey(tmpl.ParentID))
                currentFoundState[tmpl.ID].AddRange(CloseLevelFound(currentFoundState[tmpl.ParentID], foundList, acronyms, tmpl, restTail));
            else
                currentFoundState[tmpl.ID].AddRange(CloseLevelFound(null, foundList, acronyms, tmpl, restTail));

            return currentFoundState[tmpl.ID].Any(point => point.FoundGeo != null && (int)point.FoundGeo.Level == tmpl.Level);
        }
Ejemplo n.º 6
0
        internal static IEnumerable <FindEndPoint> CloseLevelFound(IEnumerable <FindEndPoint> parents, IEnumerable <ObjGeo> foundList, IEnumerable <string> foundAcronym, AddressTemplate tmpl, string restTail)
        {
            var ret = new List <FindEndPoint>();

            if (foundList != null)
            {
                foreach (var geo in foundList)
                {
                    ResolveRating rating = foundAcronym != null && foundAcronym.Any(s => s.Equals(geo.AcronymName, StringComparison.InvariantCultureIgnoreCase)) ? ResolveRating.Clear : ResolveRating.AcronymNotFound;

                    if (parents == null)
                    {
                        var point = new FindEndPoint()
                        {
                            FoundGeo = geo, ResolveRating = rating, RestTail = restTail
                        };
                        ret.Add(point);
                    }
                    else
                    {
                        foreach (var point in parents)
                        {
                            rating |= EnsureParentChildConsistency(point.FoundGeo, geo);
                            if (rating < ResolveRating.Excess)
                            {
                                ObjGeo actualGeo = null;
                                //51 Признак актуальности - в актуальное , т.е. в 0
                                if (geo.Actual == 51)
                                {
                                    actualGeo = DbHelper.Select <ObjGeo>("select top 1 * from tblKLADR where OriginalCode in (select NewCode from tbl_KLADR_AltNames where OldCode=@code and Lvl=@lvl)"
                                                                         , DbHelper.CreateParameter("@code", geo.OriginalCode.Substring(0, geo.OriginalCode.Length - 2) + "00")
                                                                         , DbHelper.CreateParameter("@lvl", (int)geo.Level + 1)).FirstOrDefault();
                                }

                                var newPoint = new FindEndPoint()
                                {
                                    FoundGeo = actualGeo ?? geo, ParentEndPoint = point, ResolveRating = rating | point.ResolveRating, RestTail = restTail
                                };
                                ret.Add(newPoint);
                            }
                        }
                    }
                }
            }

            ret.ForEach(point => point.Template = tmpl);
            return(ret);
        }