0

I am using textblob nltk to do some action for a given sentence.I am very new to nltk and text processing.I am able to decide the action for the given sentence but I have no idea how to extract the subject

Here is the code

from textblob.classifiers import NaiveBayesClassifier


trainingSet = [
('Get me juice','get'),
('Get me orange', 'get'),
('I want juice', 'get'),
('I dont want orange', 'take'),
('I dont like apple', 'take'),
('I detest watermelon', 'take')
]

cl = NaiveBayesClassifier(trainingSet)

print(cl.classify('I hate pumpkin'))

This gives me the label 'take' but how do I train it to extract the subject too? That is I want the result to be 'take', 'pumpkin'

MaPY
  • 321
  • 2
  • 13
  • For extracting the subject, consider [parsing](http://www.nltk.org/api/nltk.parse.html#module-nltk.parse.api) (there might be a shortcut in textblob, I don't know). – lenz Jan 15 '17 at 23:21
  • Note that the subject might not always be what you want: eg. in "Watermelons disgust me", the subject is "watermelons", while in "I hate watermelons", it is "I". You might want to look into semantic roles, where you should get the same role for "me"/"I" in both sentences. – lenz Jan 15 '17 at 23:25

0 Answers0