【问题标题】:Sentiment Analysis using senti_classifier and NLTK使用 senti_classifier 和 NLTK 进行情绪分析
【发布时间】:2017-01-22 19:56:01
【问题描述】:

我没有做正确的事情——从我得到的错误的外观来看,我认为我丢失了一些数据。我为sentiment_classifier (https://pypi.python.org/pypi/sentiment_classifier/0.7) 安装了所有先决条件,它们是nltk、numpy 和sentiwordnet。这是我的代码 - 我正在尝试开始工作的文档中的一个快速示例。

from senti_classifier import senti_classifier
sentences = ['The movie was the worst movie', 'It was the worst acting by the actors']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score

这是我收到的错误消息

Traceback (most recent call last):
  File "/home/beef/sciencefair2017/sentiment.py", line 1, in <module>
from senti_classifier import senti_classifier
  File "build/bdist.linux-x86_64/egg/senti_classifier/senti_classifier.py", line 227, in <module>
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1178, in resource_stream
self, resource_name
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1454, in get_resource_stream
return io.BytesIO(self.get_resource_string(manager, resource_name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1457, in get_resource_string
return self._get(self._fn(self.module_path, resource_name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1535, in _get
return self.loader.get_data(path)
IOError: [Errno 0] Error: 'senti_classifier/data/SentiWn.p'

有什么问题,我怎样才能让它工作?任何建议,即使只是一个建议而不是一个实际的解决方案,我们都非常感谢。我已经尝试了所有软件包的各种版本,但我查看了一些文档无济于事。

【问题讨论】:

  • 我认为这可能不是问题,但您能否尝试删除by the actors 到by the actors 中的多余空格(“by”和“the”之间的一个空格)?跨度>
  • @fedepad 刚刚编辑了它——很惊讶我自己没有注意到它!这些东西通常真的让我很烦。
  • 如果可行,我会写一个答案......但我不确定这是问题所在。我正在查看库中的代码以查看它。告诉我。
  • 好的,我认为这不是代码的问题。加载数据文件夹时似乎有问题,特别是 senti_classifier/data/SentiWn.p.
  • 那个文件在某个地方吗?

标签: python nltk sentiment-analysis wordnet


【解决方案1】:

我想通了:我没有安装完整的包 - 我最初使用 pip 但我必须像这样安装它:

git clone https://github.com/kevincobain2000/sentiment_classifier
cd sentiment_classifier
python setup.py install

现在效果很好。

【讨论】:

  • 您好 - 我遇到了类似的问题。我已经在 powershell 中运行了 python setup.py install,我有 NLTK、NumPy。我已经下载了 'sentiment_classifier-0.5.tar.gz',解压缩并粘贴到我的目录中的文件夹,我收到以下错误: FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\AC\ \Anaconda3\\lib\\site-packages\\senti_classifier\\data\\SentiWn.p'。关于我做错了什么的任何想法?我知道它没有找到文件,但我可以在我的目录中看到它。数据文件为空白。假设这可能与它有关,但我无法确认
【解决方案2】:

在:

import inspect
all_functions = inspect.getmembers(senti_classifier, inspect.isfunction)
all_functions

输出:

[]

senti_classifier 模块中没有函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 2015-06-30
    相关资源
    最近更新 更多