/// <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); } } }
/// <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); } } }