コード例 #1
0
        /// <summary>
        /// Анализ текста
        /// </summary>
        void Analis()
        {
            bool flag;

            Words.RemoveAll(DigialPredickat);                    // Удаление строк с числами



            foreach (string str in stop)
            {
                do
                {
                    flag = Words.Remove(str);
                }while(flag);
            }



            flag = false;


            // Составление словаря
            while (Words.Count != 0)
            {
                string str   = Words[0];
                double count = 0;
                ProbabilityDictionaryData fD = new ProbabilityDictionaryData();

                for (int i = 0; i < Words.Count; i++)
                {
                    if (Words[i] == str)
                    {
                        count++;
                    }
                }


                fD.Probability = (double)count / (double)n;
                fD.Word        = str;

                list.Add(fD);                 // Добавление элемента


                // Удаление данных
                do
                {
                    flag = Words.Remove(str);
                }while(flag);
            }
        }
コード例 #2
0
        public void LoadData(string path)
        {
            string[] data = File.ReadAllLines(path), wordAndProb;
            pds = new ProbabilityDictionaryData[data.Length];

            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ",";
            provider.NumberGroupSeparator   = ".";
            provider.NumberGroupSizes       = new int[] { 3 };



            for (int i = 0; i < data.Length; i++)
            {
                wordAndProb        = data[i].Split();
                pds[i]             = new ProbabilityDictionaryData();
                pds[i].Word        = wordAndProb[0];
                pds[i].Probability = Convert.ToDouble(wordAndProb[1], provider);
            }
        }