Hunspell(Python3)如何处理元音变音

2024-04-29 18:38:15 发布

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

我在OSX上使用CyHunspell和python3.6(IDLE)来检查单词的拼写是否正确。它适用于大多数单词,但如果它有德语变音词,比如ä就不行了。所以我想编码可能是个问题。我已经试过一些字典了,因为来自here的LibreOffice是ISO8859-1。我试过this one for Sublime这是UTF-8,但它也不起作用。我还将LibreOffice文件转换为ISO8859-1,但仍然是相同的行为。在

我的代码:

import os
from hunspell import Hunspell
hunspell_path = os.path.dirname(os.path.abspath(__file__)) + "/dictionaries"
h = Hunspell("de_DE_utf8", hunspell_data_dir=hunspell_path)
print(h.spell("Beispiel")) # TRUE - should be TRUE
print(h.spell("überall")) # FALSE - should be TRUE
print(h.spell("über")) # TRUE - should be TRUE

我不明白“über”是真的。在

这三个词都在“de_de_utf8.dic”中:

^{pr2}$

你知道我能怎么解决这个问题吗?我在其他问题中发现了一些关于UTF-8和Python的信息,但它们通常是关于读取文件的。在


Tags: 文件pathimporttruelibreofficeosdebe
1条回答
网友
1楼 · 发布于 2024-04-29 18:38:15

我试过了,但用的是另一本字典: https://extensions.libreoffice.org/extensions/german-de-de-frami-dictionaries 在那里工作得很好。 不过,在Ubuntu16.04上尝试了Python3.5。在

import os
from hunspell import Hunspell

dict_path = .....
h = Hunspell("de_DE_frami", hunspell_data_dir=dict_path)
print(h.spell("Beispiel"))
print(h.spell("über"))
print(h.spell("überall"))
print(h.spell("Über"))
True
True
True
True

相关问题 更多 >