Hunspell (Python 3) 如何处理元音变音
Hunspell (Python 3) how to handle umlauts
我在 OS X 上使用 CyHunspell 和 Python 3.6 (IDLE) 检查单词是否拼写正确。它适用于大多数单词,但如果它有像 ä 这样的德语变音符号,则无效。所以我猜编码可能是个问题。我已经尝试过一些词典,例如来自 here is ISO8859-1. I tried this one for Sublime 的 LibreOffice 词典,它是 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":
beispiel/EPSozm
beispiel/hke
Beispiel/EPSmij
überall
Über/hij
über/Ske
知道我可以尝试解决这个问题吗?我在其他问题中找到了一些关于 UTF-8 和 Python 的信息,但它们通常是关于读取文件的。
我试过了,但是用的是不同的词典:
https://extensions.libreoffice.org/extensions/german-de-de-frami-dictionaries
它似乎工作正常。
虽然在 Ubuntu 16.04 上尝试了 Python 3.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
我在 OS X 上使用 CyHunspell 和 Python 3.6 (IDLE) 检查单词是否拼写正确。它适用于大多数单词,但如果它有像 ä 这样的德语变音符号,则无效。所以我猜编码可能是个问题。我已经尝试过一些词典,例如来自 here is ISO8859-1. I tried this one for Sublime 的 LibreOffice 词典,它是 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":
beispiel/EPSozm
beispiel/hke
Beispiel/EPSmij
überall
Über/hij
über/Ske
知道我可以尝试解决这个问题吗?我在其他问题中找到了一些关于 UTF-8 和 Python 的信息,但它们通常是关于读取文件的。
我试过了,但是用的是不同的词典: https://extensions.libreoffice.org/extensions/german-de-de-frami-dictionaries 它似乎工作正常。 虽然在 Ubuntu 16.04 上尝试了 Python 3.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