葡萄牙语拼法显示拼写正确的单词拼写错误

2024-04-29 22:36:37 发布

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

我正在使用最新版本的spacy_hunspell和葡萄牙语dictionaries。而且,我意识到,当我有包含特殊字符的屈折动词时,例如锐音符(`)和颚化符(~),拼写检查器无法检索正确的验证:

import hunspell

spellchecker = hunspell.HunSpell('/usr/share/hunspell/pt_PT.dic',
                                 '/usr/share/hunspell/pt_PT.aff')

#Verb: fazer
spellchecker.spell('fazer') # True, correct
spellchecker.spell('faremos') # True, correct
spellchecker.spell('fará') # False, incorrect
spellchecker.spell('fara') # True, incorrect
spellchecker.spell('farão') # False, incorrect

#Verb: andar
spellchecker.spell('andar') # True, correct
spellchecker.spell('andamos') # True, correct
spellchecker.spell('andará') # False, incorrect
spellchecker.spell('andara') # True, correct

#Verb: ouvir
spellchecker.spell('ouvir') # True, correct
spellchecker.spell('ouço') # False, incorrect

另一个问题是当动词不规则时,比如ir

spellchecker.spell('vamos') # False, incorrect
spellchecker.spell('vai') # False, incorrect
spellchecker.spell('iremos') # True, correct
spellchecker.spell('irá') # False, incorrect

据注意,这个问题并不发生在具有特殊字符的名词上:

spellchecker.spell('coração') # True, correct
spellchecker.spell('órgão') # True, correct
spellchecker.spell('óbvio') # True, correct
spellchecker.spell('pivô') # True, correct

有什么建议吗?你知道吗


Tags: ptfalsetrueshareusr动词verbhunspell
2条回答

这个问题是关于hunspell而不是spacy或spacy\u hunspell。你知道吗

我认为这是一个编码问题,尽管在您的所有测试用例中可能都不是这样。我不确定您是如何找到这些葡萄牙语词典的,但它们不在UTF-8中,也不是当前/标准的hunspell pt\u pt库,这些库来自LibreOffice:

https://github.com/LibreOffice/dictionaries/tree/master/pt_PT

这些是debian/ubuntu安装的葡萄牙语词典,如果您安装包hunspell-pt-pt(例如,使用apt-get install hunspell-pt-pt),它们在上面的测试用例中具有正确的行为,无论是命令行上的hunspell还是上面代码中的pyhunspell。你知道吗

为了阐明一些重要的观点:拼写检查与引理化一起,通常使用一组预定义规则(是的,没有机器学习,也没有广泛的注释词库)。然而,正如你所注意到的,这些规则中的一些并不适用于不规则动词和弯曲。你知道吗

事实证明,与其他语言相比,Spacy模型和规则(事实上不仅是Spacy,还有用于葡萄牙语的任何工具)非常薄弱。你知道吗

总之:你得到的结果不是错误的,而是因为spacy(和hunspell)提供的模型是错误的。你知道吗

作为一个开源项目,您可以尝试自己增强它。如果这不是一个选项,您可以尝试其他一些工具,例如dicio(这是基于同义词库的,但是速度非常慢,因为您必须将其与Ajax集成,这需要对每个单词都进行请求!)你知道吗

欢迎来到葡萄牙语NLP!你知道吗

相关问题 更多 >