LoginSignup
0
0

SudachiPy にて未知語を判定する

Posted at

Sudachi はUniDic品詞体系なので、品詞として未知語は存在しません。
SudachiPy を利用して形態素解析を行う場合、未知語を判定したい場合があります。

手元の環境は以下になります。

  • Ubuntu 22.04.2 LTS
  • Python 3.10.6
  • SudachiDict-core==20221021
  • SudachiPy==0.6.6

未知語を判定したい場合は以下のようにis_oov()を使って実装します。

from sudachipy import tokenizer
from sudachipy import dictionary

tokenizer_obj = dictionary.Dictionary().create()
mode = tokenizer.Tokenizer.SplitMode.A

contents = 'ChatGPTに質問する'

for m in tokenizer_obj.tokenize(contents, mode):
    word = m.normalized_form()
    print(word + ':未知語判定 ' + str(m.is_oov()))

上記のコードを実行すると以下のような結果になります。

chatgpt:未知語判定 True
に:未知語判定 False
質問:未知語判定 False
為る:未知語判定 False

参考になった記事

sudachipy.Morpheme.is_oov

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