Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit 8f53044

Browse files
committed
add dictionary option document
1 parent f286c6f commit 8f53044

File tree

2 files changed

+109
-26
lines changed

2 files changed

+109
-26
lines changed

README.md

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ EOS
7070

7171
```bash
7272
$ sudachipy tokenize -h
73-
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-a] [-d] [-v]
73+
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-s string]
74+
[-a] [-d] [-v]
7475
[file [file ...]]
7576

7677
Tokenize Text
@@ -83,6 +84,7 @@ optional arguments:
8384
-r file the setting file in JSON format
8485
-m {A,B,C} the mode of splitting
8586
-o file the output file
87+
-s string sudachidict type
8688
-a print all of the fields
8789
-d print the debug information
8890
-v, --version print sudachipy version
@@ -175,33 +177,71 @@ tokenizer_obj.tokenize("シュミレーション", mode)[0].normalized_form()
175177
176178
## Dictionary Edition
177179
180+
**WARNING: `sudachipy link` is no longer available in SudachiPy v0.5.2 and later. **
181+
182+
178183
There are three editions of Sudachi Dictionary, namely, `small`, `core`, and `full`. See [WorksApplications/SudachiDict](https://github.com/WorksApplications/SudachiDict) for the detail.
179184
180-
SudachiPy uses `sudachidict_core` by default. You can specify the dictionary with the `link -t` command.
185+
SudachiPy uses `sudachidict_core` by default.
186+
187+
Dictionaries are installed as Python packages `sudachidict_small`, `sudachidict_core`, and `sudachidict_full`.
188+
189+
* [SudachiDict-small · PyPI](https://pypi.org/project/SudachiDict-small/)
190+
* [SudachiDict-core · PyPI](https://pypi.org/project/SudachiDict-core/)
191+
* [SudachiDict-full · PyPI](https://pypi.org/project/SudachiDict-full/)
192+
193+
The dictionary files are not in the package itself, but it is downloaded upon installation.
194+
195+
### Dictionary option: command line
196+
197+
You can specify the dictionary with the tokenize option `-s`.
181198
182199
```bash
183200
$ pip install sudachidict_small
184-
$ sudachipy link -t small
201+
$ echo "外国人参政権" | sudachipy -s small
185202
```
186203
187204
```bash
188205
$ pip install sudachidict_full
189-
$ sudachipy link -t full
206+
$ echo "外国人参政権" | sudachipy -s full
190207
```
191208
192-
You can remove the dictionary link with the `link -u` commnad.
209+
### Dictionary option: Python package
193210
194-
```bash
195-
$ sudachipy link -u
211+
You can specify the dictionary with the `Dicionary()` argument; `config_path` or `dict_type`.
212+
213+
```python
214+
class Dictionary(config_path=None, resource_dir=None, dict_type=None)
196215
```
197216
198-
Dictionaries are installed as Python packages `sudachidict_small`, `sudachidict_core`, and `sudachidict_full`. SudachiPy tries to refer `sudachidict` package to use a dictionary. The `link` subcommand creates *a symbolic link* of `sudachidict_*` as `sudachidict`, to switch the packages.
217+
1. `config_path`
218+
* You can specify the file path to the setting file with `config_path` (See [Dictionary in The Setting File](#Dictionary in The Setting File) for the detail).
219+
* If the dictionary file is specified in the setting file as `systemDict`, SudachiPy will use the dictionary.
220+
2. `dict_type`
221+
* You can also specify the dictionary type with `dict_type`.
222+
* The available arguments are `small`, `core`, or `full`.
223+
* If different dictionaries are specified with `config_path` and `dict_type`, **a dictionary defined `dict_type` overrides** those defined in the config path.
199224
200-
* [SudachiDict-small · PyPI](https://pypi.org/project/SudachiDict-small/)
201-
* [SudachiDict-core · PyPI](https://pypi.org/project/SudachiDict-core/)
202-
* [SudachiDict-full · PyPI](https://pypi.org/project/SudachiDict-full/)
225+
```python
226+
from sudachipy import tokenizer
227+
from sudachipy import dictionary
228+
229+
# default: sudachidict_core
230+
tokenizer_obj = dictionary.Dictionary().create()
231+
232+
# The dictionary given by the `systemDict` key in the config file (/path/to/sudachi.json) will be used
233+
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json").create()
234+
235+
# The dictionary specified by `dict_type` will be set.
236+
tokenizer_obj = dictionary.Dictionary(dict_type="core").create() # sudachidict_core (same as default)
237+
tokenizer_obj = dictionary.Dictionary(dict_type="small").create() # sudachidict_small
238+
tokenizer_obj = dictionary.Dictionary(dict_type="full").create() # sudachidict_full
239+
240+
# The dictionary specified by `dict_type` overrides those defined in the config path.
241+
# In the following code, `sudachidict_full` will be used regardless of a dictionary defined in the config file.
242+
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json", dict_type="full").create()
243+
```
203244
204-
The dictionary files are not in the package itself, but it is downloaded upon installation.
205245
206246
### Dictionary in The Setting File
207247
@@ -256,7 +296,7 @@ optional arguments:
256296
-h, --help show this help message and exit
257297
-d string description comment to be embedded on dictionary
258298
-o file output file (default: user.dic)
259-
-s file system dictionary (default: linked system_dic, see link -h)
299+
-s file system dictionary (default: core dic)
260300
```
261301
262302
About the dictionary file format, please refer to [this document](https://github.com/WorksApplications/Sudachi/blob/develop/docs/user_dict.md) (written in Japanese, English version is not available yet).

docs/tutorial.md

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ EOS
7070

7171
```bash
7272
$ sudachipy tokenize -h
73-
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-a] [-d] [-v]
73+
usage: sudachipy tokenize [-h] [-r file] [-m {A,B,C}] [-o file] [-s string]
74+
[-a] [-d] [-v]
7475
[file [file ...]]
7576

7677
Tokenize Text
@@ -83,6 +84,7 @@ optional arguments:
8384
-r file the setting file in JSON format
8485
-m {A,B,C} the mode of splitting
8586
-o file the output file
87+
-s string sudachidict type
8688
-a print all of the fields
8789
-d print the debug information
8890
-v, --version print sudachipy version
@@ -170,39 +172,80 @@ tokenizer_obj.tokenize("シュミレーション", mode)[0].normalized_form()
170172
(これは `20200330` `core` 辞書による出力例です。 辞書のバージョンによって変わる可能性があります。)
171173
172174
## 辞書の種類
175+
176+
**WARNING: `sudachipy link` コマンドは SudachiPy v0.5.2 以降から利用できなくなりました. **
177+
173178
Sudachi辞書は`small``core``full`の3種類があります。 詳細は[WorksApplications/SudachiDict](https://github.com/WorksApplications/SudachiDict)を参照してください。
174179
175-
SudachiPyはデフォルトでは`sudachidict_core`に設定されています。辞書設定の変更は`link -t`コマンドによって行えます。
180+
SudachiPyはデフォルトでは`sudachidict_core`に設定されています。
181+
182+
`sudachidict_small`, `sudachidict_core`, `sudachidict_full`はPythonのパッケージとしてインストールされます。
183+
184+
* [SudachiDict-small · PyPI](https://pypi.org/project/SudachiDict-small/)
185+
* [SudachiDict-core · PyPI](https://pypi.org/project/SudachiDict-core/)
186+
* [SudachiDict-full · PyPI](https://pypi.org/project/SudachiDict-full/)
187+
188+
辞書ファイルはパッケージ自体には含まれていませんが、上記のインストール時にダウンロードする処理が埋め込まれています。
189+
190+
### 辞書オプション: コマンドライン
191+
192+
辞書設定の変更は`-s`オプションで指定することができます。
176193
177194
178195
```bash
179196
$ pip install sudachidict_small
180-
$ sudachipy link -t small
197+
$ echo "外国人参政権" | sudachipy -s small
181198
```
182199
183200
```bash
184201
$ pip install sudachidict_full
185-
$ sudachipy link -t full
202+
$ echo "外国人参政権" | sudachipy -s full
186203
```
187204
188-
`link -u`によってリンクを削除するとデフォルトの`sudachidict_core`を使用します。
205+
### 辞書オプション: Python パッケージ
189206
190-
```bash
191-
$ sudachipy link -u
207+
Dictionary の引数 `config_path` または `dict_type` から利用する辞書を指定することができます。
208+
209+
```python
210+
class Dictionary(config_path=None, resource_dir=None, dict_type=None)
192211
```
193212
194-
`sudachidict_small`, `sudachidict_core`, `sudachidict_full`はPythonのパッケージとしてインストールされます。 SudachiPyは辞書を使用するとき`sudachidict` パッケージを参照します。 `link` によって`sudachidict_*``sudachidict`として参照するための *symbolic link* が作られます。
213+
1. `config_path`
214+
* `config_path` で辞書の設定ファイルのパスを指定することができます([辞書の設定ファイル](#辞書の設定ファイル) 参照)。
215+
* 指定した辞書の設定ファイルに、辞書のファイルパス `systemDict` が記述されていれば、その辞書を優先して利用します.
216+
2. `dict_type`
217+
* `dict_type` オプションで辞書の種類を直接指定することもできます。
218+
* `small`, `core`, `full` の3種類が指定可能です。
219+
* `config_path``dict_type` で異なる辞書が指定されている場合、**`dict_type` が優先**されます。
195220
196-
* [SudachiDict-small · PyPI](https://pypi.org/project/SudachiDict-small/)
197-
* [SudachiDict-core · PyPI](https://pypi.org/project/SudachiDict-core/)
198-
* [SudachiDict-full · PyPI](https://pypi.org/project/SudachiDict-full/)
221+
```python
222+
from sudachipy import tokenizer
223+
from sudachipy import dictionary
224+
225+
# デフォルトは sudachidict_core が設定されている
226+
tokenizer_obj = dictionary.Dictionary().create()
227+
228+
# /path/to/sudachi.json の systemDict で指定されている辞書が設定される
229+
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json").create()
230+
231+
# dict_type で指定された辞書が設定される
232+
tokenizer_obj = dictionary.Dictionary(dict_type="core").create() # sudachidict_core (デフォルトと同じ)
233+
tokenizer_obj = dictionary.Dictionary(dict_type="small").create() # sudachidict_small
234+
tokenizer_obj = dictionary.Dictionary(dict_type="full").create() # sudachidict_full
235+
236+
# dict_type (sudachidict_full) が優先される
237+
tokenizer_obj = dictionary.Dictionary(config_path="/path/to/sudachi.json", dict_type="full").create()
238+
```
199239
200-
辞書ファイルはパッケージ自体には含まれていませんが、上記のインストール時にダウンロードする処理が埋め込まれています。
201240
202241
### 辞書の設定ファイル
203242
204243
また、`sudachi.json`で辞書ファイルを切り替えることができます。
205244
245+
辞書のファイルパス `systemDict` は、絶対パスと相対パスのどちらでも指定可能です。
246+
247+
相対パスは、辞書の設定ファイルからの相対パスです。
248+
206249
207250
```
208251
{
@@ -250,7 +293,7 @@ optional arguments:
250293
-h, --help show this help message and exit
251294
-d string description comment to be embedded on dictionary
252295
-o file output file (default: user.dic)
253-
-s file system dictionary (default: linked system_dic, see link -h)
296+
-s file system dictionary (default: core dic)
254297
```
255298
256299
辞書ファイル形式については[user_dict.md](https://github.com/WorksApplications/Sudachi/blob/develop/docs/user_dict.md)を参照してください。

0 commit comments

Comments
 (0)