I was trying all of the functions in pyenchant
and when I tried store_replacement
, it didn't work for me and I have no idea why. Here's my code:
d = enchant.Dict('en_us')
d.check('alllow')
Out[1]: False
d.suggest('alllow')`
Out[2]: ['allow',
'all low',
'all-low',
'wallop',
'allot',
'alloy',
'Willow',
'allele',
'allover']
d.store_replacement('alllow', 'alloy')`
d.suggest('alllow')`
Out[3]: ['allow',
'all low',
'all-low',
'wallop',
'allot',
'alloy',
'Willow',
'allele',
'allover']
According to the docs from pyenchant:
store_replacement(mis, cor)
:
Store a replacement spelling for a miss-spelled word. This method makes a suggestion to the spellchecking engine that the miss-spelled word is in fact correctly spelled as cor. Such a suggestion will typically mean that cor appears early in the list of suggested spellings offered for later instances of mis.
As you see it doesn't bring forward my suggestion. The suggestion list is exactly the same. If I try to do the same thing but with a word that doesn't exists in the suggestion list I get the same.
I don't understand what I'm doing wrong. I appreciate any help. Thanks!
My understanding is that store_replacement needs to be implemented by the underlying provider. My guess is that you are using Myspell or some other provider which doesn't implement it. If you change the provider to Aspell which implements it you can see it working like so: (Note you will need to install Aspell and it's dictionaries to see this working)
import enchant
b = enchant.Broker()
b.set_ordering("en_US","aspell,myspell")
print b.describe()
d=b.request_dict("en_US")
print d.provider
s = 'alllow'
d.check(s)
print d.suggest(s)
d.store_replacement(s, 'alloy')
print d.suggest(s)
After I have run it a few times with different replacements (previously with "alloy", "hallow", "sallow") and finally in this run "aloe" it outputs:
[<Enchant: Aspell Provider>, <Enchant: Myspell Provider>, <Enchant: Hspell Provider>, <Enchant: Ispell Provider>]
<Enchant: Aspell Provider>
['alloy', 'hallow', 'sallow', 'all low', 'all-low', 'allow', 'Allie', 'aloe', 'allows', 'all', 'callow', 'fallow', 'mallow', 'tallow', 'wallow', 'ally', 'aglow', 'allot', 'Allah', 'allay', 'alley']
['alloy', 'hallow', 'sallow', 'aloe', 'all low', 'all-low', 'allow', 'Allie', 'allows', 'all', 'callow', 'fallow', 'mallow', 'tallow', 'wallow', 'ally', 'aglow', 'allot', 'Allah', 'allay', 'alley']