Python sentence timing

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!

+6
source share
2 answers

You can use Stanford Parser to get offer-based analysis. The root of the dependency syntax will be the "main" verb that defines the sentence (I'm not too sure what a particular linguistic term is). You can then use the POS tag for this verb to find its time and use it.

+1
source

You can strengthen your approach in various ways. You could think more about English grammar and add a few more rules based on what you observe; or you can push the statistical approach, extract some more (corresponding) functions and throw the whole batch in the classifier. NLTK gives you a lot of classifiers for the game, and they are well documented in the NLTK book.

You can have the best of both worlds: handwritten rules can be in the form of functions that are supplied to the classifier, which will decide when it can rely on them.

0
source

Source: https://habr.com/ru/post/986450/


All Articles