How to correct text and return the corrected text automatically with PyEnchant

后端 未结 3 445
忘了有多久
忘了有多久 2021-01-13 10:20
import enchant
import wx
from enchant.checker import SpellChecker
from enchant.checker.wxSpellCheckerDialog import wxSpellCheckerDialog
from enchant.checker.CmdLineC         


        
3条回答
  •  孤街浪徒
    2021-01-13 10:45

    For my purposes, the level of automation you provided here was too risky -- the words were going to include proper nouns -- so I built a bit more of a check into the system.

    I'm appending the corrections for a file-write later in the process.

    Thought this would be helpful for others as the documentation wasn't quite sufficient for me...

    for data_field in fields:
        checker.set_text(str(data_field))
        for err in checker:
            print err.word
            print err.suggest()
            correct = raw_input("provide 0-index int of correct word or i to ignore, e to edit ")
            if correct == 'i':
                pass
            elif correct == 'e':
                suggest = raw_input("")
                err.replace(suggest)
            else:
                correct = int(correct)
                suggest = err.suggest()[correct]
                err.replace(suggest)
        corrected_text.append(checker.get_text())
    

提交回复
热议问题