在法语中使用textblob或spacy更正拼写

2024-09-28 22:29:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我想纠正法语文本中的拼写错误,看来spacy是最准确、最快捷的方法,但它很复杂, 我试过用textblob,但没能用法语单词

它在英语中非常好用,但是当我试图用法语做同样的事情时,我得到了同样的拼写错误的单词

#english words 
from textblob import TextBlob
misspelled=["hapenning", "mornin", "windoow", "jaket"]
[str(TextBlob(word).correct()) for word in misspelled]

#french words
misspelled2=["resaissir", "matinnée", "plonbier", "tecnicien"]
[str(TextBlob(word).correct()) for word in misspelled2]

我明白了:

英语: [“发生”,“早晨”,“窗户”,“夹克”]

法语: ['resassir'、'matinnée'、'plonbier'、'tecnicien']


Tags: infor单词wordwordsstr拼写错误textblob
1条回答
网友
1楼 · 发布于 2024-09-28 22:29:05

textblob仅支持英语。这就是为什么它返回法语单词的原样,没有任何更正。如果要将其用于法语,则需要安装textblob-fr。但根据其官方存储库heretextblob-fr不支持拼写检查。在

此外,spaCy的语言模型不支持拼写检查。有一个解决方案是使用spacy_hunspell包装hunspell(LibreOffice和Mozilla Firefox的拼写检查器),但它也不支持法语。在

所以,我的建议是使用pyspellchecker,它支持英语、法语、德语、西班牙语和葡萄牙语。。。它可以通过pip轻松安装,如下所示:

pip install pyspellchecker

英语

以下是如何在英语中使用它:

^{pr2}$

法语

这里是如何使用它与法语。。。它与英语中指定langauge=fr完全相同:

>>> from spellchecker import SpellChecker
>>>
>>> spell = SpellChecker(language='fr')
>>> misspelled = ["resaissir", "matinnée", "plonbier", "tecnicien"]
>>> misspelled = spell.unknown(misspelled)
>>> for word in misspelled:
...     print(word, spell.correction(word))
plonbier plombier
matinnée matinée
tecnicien technicien
resaissir ressaisir

相关问题 更多 >