Pyenchant store_replacement 不起作用?

Pyenchant store_replacement doesn't work?

我尝试了 pyenchant 中的所有功能,当我尝试 store_replacement 时,它对我不起作用,我也不知道为什么。这是我的代码:

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

根据 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.

如您所见,它并没有提出我的建议。建议列表完全相同。如果我尝试做同样的事情,但使用建议列表中不存在的词,我也会得到同样的结果。

我不明白我做错了什么。 我感谢任何帮助。谢谢!

我的理解是store_replacement需要底层provider来实现。我的猜测是您正在使用 Myspell 或其他未实现它的提供程序。如果您将提供程序更改为实现它的 Aspell,您可以看到它的工作方式如下: (请注意,您需要安装 Aspell 及其词典才能正常运行)

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)

在我运行几次之后用不同的替换(以前用"alloy"、"hallow"、"sallow")最后在这个运行 "aloe" 它输出:

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