To find synonym of a word, I have below code. There is a one problem with below source code; since word coming from user, I donot know its POS type. Therefore, how can I find IIndexWord of a word in case of I dont know its POS type?
IIndexWord idxWord = dict . getIndexWord ("dog", POS. NOUN );
IWordID wordID = idxWord . getWordIDs ().get (0) ; // 1st meaning
IWord word = dict . getWord ( wordID );
ISynset synset = word . getSynset ();
for( IWord w : synset . getWords ())
System .out . println (w. getLemma ());
signature of my method looks like;
void synonym(Strng word)
I am going to use word in type of String in place of "dog" word but, at runtime, I dont know its POS type.
I have second problem, before getting its synonym of a word, I want to check whether it is English word or not but JWI does not have a method like isEnglish() or isInDictionary(). How can I check a word whether it is english or not so that I would avoid to look for synonym of non-english word? ( eventually, improve performance)
Let's think about this. If the user wants to know the synonyms for a word like 'bark', that can be both a noun or a verb, you actually need to show him all the results. So, it will be correct to search the IIndexWord with all POS-es.
If you cannot find a specific word after trying all POS-es, then you can tell the user that it does not exist.