/// <summary> /// 获取同义词,相关词 /// </summary> /// <param name="keyWord"></param> /// <param name="language"></param> /// <returns></returns> public static List <string> GetKeyWordsWithSynonyms(string keyWord, string language = "EN") { List <string> wordList = new List <string>(); string[] keywords = SplitWordTool.SplitWord(keyWord); foreach (string word in keywords) { string item = SplitWordTool.SnowballWord(word, language); wordList.AddRange(SynonymDict.GetSynonymsWord(language, item)); } return(wordList); }
/// <summary> /// 添加同义词 /// </summary> /// <returns>False表示没有同义词,True表示有同义词</returns> private bool AddSynonymsWordToQueue() { List <string> synonymsWordList = new List <string>(); if (this._synonymsDictList != null) { //如果有外部传过来的近义词,就取外部的近义词列表 foreach (Dictionary <string, string[]> dict in _synonymsDictList) { foreach (KeyValuePair <string, string[]> pair in dict) { if (pair.Key.ToLower().Contains(this._TermAttribute.Term)) { synonymsWordList.AddRange(pair.Value); } } if (!synonymsWordList.Contains(this._TermAttribute.Term)) { synonymsWordList.Add(this._TermAttribute.Term); } } } else { //如果没有外部传过来的近义词,就取Synonym.txt的近义词列表 synonymsWordList = SynonymDict.GetSynonymsWord(this._Language, this._TermAttribute.Term); } if (synonymsWordList == null || synonymsWordList.Count <= 0) { return(false); } foreach (string synonymsWord in synonymsWordList) { if (!this._TermAttribute.Term.ToLower().Equals(synonymsWord)) {//取出同义词,不包含已经被添加到索引里面的词 this._SynonymsQueue.Enqueue(synonymsWord); } } return(true); }