Get synonym list of given word or phrase using C#.Net


This code snippet returns list of all synonyms for the given word or phrase. I use word DLL to get these synonyms.

Some time we asked for synonyms for a particular word then we use dictionary but if you need to integrate with application then it is cumbersome. this method gets string and return list of synonyms, if it found synonyms else list length would be zero. This method opens a word application and gets all synonyms for that word. It is very similar to open a word document write that word and get synonyms list after right click. For example if you pass string (Word) “Document” then this method return all synonyms list “text, file, article, essay, paper, etc.


private List<string> GetSynonyms(string SearchText)
{
private ApplicationClass wordApp = new ApplicationClass();
List<string> searchList = new List<string>();
WriteLogger("Inside GetSynonyms");
try
{
object languageID = Word.WdLanguageID.wdEnglishAUS;
//Get all Synonyms of given word
SynonymInfo synInfo = WordApp.get_SynonymInfo(SearchText, ref languageID);
Array objSynInfo = synInfo.MeaningList as Array;
//Add all synonyms to search list
WriteLogger(objSynInfo.Length + " Synonyms Found");
for (int synCount = 1; synCount <= objSynInfo.Length; synCount++)
{
SearchList.Add(objSynInfo.GetValue(synCount).ToString());
}
}
catch
{
WriteLogger("Error while getting synonyms");
}
return SearchList;
}


Comments

Guest Author: ali12 Apr 2012

can you tell me which namespace and assembly I have to add to use this code....

Guest Author: joevedam02 Jun 2012

i dont no bos tell me pls this my id joevedam@gmail.com

Author: Ahmed Danial25 Jan 2017 Member Level: Bronze   Points : 0

Need namespaces, DLL and all reference material for code. Where can I get it?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: