private Dictionary <string, CompanyRecordScore> GetCompanyNameSoundsLike(string[] companyWords, CompanyRecord companyListRecord)
        {
            // Let's not consider in order.
            Dictionary <string, CompanyRecordScore> result = new Dictionary <string, CompanyRecordScore>();
            int matchCount = 0;
            int Score      = 0;

            List <TokenSound> tokenSoundList = SoundExHash.GetTokenSounds(companyWords.ToList());

            foreach (TokenSound tokenSound in tokenSoundList)
            {
                foreach (TokenSound companyListToken in companyListRecord.tokenSoundList)
                {
                    if (companyListToken.Sound.Contains(tokenSound.Sound))
                    {
                        matchCount++;
                    }
                }
            }

            int cleansedWordCount = companyListRecord.tokenSoundList.Count;
            int companyWordCount  = tokenSoundList.Count;

            float matchPercentage = GetMatchPercentage(matchCount, cleansedWordCount, companyWordCount);

            matchPercentage = (nameSearchPercentage.MatchSoundsLikePercentage * matchPercentage) / PercentageMultiplier;

            if (matchPercentage >= nameSearchPercentage.ExactMatchWithNormalizationOutOfOrderPercentage)
            {
                Score = (int)(matchPercentage + 0.5);
                result.Add(companyListRecord.CompanyName, new CompanyRecordScore(companyListRecord, Score, CompanyScoreType.MatchSoundsLike));
            }

            return(result);
        }
Exemple #2
0
        public static void InitializeCompanyRecords()
        {
            CompanyDictionary = new Dictionary <string, CompanyRecord>();
            List <string> ExceptionList = new List <string>();

            string queryString = @"select Id, CompanyName from NameSearch";

            using (SqlConnection connection = new SqlConnection(ConnectionManager.Current.ConnectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        CompanyRecord companyRecord = new CompanyRecord();

                        companyRecord.CompanyId   = reader.GetInt32(0);
                        companyRecord.CompanyName = reader.GetString(1);

                        if (companyRecord.CompanyName != "" && companyRecord.CompanyName != string.Empty && companyRecord.CompanyName != null)
                        {
                            if (!CompanyDictionary.ContainsKey(companyRecord.CompanyName))
                            {
                                companyRecord.CleansedCompanyName      = NormalizeName.GetCleansedCompanyName(companyRecord.CompanyName);
                                companyRecord.CleansedCompanyNameWords = companyRecord.CleansedCompanyName.Split(' ');

                                companyRecord.tokenSoundList = SoundExHash.GetTokenSounds(new List <string>(companyRecord.CleansedCompanyNameWords));

                                CompanyDictionary.Add(companyRecord.CompanyName, companyRecord);
                            }
                            else
                            {
                                ExceptionList.Add(companyRecord.CompanyName);
                            }
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    reader = null;
                }
                command.Dispose();
                command = null;
            }

            return;
        }
Exemple #3
0
        // Helper class to Add or Update CompanyRecords.
        public static bool InsertCompanyRecord(string companyName, CompanyRecord companyRecord)
        {
            bool result = false;

            if (companyName == null || companyName == string.Empty || companyName == "")
            {
                throw new ApplicationException("Invalid string for CompanyName {companyName}");
            }

            if (companyRecord == null)
            {
                throw new ApplicationException("Must assign CompanyRecord type value before use");
            }

            if (companyName.CompareTo(companyRecord.CompanyName) != 0)
            {
                companyRecord.CompanyName = companyName;
            }

            object lockit = new object();

            lock (lockit)
            {
                companyRecord.CleansedCompanyName      = NormalizeName.GetCleansedCompanyName(companyRecord.CompanyName);
                companyRecord.CleansedCompanyNameWords = companyRecord.CleansedCompanyName.Split(' ');
                List <TokenSound> tokenSoundList = SoundExHash.GetTokenSounds(new List <string>(companyRecord.CleansedCompanyNameWords));

                if (!CompanyDictionary.ContainsKey(companyName))
                {
                    CompanyDictionary.Add(companyName, companyRecord);
                }
                else
                {
                    CompanyDictionary[companyName] = companyRecord;
                }

                result = true;
            }

            return(result);
        }