简介:pycorrector是一个开源的中文文本纠错工具。支持中文音似、形似、语法错误纠正,python3开发。pycorrector实现了Kenlm、ConvSeq2Seq、BERT、MacBERT、ELECTRA、ERNIE、Transformer等多种模型的文本纠错,并在SigHAN数据集评估各模型的效果。

项目开源地址:

https://github.com/shibing624/pycorrector

安装:

pip install -U pycorrector

案例1:文本纠错

# -*- coding: utf-8 -*-# time: 2023/02/18 11:26# file: demo1.py# 公众号: 伤心的辣条import pycorrectormessage = "机七学习是人工智能领遇最能体现智能的一个分知"corrected_sent, detail = pycorrector.message(mes)print(corrected_sent, detail)

运行结果:

(base) [root@ci4vyvxi572ysx2s write]# python demo1.py 2023-02-18 11:53:18.515 | DEBUG| pycorrector.detector:_initialize_detector:89 - Loaded language model: /root/.pycorrector/datasets/zh_giga.no_cna_cmn.prune01244.klm机器学习是人工智能领域最能体现智能的一个分知 [('机七', '机器', 0, 2), ('领遇', '领域', 9, 11)]

案例2:成语、专名纠错

# -*- coding: utf-8 -*-# time: 2023/02/18 11:26# file: demo2.py# 公众号: 伤心的辣条import syssys.path.append("..")from pycorrector.proper_corrector import ProperCorrectorm = ProperCorrector()x = ['报应接中迩来','今天在拼哆哆上买了点苹果',]for i in x:print(i, ' -> ', m.proper_correct(i))

运行结果:

(base) [root@ci4vyvxi572ysx2s write]# python demo2.py 报应接中迩来->('报应接踵而来', [('接中迩来', '接踵而来', 2, 6)])今天在拼哆哆上买了点苹果->('今天在拼多多上买了点苹果', [('拼哆哆', '拼多多', 3, 6)])

案例3:英文拼写纠错

# -*- coding: utf-8 -*-# time: 2023/02/18 11:26# file: demo3.py# 公众号: 伤心的辣条import pycorrectorsent = "what happending? how to speling it, can you gorrect it?"corrected_text, details = pycorrector.en_correct(sent)print(sent, '=>', corrected_text)print(details)

运行结果:

(base) [root@ci4vyvxi572ysx2s write]# python demo3.py 2023-02-18 11:59:02.620 | DEBUG| pycorrector.en_spell:_init:39 - load en spell data: /root/miniconda3/lib/python3.9/site-packages/pycorrector/data/en/en.json.gz, size: 30120what happending? how to speling it, can you gorrect it? => what happening? how to spelling it, can you correct it?[('happending', 'happening', 5, 15), ('speling', 'spelling', 24, 31), ('gorrect', 'correct', 44, 51)]

更多使用技巧详见官方文档。

最后:下方这份完整的软件测试视频学习教程已经整理上传完成,朋友们如果需要可以自行免费领取【保证100%免费】

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!