创建用于拼写检查的德语单词组合

Create combinations of german words for spellchecking

我正在使用 Symspell 在 C# 中实现 SpellChecker。 它工作得很好,但我遇到了一些包含尖锐的 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:如果一个单词包含多个变音符号,则无需创建该单词的所有变音符号组合。您只需要在 字典生成 拼写更正:

CreateDictionaryEntry(key.Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss")  , "")

Correct(word.ToLower().Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss")  ,"");