LoginSignup
5
1

More than 1 year has passed since last update.

chikkarpyを使って同義語検索やってみた

Posted at

はじめに

ネットサーフィンしていたら、同義語検索ライブラリでchikkarpyというのがあるらしい。

面白そうなので、使ったみました。

インストール

pip install chikkarpy

これだけ。凄い楽ちん

pythonでの実装例

以下のように、簡単に同義語検索を試すことができます。

from chikkarpy import Chikkar
from chikkarpy.dictionarylib import Dictionary

chikkar = Chikkar()
system_dic = Dictionary(<system.dicのファイルパス>, False)

chikkar.add_dictionary(system_dic)

print(chikkar.find("漫画"))
# ['コミックス', 'comics', 'まんが', 'マンガ', '漫画雑誌', 'コミック', 'comic']

この時<system.dicのファイルパス>ですが、chikkarpyをインストールするとpythonのバージョン/site-packages/chikkarpy/resources/system_synonym.dicというファイルパスがあるはずなので、それを指定すれば大丈夫です。

あと、他の例でも試してみました。ポケモンの同義語として考えられる「ポケットモンスター」などは存在しなかったので、別途辞書を作成してビルドする必要がありそうです(カスタム辞書のビルド方法は最初に載せていた参考URLで説明されていました)。

print(chikkar.find("ポケモン"))

print(chikkar.find("博士課程"))

print(chikkar.find("就職"))

print(chikkar.find("ポスドク"))

print(chikkar.find("将来"))

print(chikkar.find("不安"))

print(chikkar.find("結婚"))

print(chikkar.find("メンタル"))
[]
['ドクターコース', 'doctor course']
['入社']
['ポストドクター', '博士研究員']
['前途', '未来', '行く先', '行く末', '先行き', 'フューチャー', 'future']
['恐れ', '畏れ', '虞', 'おそれ', '不安感', '懸念', '危惧', '心配', '気掛かり', '憂慮']
['婚姻', '入籍']
['mental', '精神的']

うーん、同義語のせいで不安な単語を入れたら不安を煽る単語が沢山出てきた(泣)

対義語検索ライブラリ欲しい...

5
1
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
5
1