1

スペル/文法修正スクリプトに PyEnchant を使用しています。Mac で次の動作に気付きました。

>>> import enchant
>>> d  = enchant.Dict('en_us')
>>> d.suggest('50')
['W', 'Y', 'w', 'y', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'z']
>>> enchant.__version__
'1.6.6'

ただし、私のLinuxマシン(同じバージョンのpyenchant)ではより予想通りに動作します

>>> import enchant
>>> d = enchant.Dict('en_us')
>>> d.suggest('50')
['5', '0', '50s']
4

1 に答える 1

0

これは、基になるプロバイダーが原因です。Ubuntu では、myspell と aspell の両方に en_US 辞書がインストールされています。プロバイダーを切り替えると、異なる結果が得られます。たとえば、次のようなスクリプトを使用します。

import enchant

b = enchant.Broker()
b.set_ordering("en_US","myspell,aspell")
print b.describe()
d=b.request_dict("en_US")
print d.provider
s = '50'
print d.suggest(s)

b = enchant.Broker()
b.set_ordering("en_US","aspell,myspell")
print b.describe()
d=b.request_dict("en_US")
print d.provider
s = '50'
print d.suggest(s)

次の出力が得られます。

[<Enchant: Aspell Provider>, <Enchant: Ispell Provider>, <Enchant: Myspell Provider>, <Enchant: Hspell Provider>]
<Enchant: Myspell Provider>
['5', '0', '50s']
[<Enchant: Aspell Provider>, <Enchant: Ispell Provider>, <Enchant: Myspell Provider>, <Enchant: Hspell Provider>]
<Enchant: Aspell Provider>
['W', 'Y', 'w', 'y', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'X', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'z']

最初の提案は Linux で見られるものですが、私は Myspell Provider を使用しています。2 つ目は、Mac で表示されているもので、私は Aspell Provider を使用しています。

于 2016-05-19T20:04:03.077 に答える