python文本纠错


def chkcntxt():

    oldwords = textPad.get(1.0, END)
    # d.SpellChecker("en_US") https://blog.csdn.net/hpulfc/article/details/80997252
    apiidchk='27213257'
    APIKey_wordchk = 'LkUF1O3NmssOQDB6RvnWkwy2'
    secretKey_wordchk = "dC373FcA7o62rPQSHL1WI0WIgjD42nmO"
    host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=LkUF1O3NmssOQDB6RvnWkwy2&client_secret=dC373FcA7o62rPQSHL1WI0WIgjD42nmO'
    response_token = requests.get(host)
    token = response_token.json()['access_token']
    print(token)
    url = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/ecnet?access_token=' + token
#https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?charset=UTF-8&access_token=24.f9ba9c5241b67688bb4adbed8bc91dec.2592000.1485570332.282335-8574074
    headers = {'Content-Type': 'application/json'}
    payload = {'text': oldwords,  }
    r = requests.post(url,params=payload,  headers=headers)
    result = r.json()
    result2='可能是:\n'+result['item']['correct_query']
    print(result2)
    # chkr = SpellChecker("en_US")
    # chkr.set_text(oldwords)
    # textPad3fanyi.delete(0.0, 'end')
    # for err in chkr:
    #     print("ERROR", err.word)
    #     showerr = "ERROR", err.word, '\n'
    #     textPad3fanyi.insert('end', showerr)
    # now1 = textPad3fanyi.get(1.0, END).replace('}', '').replace(' {', '')
    textPad3fanyi.delete(0.0, 'end')
    textPad3fanyi.insert('end', result2)

    # https://www.jc2182.com/python/python-text-translation.html
    showinfo('notice', '纠正后内容显示在 翻译区.')

def chkspell():
    import enchant
    from enchant.checker import SpellChecker
    oldwords = textPad.get(1.0, END)
    chkr = enchant.Dict("en_US")
    # d.SpellChecker("en_US") https://blog.csdn.net/hpulfc/article/details/80997252
    chkr = SpellChecker("en_US")
    chkr.set_text(oldwords)
    textPad3fanyi.delete(0.0, 'end')
    for err in chkr:
        print ("ERROR", err.word)
        showerr="ERROR", err.word,'\n'
        textPad3fanyi.insert('end', showerr)
    now1=textPad3fanyi.get(1.0, END).replace('}','').replace(' {','')
    textPad3fanyi.delete(0.0, 'end')
    textPad3fanyi.insert('end', now1)

    # https://www.jc2182.com/python/python-text-translation.html
    showinfo('notice','拼写错误的英语单词显示在 翻译区.')

Rogabet-note高级版2022830链接:https://pan.baidu.com/s/1E_8uJ5KuUY9dlH309MdaGw?pwd=0830

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rogabet-note

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值