5
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 3 years have passed since last update.

ColabのRのノートブックにNEologd辞書をインストール

Last updated at Posted at 2021-08-05

Ⅰ.はじめに

 Google Colaboratory(略称: Colab)で、 R のノートブックを作り、MeCab から RMeCab、NEologd 辞書までインストールした手順のメモです。

Ⅱ.Colab で R を使うとき

 次のリンクからノートブックを新規作成する。
  https://colab.research.google.com/notebook#create=true&language=r

Ⅲ.R のコード

1.日本語フォントのインストール

 ggplot2 のグラフなどで、日本語を使いたいとき日本語フォントのインストールが必要になる。
 今回は、日本語 IPA フォントをインストールした。

system("apt-get install -y fonts-ipafont")

2.MeCab をインストール

  • MeCab 本体や辞書等のシステムライブラリをインストール
system('apt-get install -y mecab libmecab-dev mecab-ipadic-utf8')

3.RMeCab をインストール

  • RMeCab をインストール
install.packages("RMeCab", repos = "https://​rmecab.jp/R")
  • RMeCab の動作確認
library(RMeCab)
RMeCabC("すもももももももものうち")
  • 次のように出力されれば、RMeCab が使えている。

名詞: 'すもも'
助詞: 'も'
名詞: 'もも'
助詞: 'も'
名詞: 'もも'
助詞: 'の'
名詞: 'うち'

4.NEologd 辞書のインストール

  • NEologd 辞書をインストール
system('apt install git make curl xz-utils file')
system('git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git')
system('/content/mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n -a -y')

 3行目をsystem('echo yes | /content/mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n -a')からsystem('/content/mecab-ipadic-neologd/bin/install-mecab-ipadic-neologd -n -a -y')に変更(2021.08.07)

  • 辞書を mecab-ipadic-NEologd に変更する(/etc/mecabrc の書換)
system('sed -i -e "s!/var/lib/mecab/dic/debian!/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd!g" /etc/mecabrc')
  • 辞書を NEologd 辞書に変更できたか動作確認
library(RMeCab)
RMeCabC("鬼滅の刃")
  • 次のように出力されれば、NEologd 辞書が使えている。

名詞: '鬼滅の刃'

  • 辞書を標準のシステム辞書 IPADIC に戻すとき、
system('sed -i -e "s!/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd!/var/lib/mecab/dic/debian!g" /etc/mecabrc')

Ⅳ.参考URL

5
0
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
5
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?