LoginSignup
0
0

More than 3 years have passed since last update.

Exception: Error: ;; Invalid morpheme ID: kata(25) kei(37)

Last updated at Posted at 2020-06-23

環境

  • OS : ubuntu16.04
  • knp : 5.00
  • jumanpp : 2.0.0-rc3
  • juman : 7.01

概要

from pyknp import KNP
knp = KNP()
knp.parse("学校でしてね") 

こんな感じで普通にKNPを使っていたところ

Exception: Error: ;; Invalid morpheme ID: kata(25) kei(37)

こんなエラーが文字によって出たり出なかったりしていました
(『てして』は起こる例です)

本家のgithubに解決策が提示されているので、それを参考に個人的なベストソリューションを防備録代わりにメモします
https://github.com/ku-nlp/pyknp/issues/16
https://github.com/ku-nlp/jumanpp/issues/108

解決策

# 一回消す
$ which knp
-> /usr/local/bin/knp
$ sudo rm -r /usr/local/bin/knp
$ sudo rm -r /usr/local/bin/juman
$ sudo rm -r /usr/local/bin/jumanpp

jumanの辞書をKNPに内包されている辞書で更新します
jumanの辞書と、KNPの中にあるjumanの辞書、が一致していないからこのエラーが出るらしいですね
KNPは最新のものがほしいのでこちらから
https://github.com/ku-nlp/knp

# juman 7.01
$ wget http://nlp.ist.i.kyoto-u.ac.jp/nl-resource/juman/juman-7.01.tar.bz2
$ tar -jxvf juman-7.01.tar.bz2

# KNP 5.0
$ git clone https://github.com/ku-nlp/knp.git

# copy some files from knp to juman
$ cp knp/juman/makemat/makemat.c juman-7.01/makemat/
$ cp knp/juman/dic/JUMAN.grammar juman-7.01/dic/
$ cp knp/juman/dic/JUMAN.kankei juman-7.01/dic/
$ cp knp/juman/dic/JUMAN.katuyou juman-7.01/dic/

# install juman
$ cd juman-7.01/
$ ./configure
$ make
$ sudo make install
$ cd ..

jumanppとKNPはいつもどおりです

# jumanppの再インストール(v2で動作確認)
$ wget https://github.com/ku-nlp/jumanpp/releases/download/v2.0.0-rc3/jumanpp-2.0.0-rc3.tar.xz
$ tar xvf jumanpp-2.0.0-rc3.tar.xz
$ cd jumanpp-2.0.0-rc3/
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
$ cd ../..

# KNPのインストール
$ sudo apt-get install automake m4 libtool automake autoconf
$ cd knp
$ ./autogen.sh
$ wget http://lotus.kuee.kyoto-u.ac.jp/nl-resource/knp/dict/latest/knp-dict-latest-bin.zip
$ unzip knp-dict-latest-bin.zip
$ cp -ars `pwd`/dict-bin/* ./dict
$ ./configure
$ make
$ sudo make install
$ cd ..

configureがないとか出た場合はautogen.shの実行に失敗しているので、ログを見てください
必要なライブラリが足りていない感じです、多分

$ python
from pyknp import KNP
knp = KNP()
knp.parse("学校でしてね")
-> 成功

行けましたね
解決策を提示していただいた方に感謝です
これに加えて200文字以上の長文を加えないようにしたら、KNPのエラーはほぼなくなりました

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