hunspell: コマンドラインから辞書に単語を追加する

hunspell: コマンドラインから辞書に単語を追加する

からhunspell マニュアルページ:

...
    When in the -a mode, hunspell will also accept lines  of  single
    words  prefixed  with  any of '*', '&', '@', '+', '-', '~', '#',
    '!', '%', '`', or '^'.  A line starting with '*' tells  hunspell
    to  insert the word into the user's dictionary (similar to the I
    command).
...

次のようなことを試してみましたecho "* my_word" | hunspell -aが、サンプルファイルを再度解析するとスペルミスとして表示されるため、この単語は辞書にありません。

これはどのように機能するのでしょうか。カスタム単語を追加するにはどうすればよいでしょうか。
または、Aspell や、Hunspell/Aspell で読み取られる互換性のある辞書に書き込む「一般的な」プログラムではどうでしょうか。

答え1

(similar to the I command)代わりに次のようにすべきだと思います(similar to the A command):

A

Accept the word for the rest of this hunspell session. 

もう一度ページを確認してみましょうman:

The -a option is intended to be used from other programs through a pipe.
In this mode, hunspell prints a one-line version identification message,
and then begins reading lines of input.

したがって、 の場合-a modehunspell最後の入力行を読み取って処理した後にセッションが終了します。さらに、

When in the -a mode, hunspell will also accept lines of single words prefixed
with any of '*', '&', '@', '+', '-', '~', '#', '!', '%', ''', or '^'. A line
starting with '*' tells hunspell to insert the word into the user's dictionary
(similar to the I command)[........] A line prefixed with '#' will cause the
personal dictionary to be saved.

1つの単語行に をプレフィックスとして付けると*(単語とプレフィックスの間にスペースを入れないでください)、その単語がユーザーの辞書に追加されますが、これは現在のhunspellセッションのみで、ページによるとman、 をプレフィックスとして付けた行のみが#個人辞書(つまりディスク上のファイル)を保存するためです。したがって、

echo "*goosfraba" | hunspell -a

何もしません。hunspell追加グースフラバこのセッションの辞書に を追加して終了します (処理する他の行はありません) #。最近追加された単語を保存するには、を先頭に付けた 2 番目の行を追加する必要があります。

echo -e "*goosfraba\n#" | hunspell -a

見てみましょう:

::スペルチェックグースフラバ:

echo -e "goosfraba" | hunspell -a
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
& goosfraba 1 0: goofball

& = はWord辞書にないので、ニアミスが 1 つあります。間抜け

::goosfraba を辞書に追加し、同じhunspellセッション中にスペルチェックを実行します (2 行):

echo -e "*goosfraba\ngoosfraba" | hunspell -a
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
*

* = はWord辞書にあります。

::スペルチェックグースフラバ再度(新しいhunspellセッション):

echo -e "goosfraba" | hunspell -a
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
& goosfraba 1 0: goofball

& = これもword辞書にありません (前回のセッションでは何も保存されていません)

::goosfraba を辞書に追加し、同じhunspellセッション中に保存します (2 行):

echo -e "*goosfraba\n#" | hunspell -a
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)

::スペルチェックグースフラバ再度(新しいhunspellセッション):

echo "goosfraba" | hunspell -a
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
*

* = はWord辞書にあります。

答え2

最も簡単な解決策は、Aspellを使用してホームフォルダにカスタムファイルを作成し、.aspell.lang.pws、内容は次のようになります:

personal_ws-1.1 en 0
my_word

ところで、これは「ポータブル辞書」を共有する素晴らしい方法のように思えます。

関連情報