こんにちは。GMOアドマーケティングのS.Rです。
今回はJumanppと構文分析のツールKNPを連携する方法を皆さんへ紹介します。
KNPとは
構文解析については京都大学黒橋・ 褚・ 村脇 研究室の公式サイトで下記のように紹介されています。KNPは同じく京都大学橋・ 褚・ 村脇研究室で開発されている日本語の構文解析を行うシステムです。
形態素解析システムJUMANの解析結果(形態素列)を入力とし、文節および基本句間の係り受け関係,格関係,照応関係を出力することができます。 引用元 | 京都大学大学院情報学研究科知能情報学専攻黒橋・褚・村 脇研究室 (https://nlp.ist.i.kyoto-u.ac.jp/ )
ColabのInstanceを作る
今回はGoogleのMachine Learning Cloud Serviceというcolabを利用して説明します。Colabの公式サイトからColabのPython3のInstanceを作ります。Jumanppの環境を構築する
下記のcommandでJumanppをインストールします。
1 2 3 4 5 6 7 8 9 |
!sudo apt-get -q -y install nkf !sudo apt-get -y install zsh !sudo apt-get -y install libboost-all-dev !wget -O /tmp/jumanpp-1.02.tar.xz https://nlp.ist.i.kyoto-u.ac.jp/DLcounter/lime.cgi?down=https://lotus.kuee.kyoto-u.ac.jp/nl-resource/jumanpp/jumanpp-1.02.tar.xz !sudo tar xf /tmp/jumanpp-1.02.tar.xz -C /tmp/ !cd /tmp/jumanpp-1.02 !cd /tmp/jumanpp-1.02 && sudo ./configure --prefix=/usr/local !cd /tmp/jumanpp-1.02 && sudo make !cd /tmp/jumanpp-1.02 && sudo make install |
KNPをインストールする
1 2 3 4 |
!wget -O knp-4.20.tar.bz2 https://nlp.ist.i.kyoto-u.ac.jp/DLcounter/lime.cgi?down=https://nlp.ist.i.kyoto-u.ac.jp/nl-resource/knp/knp-4.20.tar.bz2&name=knp-4.20.tar.bz2 !tar jxvf knp-4.20.tar.bz2 !cd knp-4.20 && ./configure --prefix=/usr/local --with-juman-prefix=/usr/local && make && make install !pip install pyknp |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
checking if g++ static flag -static works... yes checking if g++ supports -c -o file.o... yes checking if g++ supports -c -o file.o... (cached) yes checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes checking dynamic linker characteristics... (cached) GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking for special C compiler options needed for large files... no checking for _FILE_OFFSET_BITS value needed for large files... no checking debug version... no checking juman.h usability... no checking juman.h presence... no checking for juman.h... no configure: error: juman.h: not found. |
Juman7.04をインストールする
1 2 3 4 5 |
!wget http://nlp.ist.i.kyoto-u.ac.jp/nl-resource/juman/juman-7.01.tar.bz2 !tar jxvf juman-7.01.tar.bz2 !cd juman-7.01 && ./configure --prefix=/usr/local && make && sudo make install !sudo echo "include /usr/local/lib" >> /etc/ld.so.conf !sudo ldconfig |
KNPを再インストールする
1 2 |
!tar jxvf knp-4.20.tar.bz2 !cd knp-4.20 && ./configure --prefix=/usr/local --with-juman-prefix=/usr/local && make && make install |
ユーザー辞書を追加する
Jumanpp1.04のユーザー辞書を追加する方法 で”形態素解析”をユーザー辞書へ追加します。KNPを試す
まとめ
今回はJumanpp 1.04/KNPの環境構築方法を紹介しました。Jumanpp1.04 とKNPを合わせて構文分析を処理できるようになりました。
もし今回のブログが皆さんの日本語のNLPの開発にお役に立てば幸いです。
明日は「Jumanpp1.04のユーザー辞書を追加する方法」に関しての記事を公開します。
引き続き、GMOアドマーケティング Advent Calendar 2021 をお楽しみください!
■エンジニア採用ページ ~福利厚生や各種制度のご案内はこちら~
https://note.gmo-ap.jp/n/n02cbeb6edb0d
■noteページ ~ブログや採用、イベント情報を公開中!~
https://note.gmo-ap.jp/