【发布时间】: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