Skip to main content

Python version of chikkar, a library for using the Sudachi synonym dictionary

Project description

chikkarpy

PyPi version test

chikkarpyはchikkarのPython版です。 chikkarpy は Sudachi 同義語辞書を利用し、SudachiPyの出力に同義語展開を追加するために開発されたライブラリです。 単体でも同義語辞書の検索ツールとして利用できます。

chikkarpy is a Python version of chikkar. chikkarpy is developed to utilize the Sudachi synonym dictionary and add synonym expansion to the output of SudachiPy. This library alone can be used as a search tool for our synonym dictionaries.

利用方法 Usage

TL;DR

$ pip install chikkarpy

$ echo "閉店" | chikkarpy
閉店    クローズ,close,店仕舞い

Step 1. chikkarpyのインストール Install chikkarpy

$ pip install chikkarpy

Step 2. 使用方法 Usage

コマンドライン Command Line

$ echo "閉店" | chikkarpy
閉店    クローズ,close,店仕舞い

chikkarpyは入力された単語を見て一致する同義語のリストを返します。 chikkarpy looks at a headword of synonym dictionary by the entered word and returns a list of matching synonyms.

同義語辞書内の曖昧性フラグが1の見出し語をトリガーにすることはできません。 You cannot use a headword with an ambiguity flag of 1 in a synonym dictionary as a search trigger.

出力はクエリ\t同義語リストの形式です。 The output is in the form of a query \t synonym list.

デフォルトの Sudachi 同義語辞書 の見出し語は、 SudachiPyの正規化形 (normalized_form()) で登録されています。

The headwords in the Sudachi synonym dictionary are registered in SudachiPy's normalized form, normalized_form().

$ chikkarpy search -h
usage: chikkarpy search [-h] [-d [file [file ...]]] [-ev] [-o file] [-v]
                        [file [file ...]]

Search synonyms

positional arguments:
  file                  text written in utf-8

optional arguments:
  -h, --help            show this help message and exit
  -d [file [file ...]]  synonym dictionary (default: system synonym
                        dictionary)
  -ev                   Enable verb and adjective synonyms.
  -o file               the output file
  -v, --version         print chikkarpy version

自分で用意したユーザー辞書を使いたい場合は-dで読み込むバイナリ辞書を指定できます。 (バイナリ辞書のビルドは辞書の作成を参照してください。) When you use your user dictionary, you should specify the binary dictionary to read with -d. (For building a binary dictionary, see Building a Dictionary.)

複数辞書を読み込む場合は順番に注意してください。 When reading multiple dictionaries, pay attention to the order.

以下の場合,user2 > user > system の順で同義語を検索して見つかった時点で検索結果を返します。 In the following cases, the synonyms are searched in the order of user2 > user > system, and the search results are returned which are first found.

chikkarpy -d system.dic user.dic user2.dic

また、出力はデフォルトで体言のみです。 Also, the output is noun only by default.

用言も出力したい場合は-evを有効にしてください。 When you want to output verb as well, please enable -ev.

$ echo "開放" | chikkarpy
開放	オープン,open
$ echo "開放" | chikkarpy -ev
開放	開け放す,開く,オープン,open

Python ライブラリ / Python library

使用例 Example of use

from chikkarpy import Chikkar
from chikkarpy.dictionarylib import Dictionary

chikkar = Chikkar()

# デフォルトのシステム同義語辞書を使う場合,Dictionaryの引数は省略可能 You may omit the ``Dictionary`` arguments if you want to use the system synonym dictionary
system_dic = Dictionary()
chikkar.add_dictionary(system_dic)

print(chikkar.find("閉店"))
# => ['クローズ', 'close', '店仕舞い']

print(chikkar.find("閉店", group_ids=[5])) # グループIDによる検索 Search by group ID
# => ['クローズ', 'close', '店仕舞い']

print(chikkar.find("開放"))
# => ['オープン', 'open']

chikkar.enable_verb() # 用言の出力制御(デフォルトは体言のみ出力) Output control of verbs (default is to output only nouns)
print(chikkar.find("開放"))
# => ['開け放す', '開く', 'オープン', 'open']

chikkar.add_dictionary()で複数の辞書を読み込ませる場合は順番に注意してください。 最後に読み込んだ辞書を優先して検索します。 また、enable_trieFalseに設定した辞書では、同義語を検索するときに見出し語よりもグループIDを優先して検索します。

When you read multiple dictionaries with chikkar.add_dictionary(), pay attention to the order. Priority is given to the last read dictionary. If enable_trie is False, a search by synonym group IDs takes precedence over a search by the headword.

chikkar = Chikkar()

system_dic = Dictionary(enable_trie=False)
user_dic = Dictionary(user_dict_path, enable_trie=True)
user2_dic = Dictionary(user_dict_path, enable_trie=True)

chikkar.add_dictionary(system_dic)
chikkar.add_dictionary(user_dic)
chikkar.add_dictionary(user2_dic)

辞書の作成 Build a dictionary

新しく辞書を追加する場合は、利用前にバイナリ形式辞書の作成が必要です。 Before using new dictionary, you need to create a binary format dictionary.

同義語辞書のフォーマットはSudachi 同義語辞書に従ってください。 Follow the Sudachi Synonym Dictionary for the format of the synonym dictionary.

$ chikkarpy build -i synonym_dict.csv -o system.dic 
$ chikkarpy build -h
usage: chikkarpy build [-h] -i file [-o file] [-d string]

Build Synonym Dictionary

optional arguments:
  -h, --help  show this help message and exit
  -i file     dictionary file (csv)
  -o file     output file (default: synonym.dic)
  -d string   description comment to be embedded on dictionary

開発者向け

Code Format

scripts/lint.sh を実行して、コードが正しいフォーマットかを確認してください。 Run scripts/lint.sh to check if your code is formatted correctly.

flake8 flake8-import-order flake8-builtins が必要です。 You need packages flake8 flake8-import-order flake8-builtins.

Test

scripts/test.sh を実行してテストしてください。 Run scripts/test.sh to run the tests.

Contact

chikkarpyはWAP Tokushima Laboratory of AI and NLPによって開発されています。 chikkarpy is developed by WAP Tokushima Laboratory of AI and NLP.

開発者やユーザーの方々が質問したり議論するためのSlackワークスペースを用意しています。 Open an issue, or come to our Slack workspace for questions and discussion.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chikkarpy-0.1.1.tar.gz (28.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page