我想纠正法语文本中拼写错误的单词,似乎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]
我明白了:
中文:‘发生’,‘早晨’,‘窗口’,‘夹克’
法语:“resaissir”、“matinnée”、“plonbier”、“tecnicien”
发布于 2019-11-08 04:28:23
textblob
仅支持英语。这就是为什么它返回法语单词,因为它们没有任何更正。如果你想在法语中使用它,那么你需要安装textblob-fr
。但根据其官方存储库here,textblob-fr
不支持拼写检查。
此外,spaCy不支持对其语言模型进行拼写检查。有一个解决方法是使用包装hunspell
( LibreOffice和Mozilla Firefox的拼写检查器)的spacy_hunspell
,但它也不支持法语。
所以,我的建议是使用支持英语、法语、德语、西班牙语和葡萄牙语的pyspellchecker
……它可以很容易地通过pip
安装,如下所示:
pip install pyspellchecker
英语
以下是如何在英语中使用它:
>>> from spellchecker import SpellChecker
>>>
>>> spell = SpellChecker()
>>> misspelled = ["hapenning", "mornin", "windoow", "jaket"]
>>> misspelled = spell.unknown(misspelled)
>>> for word in misspelled:
... print(word, spell.correction(word))
jaket jacket
windoow window
mornin morning
hapenning happening
法语
下面是如何在法语中使用它。它与指定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
https://stackoverflow.com/questions/58694762
复制相似问题