SudachiPy
出力テキストの評価指標・前処理
WorksApplications/SudachiPy: Python version of Sudachi, a Japanese tokenizer.
WorksApplications/sudachi.rs: Sudachi in Rust 🦀 and new generation of SudachiPy
Welcome to SudachiPy documentation! — SudachiPy 0.6.9-a1 documentation
0.6 以降は rust で書かれているのでインストールに rustc & setuptools_rust がいる?
コンテナに入れるなら
code:Dockerfile
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH=/root/.cargo/bin:$PATH # これは root の例、他の USER なら $HOME/.cargo/bin にパス通す
code:synopsis.py
from sudachipy import dictionary, tokenizer
t = dictionary.Dictionary().create()
t.tokenize("東京特許許可局", mode=tokenizer.Tokenizer.SplitMode.A) # => MorphemeListMorpheme, ...
辞書
SudachiPy/docs/tutorial.md at develop · WorksApplications/SudachiPy
Sudachi辞書の紹介 Part 1 -3種類の辞書- Sudachi - Qiita このシリーズは最高
サイズは small < core < full
code:dictionary.py
tokenizer_core = dictionary.Dictionary(dict="core").create()
tokenizer_full = dictionary.Dictionary(dict="full").create()
分割モード
Sudachi辞書の紹介 Part 3 -分割モードおよび分割情報- Sudachi - Qiita
A単位は、検索用の短い単位、B単位は、国語辞典の見出しに近い日本語として自然な単位、C単位は、Sudachi辞書に登録している語の長さそのもの、となります。
code:splitmode.py
mode = tokenizer.Tokenizer.SplitMode.A
tokenizer_core.tokenize("国家公務員", mode=mode)
固有表現抽出なら C かな
形態素のメソッド
code:methods.py
m = tokenizer_obj.tokenize("食べ", mode)0
m.surface() # => '食べ'
m.dictionary_form() # => '食べる'
m.reading_form() # => 'タベ'
m.part_of_speech() # => '動詞', '一般', '*', '*', '下一段-バ行', '連用形-一般'
m.part_of_speech_id() # => 379
dictionary.Dictionary(dict="core").pos_of(379)
#=> ('動詞', '一般', '*', '*', '下一段-バ行', '連用形-一般')
# 正規化
m.normalized_form() #=> 食べる
part_of_speech is 何
長さ6のタプル
(品詞大分類, 品詞中分類, 品詞小分類, 品詞細分類, 活用型大分類-活用型行分類, 活用形大分類-活用形小分類) が返る
Sudachi辞書の紹介 Part 2 -品詞体系- Sudachi - Qiita に一覧がある
code:part_of_speech.py
[
(t.surface(), t.part_of_speech())
for t in tokenizer_full.tokenize(
"夕ご飯はマクドナルドのラーメンでした", mode=tokenizer.Tokenizer.SplitMode.C
)
]
# =>
[('夕ご飯', ('名詞', '普通名詞', '一般', '*', '*', '*')),
('は', ('助詞', '係助詞', '*', '*', '*', '*')),
('マクドナルド', ('名詞', '固有名詞', '一般', '*', '*', '*')),
('の', ('助詞', '格助詞', '*', '*', '*', '*')),
('ラーメン', ('名詞', '普通名詞', '一般', '*', '*', '*')),
('でし', ('助動詞', '*', '*', '*', '助動詞-デス', '連用形-一般')),
('た', ('助動詞', '*', '*', '*', '助動詞-タ', '終止形-一般'))]
名詞で何かする(何かとは?)なら
PosMatcher
SudachiPyのPosMatcher 自然言語処理 - Qiita
Sudachi/docs/user_dict.md at develop · WorksApplications/Sudachi