Add LibreOffice dictionary to Pyenchant on Windows for Anaconda

945 views Asked by At

How can I add dictionaries from github.com/LibreOffice/dictionaries to pyenchant on windows for anaconda?

There are similar questions about this on SO, but not for windows:


Background

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

I've found and installed pyenchant inside the Anaconda Prompt successfully (on Windows 10) by using pip because it apparently can't be installed with conda for win-32 nor for 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

This worked for me. I can now open Spyder (Python 3.6) and then run

import enchant 
print(enchant.list_languages())

to see that I have some English dictionaries

['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']

I would like to have access to languages supported by LibreOffice.

1

There are 1 answers

0
Vepir On BEST ANSWER

Find your anaconda package (should be enchant).

Inside, find your provider (default should be hunspell).

For me, this is at

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

Now, simply add .aff and .dic files of the desired language to this hunspell folder.

For example, github.com/LibreOffice/dictionaries/tree/master/hr_HR is for Croatian (Hrvatski).

Then for example,

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

Returns

True

as expected. ("mačak" = croatian word for male cat.)