How to convert between verb/noun/adjective/adverb forms using Wordnet

You might have stumbled in your NLP application development upon situations when you needed to get the “closest” adjective to a noun, or maybe you needed to “nounify” a verb. After poking around Wordnet I found a simple and pretty effective way to do this. Keep in mind that it is not error proof, but for most of my needs, I found it to perform pretty well. We’ll be using NLTK Wordnet wrapper for this. Let’s have a look at the code:

This is pretty much it. Because most of the time, there is not just one correct answer to the question, I’ve decided to return a list with possible answers with attached probabilities. The probabilities are computed in a simple manner: no_times_lemma_appears/no_possible_answers. Let’s take a look at some results: