Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect English verb tenses using NLTK

Tags:

python

nlp

nltk

I am looking for a way given an English text count verb phrases in it in past, present and future tenses. For now I am using NLTK, do a POS (Part-Of-Speech) tagging, and then count say 'VBD' to get past tenses. This is not accurate enough though, so I guess I need to go further and use chunking, then analyze VP-chunks for specific tense patterns. Is there anything existing that does that? Any further reading that might be helpful? The NLTK book is focused mostly on NP-chunks, and I can find quite few info on VP-chunks.

like image 605
Michael Pliskin Avatar asked Aug 08 '10 11:08

Michael Pliskin


People also ask

How do you find the tense of a sentence in Python?

You can then use the POS tag on this verb to find its tense, and use that. You think? For "My dog has eaten my homework" you'll get the main verb (VBZ has) i.e. "present tense (with 3rd person inflection)". But perfect tense is in the past.

How do you convert past tense to present tense?

The basic way to form the past tense in English is to take the present tense of the word and add the suffix -ed. For example, to turn the verb "walk" into the past tense, add -ed to form "walked." .


1 Answers

Thee exact answer depends on which chunker you intend to use, but list comprehensions will take you a long way. This gets you the number of verb phrases using a non-existent chunker.

len([phrase for phrase in nltk.Chunker(sentence) if phrase[1] == 'VP'])

You can take a more fine-grained approach to detect numbers of tenses.

like image 194
Tim McNamara Avatar answered Oct 20 '22 00:10

Tim McNamara