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