ahappysadface
ahappysadface

Reputation: 11

nltk in python code for emotion extraction

I would be very glad if you could help me to find a solution for linking my python code with nltk. my code is for creating an emotion extraction engine in background of a chat environment. i could separate the chatters and their conversations. Now i need to extract noun, verbs, adjectives etc. from their conversation.

How can i do that? Someone please help me ... I'm stuck.

Upvotes: 1

Views: 1763

Answers (2)

Elvis D'Souza
Elvis D'Souza

Reputation: 2313

What you are trying to achieve is called POS Tagging.

from nltk import pos_tag, word_tokenize

sentence = "No, Mr. Bond. I expect you to die!"
tagged_sentence = pos_tag(word_tokenize(sentence)) 

print tagged_sentence

The result is a list of (word,tag) tuples:

[('No', 'DT'), (',', ','), ('Mr.', 'NNP'), ('Bond.', 'NNP'), ('I', 'NNP'), ('expect', 'VBP'), ('you', 'PRP'), ('to', 'TO'), ('die', 'VB'), ('!', '.')]

More info here: nltk docs

Upvotes: 4

Lennart Regebro
Lennart Regebro

Reputation: 172249

Nltk is written in Python, and are Python packages you can download and install and then import in Python. There is no linking required.

Instructions for installing are here: http://www.nltk.org/download

And for using here: http://www.nltk.org/documentation

Upvotes: 2

Related Questions