2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Python][MeCab] Mac に oseti をインストールする

Last updated at Posted at 2019-10-18

oseti とは

Python で 感情分析 (Sentiment Analysis) を行うためのライブラリ。詳しくは次の記事を参照。

インストールするもの

  • MeCab : 日本語向けの形態素解析エンジン
  • mecab-ipadic : IPA 辞書 (形態素解析エンジン用の辞書)
  • mecab-ipadic-NEologd : 新語対応版の辞書
  • SWIG : C/C++ で書かれたプログラムやライブラリを別のプログラミング言語 (Java, Python, Ruby etc.) に接続するためのツール
    • oseti が依存している mecab-python3 のインストールに必要。
  • oseti : 感情分析用ライブラリ

前提

  • Homebrew をインストールしていること。
  • Python (3 系) をインストールしていること。
    • インストールしていない場合は pyenv などを使ってインストールする。

方法

$ brew install mecab
$ brew install mecab-ipadic

# リポジトリを git clone するための任意のディレクトリに移動する。
$ cd ~/workspace
# --depth 1 で最新のコミットのみを取得 (大容量のリポジトリを clone する場合に有効) 。
$ git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
$ cd mecab-ipadic-neologd
$ bin/install-mecab-ipadic-neologd -n -a
# 途中で "Do you want to install mecab-ipadic-NEologd?" と訊かれるので yes と打つ。

$ brew install swig

$ pip install oseti

使用例

import oseti

analyzer = oseti.Analyzer()
analyzer.analyze_detail('津々と悲しみだけが降り積もる 願望も悔恨もただ埋め尽くす')
# => [{'positive': ['願望'], 'negative': ['悲しみ'], 'score': 0.0}]
analyzer.analyze_detail('光を求め歩きつづける 君の情熱がいつの日か 誰かにとっての光となるでしょう 誰かにとっての兆しとなるでしょう')
# => [{'positive': ['光', '情熱', '光'], 'negative': [], 'score': 1.0}]

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?