从文本中提取正负词?

问题描述 投票:1回答:1

我需要找到网站上某些评论的观点。我为此使用了sendiwordnet。我首先将包含所有评论的文件发送到POS Tagger。

是否还有其他准确的分词方式,认为不是1个单词,而是认为它是2个单独的单词。

现在,我必须给带标记的单词加上正负分数,然后计算总分数。在sendiwordnet中是否有此功能。请帮助。

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'
python python-2.7 nltk pos-tagger senti-wordnet
1个回答
0
投票

由于缺少nltk软件包而发生了错误,可以通过下载软件包来解决该错误,请执行以下代码来解决此问题

import nltk 
nltk.download()
© www.soinside.com 2019 - 2024. All rights reserved.