我在 C# 中使用 Symspell 实现拼写检查器. 它工作得很好,但我遇到了一些包含尖锐的 s (ß) 和变音符号 (ä,ö,ü) 的德语单词的问题。 例如,当我检查一个带有元音变音的单词并写下它的同义词(ä-> ae)时,它没有找到任何建议。 (Äpfe -> 您是说“Äpfel”吗?Aepfel -> 未找到任何字词)
还有一些单词包含不止一个这样的字母,所以我正在寻找一种方法来创建一个单词的所有组合并对每个组合进行拼写检查。
例如有人写“aeußerst”: -> 检查 aeusserst、äusserst 和 äußerst
我的方法非常幼稚,效果不佳。
public static List<string> GetCorrectWords(string word2check)
{
var suggestedWordsList = SymSpell.Correct(word2check, "")
if (suggestedWordsList.Count == 0) // If no suggestions could be found...
{
if (word2check.Contains("ä")) // ...check for mistakes with ä and ae
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ä", "ae"), "");
}
else if (word2check.Contains("ae"))
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ae", "ä"), ""); }
if (word2check.Contains("ö")) // ... check for mistakes with ö and oe
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ö", "oe"), "");
}
else if (word2check.Contains("oe"))
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("oe", "ö"), "");
}
if (word2check.Contains("ü"))
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ü", "ue"), "");
}
else if (word2check.Contains("ue"))
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ue", "ü"), "");
}
if(word2check.Contains("ß")) // ...check for mistakes with ß and ss
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ß", "ss"), "");
}
else if (word2check.Contains("ss"))
{
suggestedWordsList = SymSpell.Correct(word2check.Replace("ss", "ß"), "");
}
}
return suggestedWordsList;
}
最佳答案
你说:
Aepfel -> no words found
鉴于“Äpfel”在字典中(或在创建字典的语料库中)只有当您设置了 editDistanceMax=1 时才会出现这种情况。
选项 1:在 SymSpell 中,您应该设置 editDistanceMax>=2(最大编辑距离)。然后“Aepfel”将显示建议“Äpfel”,因为这两个术语之间的Damerau-Levenshtein 编辑距离是二。
选项 2:如果单词包含多个变音符号,则无需创建单词的所有变音符号组合。您只需要在词典生成和拼写更正<期间始终将所有变音符号 ä/ö/ü/ß 替换为它们的转录 ae/oe/ue/ss 两者/strong>:
CreateDictionaryEntry(key.Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss") , "")
Correct(word.ToLower().Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss") ,"");
关于c# - 创建用于拼写检查的德语单词组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39331756/