【问题标题】:PyEnchant weird behavior for numbersPyEnchant 奇怪的数字行为
【发布时间】:2016-05-11 19:08:15
【问题描述】:

我正在使用 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']

【问题讨论】:

    标签: python pyenchant


    【解决方案1】:

    这是由于底层提供者。在 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。第二个是您在 Mac 上看到的内容,我正在使用 Aspell Provider。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2018-02-23
      • 2021-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多