1 Star 3 Fork 2

Cetteest/pycorrector

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
en_correct_demo.py 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
xuming624 提交于 4年前 . update en spell correct.
# -*- coding: utf-8 -*-
"""
@author:XuMing(xuming624@qq.com)
@description:
"""
import sys
sys.path.append("..")
import pycorrector
if __name__ == '__main__':
# 1. 演示英文句子纠错
sent = "what happending? how to speling it, can you gorrect it?"
corrected_text, details = pycorrector.en_correct(sent)
print(sent, '=>', corrected_text)
print(details)
print()
# 2. 演示英文句子列表纠错
sent_lst = ['what hapenning?','how to speling it', 'gorrect', 'i know']
for sent in sent_lst:
corrected_text, details = pycorrector.en_correct(sent)
if details:
print('[error] ', sent, '=>', corrected_text, details)
print()
# 3. 演示自定义英文词典
from pycorrector.en_spell import EnSpell
sent = "what is your name? shylock?"
spell = EnSpell()
corrected_text, details = spell.correct(sent)
print(sent, '=>', corrected_text, details)
print('-' * 42)
my_dict = {'your': 120, 'name': 2, 'is': 1, 'shylock': 1, 'what': 1} # word, freq
spell = EnSpell(word_freq_dict=my_dict)
corrected_text, details = spell.correct(sent)
print(sent, '=>', corrected_text, details)
print()
# 4. 演示自定义纠错集
from pycorrector.en_spell import EnSpell
spell = EnSpell()
sent = "what happt ? who is shylock."
corrected_text, details = spell.correct(sent)
print(sent, '=>', corrected_text, details)
print('-' * 42)
spell.set_en_custom_confusion_dict('./my_custom_confusion.txt')
corrected_text, details = spell.correct(sent)
print(sent, '=>', corrected_text, details)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cette/pycorrector.git
git@gitee.com:cette/pycorrector.git
cette
pycorrector
pycorrector
master

搜索帮助