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.

因此,當 in 時-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.

在單字行上加上前綴*(注意單字和前綴之間不應有空格)會將該單字加到使用者的字典​​中,但僅限於當前hunspell會話,因為根據頁面man,只有前綴為的行#才會導致個人字典要儲存(即磁碟上的檔案)。因此運行

echo "*goosfraba" | hunspell -a

絕對什麼都不做。hunspell添加古斯弗拉巴到此會話的字典然後退出(沒有其他行要處理)。您必須添加帶有前綴的第二行#才能保存最近添加的單字:

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字典裡沒有,有一個差點發生:傻瓜球

::將 goosfraba 加入字典中,然後在同一hunspell會話期間進行拼字檢查(兩行):

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會話期間保存(兩行):

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

對於語言“en”,這似乎是共享“便攜式詞典”的好方法,順便說一句

相關內容