Пример #1
0
        private List <RecognitionResulType> MatchFrasesPNA(string city, string street, string pna)
        {
            List <RecognitionResulType> Results = new List <RecognitionResulType>();

            string input = city + street;

            input = ZnakiPL(RemoveAllSpecialCharacters(input, true, true, true, true)).ToLower();



            List <DictType> DictByPNA = new List <DictType>();

            DictByPNA = (from o in Dict
                         where ZnakiPL(RemoveAllSpecialCharacters(o.CITY_STREET_LOWER(), true, true, true, true)) == ZnakiPL(RemoveAllSpecialCharacters(city.ToLower(), true, true, true, true))
                         select o).ToList();

            if (DictByPNA.Count == 1)
            {
                if (ZnakiPL(RemoveAllSpecialCharacters(DictByPNA[0].CITY_STREET_LOWER(), true, true, true, true)).Contains(ZnakiPL(RemoveAllSpecialCharacters(street.ToLower(), true, true, true, true))))
                {
                    RecognitionResulType R = new RecognitionResulType();
                    R.Input           = city + " " + street + " " + pna;
                    R.Method          = "MatchFrases_By_PNA";
                    R.ResultDict      = DictByPNA[0];
                    R.MatchPercentage = 100.00;

                    if (!Results.Contains(R))
                    {
                        Results.Add(R);
                    }
                }
            }


            foreach (var o in DictByPNA)
            {
                string dictfraase = ZnakiPL(RemoveAllSpecialCharacters(o.CITY_STREET_LOWER(), true, true, true, true)).ToLower();
                if (dictfraase.Contains(ZnakiPL(RemoveAllSpecialCharacters(city, true, true, true, true)).ToLower()))
                {
                    if (dictfraase.Contains(ZnakiPL(RemoveAllSpecialCharacters(street, true, true, true, true)).ToLower()))
                    {
                        RecognitionResulType R = new RecognitionResulType();
                        R.Input           = city + " " + street + " " + pna;
                        R.Method          = "MatchFrasesPNA_ByCityStreet";
                        R.ResultDict      = o;
                        R.MatchPercentage = 100.00;

                        if (!Results.Contains(R))
                        {
                            Results.Add(R);
                        }
                    }
                }
            }


            foreach (var o in DictByPNA)
            {
                string dictfraase = ZnakiPL(RemoveAllSpecialCharacters(o.CITY_STREET_LOWER(), true, true, true, true)).ToLower();

                foreach (var cityword in city.Split(' '))
                {
                    if (dictfraase.Contains(ZnakiPL(cityword).ToLower()))
                    {
                        foreach (var streetword in street.Split(' '))
                        {
                            if (dictfraase.Contains(ZnakiPL(streetword).ToLower()))
                            {
                                RecognitionResulType R = new RecognitionResulType();
                                R.Input           = city + " " + street + " " + pna;
                                R.Method          = "MatchFrasesPNA_ByPartOf_CityStreet";
                                R.ResultDict      = o;
                                R.MatchPercentage = 100.00;

                                if (!Results.Contains(R))
                                {
                                    Results.Add(R);
                                }
                            }
                        }
                    }
                }
            }


            if (Results.Count == 0)
            {
                DictByPNA = (from o in Dict
                             where o.PNA == pna
                             select o).ToList();

                if (DictByPNA.Count == 1)
                {
                    double perm = PercentageMatcher(DictByPNA[0].Street, street);
                    if (perm > PercentageMatcherPrecision)
                    {
                        RecognitionResulType R = new RecognitionResulType();
                        R.Input           = city + " " + street + " " + pna;
                        R.Method          = "MatchFrases_By_PNA";
                        R.ResultDict      = DictByPNA[0];
                        R.MatchPercentage = 100.00;

                        if (!Results.Contains(R))
                        {
                            Results.Add(R);
                        }
                    }
                    else
                    {
                        NoMatched.Add(city + "_" + street + "_" + pna + "_" + perm);
                    }
                }
            }


            return(DistResults(Results));
        }
Пример #2
0
        public List <RecognitionResulType> Match(string city, string street, string pna)
        {
            city   = WordRecognizerType.RemoveAllSpecialCharacters(city, true, true, true, false);
            street = WordRecognizerType.RemoveAllSpecialCharacters(street, true, true, true, false);
            pna    = pna.Replace("-", "").Replace(" ", "");

            city   = city.ToLower();
            street = street.ToLower();
            pna    = pna.ToLower();

            if (string.IsNullOrEmpty(city))
            {
                NoMatched.Add(city + "_" + street + "_" + pna);
                return(new List <RecognitionResulType>());
            }

            if (string.IsNullOrEmpty(pna))
            {
                new List <RecognitionResulType>();
            }

            street = street.Replace("ul.", "");
            street = street.ToLower().Replace("ul.", " ").Replace("Ul.", "");
            if (street.ToLower().StartsWith("ul "))
            {
                street = street.Substring(3, street.Length - 3);
            }


            street = street.Replace("pl.", "");
            street = street.ToLower().Replace("pl.", " ").Replace("Pl.", "");
            if (street.ToLower().StartsWith("pl "))
            {
                street = street.Substring(3, street.Length - 3);
            }

            List <RecognitionResulType> Results = new List <RecognitionResulType>();


            if (UseMatchAlias == true)
            {
                Results = MatchAlias(city + street);
            }


            if (Results.Count == 0)
            {
                if (UseMatchEquals == true)
                {
                    Results = MatchEquals(city, street, pna).ToList();
                }
            }

            if (Results.Count == 0)
            {
                if (UseMatchFrases == true)
                {
                    Results = MatchFrases(city, street, pna).ToList();
                }
            }

            if (Results.Count == 0)
            {
                if (UseContainsFrases == true)
                {
                    Results = ContainsFrases(city, street, pna).ToList();
                }
            }

            if (Results.Count == 0)
            {
                if (UseMatchFrasesPNA == true)
                {
                    Results = MatchFrasesPNA(city, street, pna).ToList();
                }
            }



            if (Results.Count > 1)
            {
                List <string> DistResults = new List <string>();

                var dist = (from o in Results
                            select o.ResultDict.City + o.ResultDict.Street).Distinct().ToList();

                var ndResults = Results;

                if (UseMatchFrasesPNA == true)
                {
                    Results = MatchFrasesPNA(city, street, pna).ToList();
                }

                if (Results.Count == 0)
                {
                    if (dist.Count > 1)
                    {
                        RecognitionResulType.ResulDecisionType nd = new RecognitionResulType.ResulDecisionType();
                        nd.input   = city + "_" + street + "_" + pna;
                        nd.Results = ndResults;
                        NeedDecision.Add(nd);
                    }


                    NoMatched.Add(city + "_" + street + "_" + pna);
                    return(new List <RecognitionResulType>());
                }
            }



            if (Results.Count == 0)
            {
                NoMatched.Add(city + "_" + street + "_" + pna);
            }

            return(DistResults(Results));
        }