Adding multiple dictionaries

112 views
Skip to first unread message

Vincent Fulco

unread,
Dec 3, 2015, 3:33:25 AM12/3/15
to pyenchant users
Doing some text processing of Chinese docs converted to English and in many cases, British English is used.  My orientation is "en_US".  However I do want to scrutinize for both US & UK dictionaries but first pass attempt (below) led to losing both the UK check and my personal word list.  I couldn't get deep enough in to the source code to check the method/function details.

d2 = enchant.DictWithPWL("en_US", "en_GB", pwl)

Googled quite a bit and don't immediately see an existing way to add established dictionaries.  Is that correct? TIA.


Ryan Kelly

unread,
Dec 7, 2015, 10:50:35 AM12/7/15
to pyencha...@googlegroups.com
On 3/12/2015 03:31, Vincent Fulco wrote:
> Doing some text processing of Chinese docs converted to English and in
> many cases, British English is used. My orientation is "en_US".
> However I do want to scrutinize for both US & UK dictionaries but first
> pass attempt (below) led to losing both the UK check and my personal
> word list. I couldn't get deep enough in to the source code to check
> the method/function details.
>
> d2 = enchant.DictWithPWL("en_US", "en_GB", pwl)

FWIW, `help(enchant.DictWithPWL)` at the interactive prompt should give
you a nice description of the API.

> Googled quite a bit and don't immediately see an existing way to add
> established dictionaries. Is that correct? TIA.

I don't believe there's an existing way to "stack" multiple dictionaries
in order to check words from both simultaneously.

Your best bet may be to create a small wrapper class to do this,
something like:

class UnionDict:

def __init__(self, *dicts):
self.dicts = []
for dict in dicts:
if isinstance(dict, str):
dict = enchant.Dict(dict)
self.dicts.append(dict)

def check(self, word):
for dict in self.dicts:
if dict.check(word):
return True
return False

def suggest(self, word):
# It's not obvious how to do a good job of this
# bit, but returning suggestions from all dicts
# may be good enough



Cheers,

Ryan
Reply all
Reply to author
Forward
0 new messages