多言語センチメント検出を実行します。サーバーにアップロードするとdownloader.download("TASK:sentiment2")
コマンドが実行できないので、sentiment2 フォルダーをダウンロードして、python ファイルと同じフォルダーに保存しました。
ポリグロットdownloader.download_dir = os.path.join(os.getcwd(),'polyglot_data')
のドキュメントに記載されているように、sentiment2 フォルダーの場所を指すように設定しようとしましたが、機能しません。
センチメント分析の実行時にセンチメント 2 ローカル フォルダーにアクセスできるように、ダウンローダー ディレクトリをオーバーライドするにはどうすればよいですか?
以下の完全なコードを参照してください。このコードは私のコンピューターとローカルホストで機能しますが、サーバーで実行するとゼロが返されます。
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 を返します