1
0

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 1 year has passed since last update.

Google Colaboratory MeCab インストール & 辞書指定

Posted at

インストール

mecab と mecab-python のインストール

!apt install aptitude
!aptitude install mecab libmecab-dev mecab-ipadic-utf8 git make curl xz-utils file -y

!pip install mecab-python3
!cat /etc/mecabrc

設定状況を確認

;
; Configuration file of MeCab
;
; $Id: mecabrc.in,v 1.3 2006/05/29 15:36:08 taku-ku Exp $;
;
dicdir = /var/lib/mecab/dic/debian

; userdic = /home/foo/bar/user.dic

; output-format-type = wakati
; input-buffer-size = 8192

; node-format = %m\n
; bos-format = %S\n
; eos-format = EOS\n

dicdir確認

mecab-python で確認

import MeCab

tagger = MeCab.Tagger()
text = "日本のSNS、混乱に備えを マスク氏のTwitterはどこへ"
print(tagger.parse(text))

オプションなしで利用できることを確認

辞書指定

デフォルトとは別の辞書を使いたい場合は別途インストール

!pip install unidic
!python -m unidic download


Successfully installed plac-1.3.5 unidic-1.1.0
download url: https://cotonoha-dic.s3-ap-northeast-1.amazonaws.com/unidic-3.1.0.zip
Dictionary version: 3.1.0+2021-08-31
Downloading UniDic v3.1.0+2021-08-31...
unidic-3.1.0.zip: 100% 526M/526M [00:31<00:00, 16.7MB/s]
Finished download.
Downloaded UniDic v3.1.0+2021-08-31 to /usr/local/lib/python3.8/dist-packages/unidic/dicdir

最後にインストールした辞書のパスが表示されるので確認する。
辞書のパスを指定して利用する 。
/etc/mecabrcを書き換えてもいいがちょっと面倒なので。。。

import MeCab

tagger = MeCab.Tagger('-d /usr/local/lib/python3.8/dist-packages/unidic/dicdir')
text = "日本のSNS、混乱に備えを マスク氏のTwitterはどこへ"
print(tagger.parse(text))

辞書のアップデート

辞書をアップデートしたい場合は辞書のコンパイルから行う方が良さそう。
アーカイブを左メニューのファイル部分にアップロードしてこんなコマンド実行。

!tar xvzf mecab-ipadic-2.7.0-20070801.tar.gz
!cd mecab-ipadic-2.7.0-20070801 && configure –with-charset=utf8 –prefix=/usr
!make
!make install

アップデートするCSVを展開したディレクトリに配置して以下のコマンドで辞書をアップデート。

!make clean all
!make install
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?