Failed to load user dict
kazukinagata opened this issue · 2 comments
kazukinagata commented
こんにちは、素晴らしいライブラリをありがとうございます。
ユーザー辞書を登録するためsudachi.json
をproject rootに配置し、Dictionary
のconfig_path
にsudachi.json
までのパスを渡した際に以下のエラーが起きます。ユーザー辞書の期待するパスは/path_to_myproject/dict/user.dic
ですが、実際に参照されるのは/path_to_myproject/venv/lib/python3.8/site-packages/sudachipy/resources/dict/user.dic
のようです。
ちなみに、pip install sudachipy
でインストールした場合にこのようなエラーになりますが、pip install git+git://github.com/WorksApplications/SudachiPy@develop#egg=SudachiPy
の場合エラーは起きませんでした。
from pathlib import Path
from sudachipy import tokenizer
from sudachipy import dictionary
config_path = os.path.join(
Path(os.path.dirname(__file__)).resolve().parent, "sudachi.json")
tokenizer_obj = dictionary.Dictionary(config_path=config_path).create()
# Exception: Error while constructing dictionary: /path_to_myproject/venv/lib/python3.8/site-packages/sudachipy/resources/dict/user.dic
// プロジェクト構成
.
├── dict
│ ├── char.def
│ ├── rewrite.def
│ ├── sudachi-user-dict.csv
│ ├── unk.def
│ └── user.dic
├── sudachi.json
└── venv
// sudachi.json
{
"systemDict": "",
"userDict": ["dict/user.dic"],
"characterDefinitionFile": "dict/char.def",
"inputTextPlugin": [
{ "class": "sudachipy.plugin.input_text.DefaultInputTextPlugin" },
{
"class": "sudachipy.plugin.input_text.ProlongedSoundMarkInputTextPlugin",
"prolongedSoundMarks": ["ー", "-", "⁓", "〜", "〰"],
"replacementSymbol": "ー"
}
],
"oovProviderPlugin": [
{
"class": "sudachipy.plugin.oov.MeCabOovProviderPlugin",
"charDef": "dict/char.def",
"unkDef": "dict/unk.def"
},
{
"class": "sudachipy.plugin.oov.SimpleOovProviderPlugin",
"oovPOS": ["補助記号", "一般", "*", "*", "*", "*"],
"leftId": 5968,
"rightId": 5968,
"cost": 3857
}
],
"pathRewritePlugin": [
{
"class": "sudachipy.plugin.path_rewrite.JoinNumericPlugin",
"enableNormalize": true
},
{
"class": "sudachipy.plugin.path_rewrite.JoinKatakanaOovPlugin",
"oovPOS": ["名詞", "普通名詞", "一般", "*", "*", "*"],
"minLength": 3
}
]
}
Python: 3.8.10
sudachipy 0.6.2 // pip install sudachipy
sudachipy 0.5.5.dev1+gb244110 // pip install git+
Update
ずっとこのリポジトリのconfig.pyを読んでましたが、v0.6からはこちらのリポジトリぽいですね。
eiennohito commented
0.6.* は resource_pathをもとにしかパスを解決していないのが問題です。
相対パスの場合、解決順を以下にするべき:
- Config上の
path
に対してのバリュー resource_path
の値Config
のファイルの親フォルダー
かな
eiennohito commented
修正したv0.6.3をリリースしました。試してみてください。