0

I am trying to find tense of sentence. But till now I can only find nltk pos tagging which can be used to determine the tense. I am using following code:

from nltk import word_tokenize, pos_tag

def determine_tense_input(sentence):
    text = word_tokenize(sentence)
    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)

Is there a better way to do this?

Stef
  • 13,242
  • 2
  • 17
  • 28
  • 1
    That's already pretty good, but then you should probably aggregate this dictionary into a prediction for the tense of the sentence. – Stef Jan 21 '23 at 09:47
  • 1
    Note that a past participle is usually not an indicator of past, unless it's coupled with "have" or "has". – Stef Jan 21 '23 at 09:47
  • 1
    Also for verbs in the present participle, if it's "going" and it's followed by "to", then it's an indicator of the future. – Stef Jan 21 '23 at 09:50
  • 2
    This should help: [Determining tense of a sentence Python?](https://stackoverflow.com/questions/30016904/determining-tense-of-a-sentence-python) – Stef Jan 21 '23 at 09:52

0 Answers0