Following a few other posts, [ Determine verb tense in English using NLTK , Verb tense identification in python , Python NLTK is typing time . I wrote the following code to determine the time of a sentence in Python using POS tags:
from nltk import word_tokenize, pos_tag def determine_tense_input(sentance): text = word_tokenize(sentance) tagged = pos_tag(text) tense = {} tense["future"] = len([word for word in tagged if word[1] == "MD"]) tense["present"] = len([word for word in tagged if word[1] in ["VBP", "VBZ","VBG"]]) tense["past"] = len([word for word in tagged if word[1] in ["VBD", "VBN"]]) return(tense)
This returns a value for using past / present / future verbs, which I usually take for the maximum value as response time. The accuracy is moderately decent, but I wonder if there is a better way to do this.
For example, is there a randomly written package that is more about retrieving sending time? [note - 2 of 3 collisions with stack overflow - 4 years, so now everything can change]. Or, alternatively, should I use a different parser from nltk to increase accuracy? If not, hope the above code can help someone else!
source share