How to use custom word lists in Enchant?

44 views Asked by At

I can't seem to get a personal word list working with Enchant.

I have a list of technical terms that I've been using happily with command line Hunspell for some time. It's just one word per line. The following code produces an empty array:

$b = enchant_broker_init();
$dict = enchant_broker_request_pwl_dict($b,'/path/to/my.pwl');
// enchant_dict_add($dict,'monospace'); // already in file
$suggestions = enchant_dict_suggest($dict,'monaspace');

Is this not how enchant_broker_request_pwl_dict is supposed to work?

Ideally I'd combine the built-in English dictionary with my custom list. I know I can add my words in memory using enchant_dict_add_to_session but I'd like to know what's wrong here.

I'm running this in PHP 8.0 on a Mac. The spelling backend appears to be aspell.


Update 1: I've established that use of enchant_dict_check works with a PWL, and is case-insensitive as long as it's lower case in the file.

enchant_dict_check($dict,'Monospace'); // true
enchant_dict_check($dict,'monospace'); // true

Still, not much use if corrections to custom words can't be suggested. What is the recommended approach to this, using Enchant?


Update 2: I've now installed Enchant on my Linux server which uses Hunspell as the backend. Here enchant_broker_request_pwl_dict DOES work as per the code above, but enchant_dict_add_to_session does NOT. I'm still none the wiser how to merge the custom strings and base dictionary, other than by doing two spell checks for every word.

0

There are 0 answers