コード例 #1
0
        /// <summary>
        /// Добавляет слово или словосочитанием, который станет одним атрибутом
        /// </summary>
        /// <param name="text">Текст</param>
        /// <param name="leightOfCollation">Длина словосочитание (1 - слово)</param>
        /// <param name="classType">Класс текста</param>
        public void AddWord(Text text, int leightOfCollation, ClassTypeValue classType)
        {
            //todo : оптимизировать поиск. Возможно удалять слова, которые повторяются
            // хотя можно и забить. так оно выглядит только круче


            int    indexList = leightOfCollation;
            string word      = text.text;

            if (word != "я" && word.Length == 1)
            {
                return;
            }

            int index = _attributeslList[indexList].FindIndex(x => x.word == word);

            if (index < 0)
            {
                Attribute attr = new Attribute(word, classType);
                attr.SetNumberText(text.numberOfText);
                _attributeslList[indexList].Add(attr);

                //    Console.WriteLine( "добавлено " + word );
            }
            else
            {
                _attributeslList[indexList][index].incrementCnt(classType);
                _attributeslList[indexList][index].SetNumberText(text.numberOfText);
            }
            return;;
        }
コード例 #2
0
        /// <summary>Создает атрибут с пустым весом </summary>
        /// <param name = "Word">Текст слова</param>
        /// <param name = "Weight">Вес слова в класе <para>Value</para> </param>
        /// <param name="value">Класс атрибута(текста)</param>
        public Attribute(string Word, ClassTypeValue value)
        {
            Init();

            this.word          = Word;
            count[(int)value]  = 1;
            weight[(int)value] = float.NaN;
        }
コード例 #3
0
        /// <summary>Создает атрибут </summary>
        /// <param name = "Word">Текст слова</param>
        /// <param name = "Weight">Вес слова в класе <para>Value</para> </param>
        /// <param name="value">Класс атрибута(текста)</param>
        public Attribute(string Word, float Weight, ClassTypeValue value)
        {
            Init();

            this.word = Word;
            this.weight[(int)value] = Weight;
            count[(int)value]       = 1;


            needCalcWeight = false;
        }
コード例 #4
0
 /// <summary>Увеличивает счетчик </summary>
 /// <param name="value">Класс атрибута(текста)</param>
 public void incrementCnt(ClassTypeValue value)
 {
     count[(int)value]++;
 }
コード例 #5
0
 public static string ToString(ClassTypeValue type)
 {
     return(ClassTypeStringList[(int)type]);
 }
コード例 #6
0
        /// <summary>
        /// Добавляет текст в список признаков
        /// </summary>
        /// <param name="text">текст</param>
        /// <param name="classType">Класс текста</param>
        /// <returns></returns>
        public bool AddText(string text, ClassTypeValue classType)
        {
            Console.WriteLine("Start add words to the dictionary");


            List <Text> wordList = new List <Text>();

            if (!ParserText.Parse(text, ref wordList))
            {
                Console.WriteLine(this.ToString() + "Error AddText : Empty input File");
            }


            int cntNewText = wordList.Last().numberOfText; // сумарное количество текстов

            ParserText.numberOfText = cntNewText;

            while (cntNewText - _TextType.Count > 0)
            {
                _TextType.Add(classType);
            }


            // добавляем все слова в список
            Console.WriteLine("add words [1]");
            for (int i = 0; i < wordList.Count; i++)
            {
                if ((i + 1) % 10000 == 0)
                {
                    Console.WriteLine("{0}\\{1}", (i + 1), wordList.Count);
                }

                AddWord(wordList[i], 0, classType);
            }

            Console.WriteLine("{0}\\{1}", wordList.Count, wordList.Count);


            //составляем все словосочитания определенной размерности и заносим их в список

            bool   exit = false;
            string word = "";

            for (int i = 1; i < MAX_LEIGHT_OF_WORDS_IN_COLLOCATION; i++)
            {
                Console.WriteLine("add words [{0}]", (i + 1));

                for (int j = 0; j < wordList.Count; j++)
                {
                    if ((j + 1) % 10000 == 0)
                    {
                        Console.WriteLine("{0}\\{1}", (j + 1), wordList.Count);
                    }

                    int tmpNum = wordList[j].numberOfText;

                    for (int k = 0; k <= i; k++)
                    {
                        if (j + k >= wordList.Count)
                        {
                            exit = true;
                            break;
                        }

                        if (wordList[j + k].numberOfText == tmpNum)
                        {
                            word += wordList[j + k].text;
                        }
                    }

                    AddWord(new Text(word, tmpNum), i, classType);
                    word = "";
                }
                Console.WriteLine("{0}\\{1}", wordList.Count, wordList.Count);
            }

            Console.WriteLine("Finish add words to the dictionary");
            return(true);
        }