Пример #1
0
        /// <summary>
        /// Trains this Category from a word or phrase<\summary>
        /// <seealso cref="DePhrase(string)">
        /// See DePhrase </seealso>
        public void TeachPhrase(string rawPhrase)                           //所谓训练数据,不过是统计某个单词有多少个而已
        {
            if ((null != m_Excluded) && (m_Excluded.IsExcluded(rawPhrase))) //IsExcluded用来检查rawPhrase是否是规定的那些无关的词,如果是无关的词,直接返回,不必处理
            {
                return;
            }

            PhraseCount pc;
            string      Phrase = DePhrase(rawPhrase);
            int         n;

            if (!m_Phrases.TryGetValue(Phrase, out n))            //m_Phrase是个SortedDictionary 这里是没有时的情况
            {
                m_Phrases.Add(Phrase, 1);
            }
            else
            {
                m_Phrases[Phrase] = n + 1;//重新赋值
            }

            m_TotalWords++;
        }