【问题标题】:how to override downloader directory with local directory in polyglot in python如何在python的polyglot中用本地目录覆盖下载器目录
【发布时间】:2020-11-08 21:35:07
【问题描述】:

我运行多语言情感检测。当我将它上传到服务器时,我无法运行downloader.download("TASK:sentiment2") 命令,所以我下载了sentiment2 文件夹并将其保存在与python 文件相同的文件夹中。

我尝试将downloader.download_dir = os.path.join(os.getcwd(),'polyglot_data') 设置为指向sentiment2 文件夹位置,正如polyglot documentation 中所说的那样,但它不起作用。

如何覆盖下载器目录,以便它在执行情绪分析时访问情绪 2 本地文件夹?

请查看下面的完整代码。此代码在我的计算机和 localhost 上运行,但在服务器上运行时返回零。

from polyglot.downloader import downloader
#downloader.download("TASK:sentiment2")
from polyglot.text import Text

downloader.download_dir = os.path.join(os.getcwd(),'polyglot_data')

def get_text_sentiment(text):
   result = 0
   ttext = Text(text)
   for w in ttext.words:
      try:
         result += w.polarity
      except ValueError:
         pass
   if result: 
      return result/ len(ttext.words)
   else:
      return 0

text = "he is feeling proud with ❤"
print(get_text_sentiment(text))

我的本​​地主机返回 - 0.1666

服务器返回 - 0.0

【问题讨论】:

    标签: python server nlp polyglot


    【解决方案1】:

    在查看了多语言 git init 函数之后。它是一个环境。问题。 data_path = os.environ.get('POLYGLOT_DATA_PATH', data_path)

    所以我删除了downloader.download_dir = os.path.join(os.getcwd(),'polyglot_data') 并简单地在环境中定义本地 POLYGLOT_DATA_PATH。小路。 它奏效了。

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 2023-03-27
      • 2015-01-23
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 2020-05-30
      相关资源
      最近更新 更多