Software Enthusiastic
Software Enthusiastic

Reputation: 26475

Using NLTK and WordNet; how do I convert simple tense verb into its present, past or past participle form?

Using NLTK and WordNet, how do I convert simple tense verb into its present, past or past participle form?

For example:

I want to write a function which would give me verb in expected form as follows.

v = 'go'
present = present_tense(v)
print present # prints "going"

past = past_tense(v)
print past # prints "went"

Upvotes: 50

Views: 39603

Answers (4)

Anatoly Alekseev
Anatoly Alekseev

Reputation: 2420

For Python3:

pip install pattern

then

from pattern.en import conjugate, lemma, lexeme, PRESENT, SG
print (lemma('gave'))
print (lexeme('gave'))
print (conjugate(verb='give',tense=PRESENT,number=SG)) # he / she / it

yields

give 
['give', 'gives', 'giving', 'gave', 'given'] 
gives

thnks to @Agargara for pointing & authors of Pattern for their beautiful work, go support them ;-)

PS. To use most of pattern's functionality in python 3.7+, you might want to use the trick described here

Upvotes: 22

Gunjan
Gunjan

Reputation: 2805

With the help of NLTK this can also be done. It can give the base form of the verb. But not the exact tense, but it still can be useful. Try the following code.

from nltk.stem.wordnet import WordNetLemmatizer
words = ['gave','went','going','dating']
for word in words:
    print word+"-->"+WordNetLemmatizer().lemmatize(word,'v')

The output is:

gave-->give
went-->go
going-->go
dating-->date

Have a look at Stack Overflow question NLTK WordNet Lemmatizer: Shouldn't it lemmatize all inflections of a word?.

Upvotes: 27

Hoda
Hoda

Reputation: 27

JWI (the WordNet library by MIT) also has a stemmer (WordNetStemmer) which converts different morphological forms of a word like ("written", "writes", "wrote") to their base form. It seems it works only for nouns (like plurals) and verbs though.

Word Stemming in Java with WordNet and JWNL also shows how to do this kind of stemming using JWNL, another Java-based Wordnet library:

Upvotes: 0

msbmsb
msbmsb

Reputation: 1416

I think what you're looking for is the NodeBox::Linguistics library. It does exactly that:

print en.verb.present("gave")
>>> give

Upvotes: 23

Related Questions