コード例 #1
0
        private AccountsLookUp GetMatchByOccurrence(List <AccountsLookUp> lookups, string strToFind)
        {
            AccountsLookUp result = null;
            Dictionary <int, AccountsLookUp> occurences = new Dictionary <int, AccountsLookUp>();

            if (!string.IsNullOrEmpty(strToFind) && lookups != null && lookups.Count() > 0)
            {
                string tempStrToFind = StripInvalidCharacters(strToFind, " ");
                int    score;

                List <string> find = tempStrToFind.Split(' ').ToList();

                foreach (AccountsLookUp lookup in lookups)
                {
                    score = 0;
                    foreach (string str in find)
                    {
                        if (StripInvalidCharacters(lookup.Bank, " ").Contains(str))
                        {
                            score++;
                        }
                    }
                    if (score >= 5)
                    {
                        occurences.Add(score, lookup);
                    }
                }
                result = occurences.OrderByDescending(x => x.Key).First().Value;
            }

            return(result);
        }
コード例 #2
0
        public string GetFundShortName(string bankName)
        {
            string shortFundName = string.Empty;

            if (!string.IsNullOrEmpty(bankName))
            {
                string tempBankName = bankName;

                bankName = StripInvalidCharacters(bankName);
                AccountsLookUp lookup = accountLookUps.Where(x => StripInvalidCharacters(x.Bank.ToLower()).Contains(bankName.ToLower())).FirstOrDefault();
                // if returned empty, do a reverse lookup
                if (lookup == null)
                {
                    lookup = accountLookUps.Where(x => StripInvalidCharacters(x.Bank.ToLower()) != string.Empty &&
                                                  bankName.ToLower().Contains(StripInvalidCharacters(x.Bank.ToLower()))).FirstOrDefault();
                }
                if (lookup != null)
                {
                    shortFundName = lookup.ShortName;
                }
                // still no result? search by occurence
                else
                {
                    lookup = GetMatchByOccurrence(accountLookUps, tempBankName);
                    if (lookup != null)
                    {
                        shortFundName = lookup.ShortName;
                    }
                }
            }

            return(shortFundName);
        }