Beispiel #1
0
        /// <summary>
        /// 合并词库中已有词汇
        /// </summary>
        public void MergeExistWords()
        {
            Dictionary <string, ulong> existNewwords = new Dictionary <string, ulong>();

            // 将词库中已有词库记录并在新词中删除
            foreach (KeyValuePair <string, ulong> word in NewWords)
            {
                if (JWordSegmentorService.IsExist(word.Key))
                {
                    existNewwords.Add(word.Key, JWordSegmentorService.GetFrequency(word.Key) + word.Value);
                }
            }
            foreach (KeyValuePair <string, ulong> word in existNewwords)
            {
                if (NewWords.ContainsKey(word.Key))
                {
                    NewWords.Remove(word.Key);
                }
            }
            // 将已存词存入已在词库属性中
            foreach (var word in existNewwords)
            {
                if (ExistWords.ContainsKey(word.Key))
                {
                    ExistWords[word.Key] += word.Value;
                }
                else
                {
                    ExistWords.Add(word.Key, word.Value);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 合并词库中已有词汇
 /// </summary>
 public void MergeExistWords()
 {
     foreach (KeyValuePair <string, ulong> word in NewWords)
     {
         if (OldWords.ContainsKey(word.Key))
         {
             ExistWords.Add(word.Key, OldWords[word.Key] + word.Value);
         }
     }
     foreach (KeyValuePair <string, ulong> word in ExistWords)
     {
         if (NewWords.ContainsKey(word.Key))
         {
             NewWords.Remove(word.Key);
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 判断关键词是否存在于新词和词库中
 /// </summary>
 /// <param name="word"></param>
 /// <returns></returns>
 public bool IsWordExist(string word)
 {
     return(NewWords.ContainsKey(word) || ExistWords.ContainsKey(word) || JWordSegmentorService.IsExist(word, ""));
 }