在 Windows 上为 Anaconda 添加 LibreOffice 词典到 Pyenchant

Add LibreOffice dictionary to Pyenchant on Windows for Anaconda

如何在 windows 上为 anaconda 添加从 github.com/LibreOffice/dictionariespyenchant 的词典?

SO 上也有类似的问题,但 windows:


背景

I've been looking for a way to check if a given string is a valid word of a given language.

found and installed pyenchant inside the Anaconda Prompt successfully (on Windows 10) by using pip because it apparently 无法安装 conda for win-32 也无法安装 win-64.

  (base) C:\Users\V>pip install pyenchant
    Collecting pyenchant
      Downloading pyenchant-3.2.0-py3-none-win_amd64.whl (11.9 MB)
         |████████████████████████████████| 11.9 MB 1.7 MB/s
    Installing collected packages: pyenchant
    Successfully installed pyenchant-3.2.0

这对我有用。我现在可以打开 Spyder (Python 3.6) 然后 运行

import enchant 
print(enchant.list_languages())

看到我有一些英文词典

['en_BW', 'en_AU', 'en_BZ', 'en_GB', 'en_JM', 'en_DK', 'en_HK', 'en_GH', 'en_US', 'en_ZA', 'en_ZW', 'en_SG', 'en_NZ', 'en_BS', 'en_AG', 'en_PH', 'en_IE', 'en_NA', 'en_TT', 'en_IN', 'en_NG', 'en_CA']

我想访问 LibreOffice 支持的语言。

找到你的 anaconda 包(应该是 enchant)。

在里面,找到你的供应商(默认应该是 hunspell)。

对我来说,这是在

C:\Users\V\Anaconda3\Lib\site-packages\enchant\data\mingw64\share\enchant\hunspell

现在,只需将所需语言的 .aff.dic 文件添加到此 hunspell 文件夹即可。

例如,github.com/LibreOffice/dictionaries/tree/master/hr_HR 代表克罗地亚语 (Hrvatski)。

那么例如,

d = enchant.Dict("hr_HR")
print(d.check("mačak"))

Returns

True

符合预期。 (“mačak”= 克罗地亚语中公猫的意思。)