我需要找到网站上给出的某些评论的意见。我正在使用sentiwordnet。我首先将包含所有评论的文件发送到POS Tagger。
除了将其视为2个单独的单词之外,还有其他任何准确的标记方式,除了将其视为1个单词之外。
现在我必须对标记化的单词给出正面和负面分数,然后计算总分。 sentiwordnet中是否有任何功能。请帮忙。
import nltk
from not.tokenize import sent_tokenize, word_tokenize
import CSV
para = "What can I say about this place. The staff of the restaurant is nice and the eggplant is not bad. Apart from that, very uninspired food, lack of atmosphere and too expensive. I am a staunch vegetarian and was sorely disappointed with the veggie options on the menu. Will be the last time I visit, I recommend others to avoid"
sentense = word_tokenize(para)
word_features = []
for i,j in nltk.pos_tag(sentense):
if j in ['JJ', 'JJR', 'JJS', 'RB', 'RBR', 'RBS']:
word_features.append(i)
rating = 0
for i in word_features:
with open('words.txt', 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
if i == row[0]:
print i, row[1]
if row[1] == 'pos':
rating = rating + 1
elif row[1] == 'neg':
rating = rating - 1
print rating
错误:
Traceback (most recent call last):
File "E:/Emotional from text/pORnOfWord.py", line 10, in <module>
for i,j in nltk.pos_tag(sentense):
File "C:\Python27\lib\site-packages\nltk\tag\__init__.py", line 99, in pos_tag
tagger = load(_POS_TAGGER)
File "C:\Python27\lib\site-packages\nltk\data.py", line 605, in load
resource_val = pickle.load(_open(resource_url))
File "C:\Python27\lib\site-packages\nltk\data.py", line 686, in _open
return find(path).open()
File "C:\Python27\lib\site-packages\nltk\data.py", line 467, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found. Please use the NLTK Downloader to obtain the resource:
>>> nltk.download()
Searched in:
- `enter code here`'C:\\Users\\Eman\x99/nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Python27\\nltk_data'
- 'C:\\Python27\\lib\\nltk_data'
- 'C:\\Users\\Eman\x99\\AppData\\Roaming\\nltk_data'
答案 0 :(得分:0)
由于缺少nltk软件包而发生了错误,可以通过下载软件包来解决该错误,请执行以下代码以解决该问题
import nltk
nltk.download()