LoginSignup
29
33

More than 5 years have passed since last update.

【Mac】KH Coder導入手順

Last updated at Posted at 2016-06-01

はじめに

形態素解析を行うにあたって、KH Coderを使ってみたかったのですが、
Macでの導入情報が少ないようだったので手順を書いてみようと思いました。

実行環境

MacBook Pro
OS X Yosemite 10.10.5

今回KHCoderを導入する前に、必要なものをいろいろと導入していたため、参考にしたページやコマンドを記載します。
()の中は導入時点でのバージョンです。

homebrew(0.9.9)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

R(3.2.2)
http://bi.biopapyrus.net/mac/r-install.html

mecab(0.996)
http://qiita.com/tstomoki/items/f17c04bd18699a6465be

MYSQL(5.6.26)
http://qiita.com/hkusu/items/cda3e8461e7a46ecf25d

ここから、今回実施した手順になります。

環境構築

CPANM

perlモジュールのインストールにCPANMを使用します。
http://www.omakase.org/perl/cpanm.html

cd /usr/bin/
sudo curl -LOk http://xrl.us/cpanm
sudo chmod +x cpanm

ターミナルでperlモジュールをインストールします。
もし、足りないものがあったらKHcoder実行時にエラーで何が足りないのか表示されるので
都度追加していくことになります。

今回、私の環境で追加したものはこちらになります。ご参考までに。

sudo cpanm Jcode
sudo cpanm Tk
sudo cpanm DBD::CSV
sudo cpanm Spreadsheet::ParseExcel
sudo cpanm Spreadsheet::WriteExcel
sudo cpanm Unicode::String
sudo cpanm DBD::mysql
sudo cpanm Spreadsheet::XLSX
sudo cpanm Clipboard
sudo cpanm Statistics::Lite
sudo cpanm Algorithm::NaiveBayes
sudo cpanm Net::Telnet
sudo cpanm YAML

Rパッケージ

グラフを表示したりするために必要です。
Rコンソール内で以下を実行します。

こちらもKHcoder実行時に表示されたエラーを参考に追加していきました。

install.packages("RColorBrewer")
install.packages("wordcloud")
install.packages("amap")
install.packages("ggdendro")
install.packages("maptools")
install.packages("ade4")
install.packages("scatterplot3d")

共起ネットワークの表示のためにはigraphというRパッケージをインストールする必要がありますが、上記のように普通にインストールするとバージョンが合わずに動かなかったため、
https://cran.r-project.org/src/contrib/Archive/igraph/
から古いものをダウンロードします。
0.7.1で試してみました。

ダウンロードしたigraphパッケージを、他のパッケージと同じ場所に配置し、
install.packages("/配置先パス/igraph_0.7.1.tar.gz", repos = NULL)

※私の環境ではigraphインストール時にエラーが出ていたので
エラーを見ながら足りないライブラリを追加しました。

私の場合、以下のようにgfortranが"no"となっていたので

・・・
checking whether clang accepts -g... yes
checking for clang option to accept ISO C89... none needed
checking whether we are using the GNU Fortran compiler... no 
checking whether gfortran-4.8 accepts -g... no  
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ accepts -g... yes
checking how to run the C++ preprocessor... clang++ -E
・・・

以下を参考に追加しました。

gfortranの展開方法
http://stackoverflow.com/questions/23916219/os-x-package-installation-depends-on-gfortran-4-8?lq=1

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

KHcoderダウンロード

ここからソースコードをダウンロードして任意の場所に展開。(例としてApplications以下に配置)
http://khc.sourceforge.net/dl.html

展開した先(kh_coder)フォルダに移動

cd /Applications/kh_coder/

KH Coder起動

perl kh_coder.pl

KHCoderが立ち上がったら

  • プロジェクト→設定→MeCabを選択
  • 外部アプリケーションに open %s & を記述(Excelを利用します)  

設定が終わったら
プロジェクト→新規→分析対象ファイル にテキストデータを選択し実行。

後は抽出語の「対応分析」〜「自己組織化マップ」までを一通り実行してみて、
エラーメッセージを見て適宜、Rのパッケージをインストールしていく形になります。

おわりに

perlやらRやら、普段使わないので戸惑いましたが、KH Coderが立ち上がれば必要なものはエラーの内容でなんとなくわかったので、ひたすらググりながら導入してみました。

わかりにくい点も多々あるかと思いますが、何かのお役に立てれば幸いです。

参考

KH Coderチュートリアル
http://www.slideshare.net/khcoder/kh-coder-28776074

igraphがインストールできない(英語)
https://sourceforge.net/p/khc/discussion/222396/thread/477e23e1/

Rのパッケージ管理
http://www.task-notes.com/entry/20150822/1440212400

Perlモジュールインストール
https://uehatsu.info/tech/archives/2012/07/how-to-install-cpanm-command.html

mecab 辞書更新
https://github.com/neologd/mecab-ipadic-neologd/blob/master/README.ja.md

29
33
1

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
29
33