简体   繁体   English

python代码中的nltk用于情感提取

[英]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 . 如果您能帮助我找到将python代码与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. 有人请帮助我...我被卡住了。

What you are trying to achieve is called POS Tagging . 您试图实现的目标称为POS标记

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 更多信息在这里: nltk docs

Nltk is written in Python, and are Python packages you can download and install and then import in Python. Nltk是用Python编写的,是可以下载并安装然后再用Python导入的Python软件包。 There is no linking required. 无需链接。

Instructions for installing are here: http://www.nltk.org/download 安装说明在这里: http : //www.nltk.org/download

And for using here: http://www.nltk.org/documentation 并在此处使用: http : //www.nltk.org/documentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM