public static IEnumerable <string> GetSynonyms(string word, List <string> invalid_synonyms, Microsoft.Office.Interop.Word.Application wordApp) { word = word.ToLower(); var found = new List <string>(); var theSynonyms = wordApp.get_SynonymInfo(word); foreach (var Meaning in theSynonyms.MeaningList as Array) { if (found.Count >= 4) { return(found); } var synonym = Meaning.ToString(); if (!IsSynonymTooSimilar(word, synonym, found)) { if (!invalid_synonyms.Contains(synonym)) { found.Add(synonym); } else { Debug.WriteLine("Synonym " + synonym + " was blocked because it was on the invalid list."); } } } for (int ii = 0; ii < found.Count; ii++) { theSynonyms = wordApp.SynonymInfo[found[ii]]; foreach (string synonym in theSynonyms.MeaningList as Array) { if (found.Count >= 4) { return(found); } if (IsSynonymTooSimilar(word, synonym, found)) { continue; } found.Add(synonym); } } return(found); }
//Get Synonyms word by Microsoft.Word Application public IEnumerable <string> GetSynonyms(string term) { var appWord = new Microsoft.Office.Interop.Word.Application(); object objLanguage = Microsoft.Office.Interop.Word.WdLanguageID.wdEnglishUS; Microsoft.Office.Interop.Word.SynonymInfo si = appWord.get_SynonymInfo(term, ref (objLanguage)); foreach (var meaning in (si.MeaningList as Array)) { yield return(meaning.ToString()); } appWord.Quit(); //include this to ensure the related process (winword.exe) is correctly closed. System.Runtime.InteropServices.Marshal.ReleaseComObject(appWord); objLanguage = null; appWord = null; }