【问题标题】:Spelling correction in sentences句子中的拼写更正
【发布时间】:2019-02-16 13:19:21
【问题描述】:

我使用https://norvig.com/spell-correct.html 查找拼写错误

如何在句子中查找和替换拼写错误的单词。

目前的努力:

sentences = "This sntence cntins errors. This sentence has to be corrcted."
list_string = sentences.split(' ') 
for word in list_string:
    print(correction(word))

输出:

this
sentence
contains
error
this
sentence
has
to
be
corrected.

预期输出:

This <<sntence>> sentence <<cntins>> contains errors. This sentence has to be <<corrcted>> corrected.

可以使用https://stackoverflow.com/questions/48123861/spelling-mistakes-pyenchant.实现它如何在保留拼写错误的单词的同时将拼写错误的单词查找并替换为原始文本>

【问题讨论】:

  • 你有什么问题?您链接到的答案有什么问题?
  • 什么是“直接方法”?为什么需要更多的方法?顺便说一句,你的拼写检查模块不是很好,它不能识别“错误”这个词。
  • 得到了答案。该错误基于 big.txt 并且可能不包含关闭词。感谢您的回复。

标签: python regex spelling


【解决方案1】:

尝试str.join生成器:

print(' '.join('<<'+i+'>>'+' %s'%correction(i) if correction(i) != i else i for i in sentences.split()))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    相关资源
    最近更新 更多