创建用于拼写检查的德语单词组合
本文关键字:德语 单词 组合 检查 用于 创建 | 更新日期: 2023-09-27 18:05:38
我正在使用Symspell在c#中实现一个拼写检查器。它工作得很好,但我在一些包含尖锐的s (ß)和变音符的德语单词(ä,ö,ü)上遇到了一些问题。例如,当我检查一个带有变音符号的单词并为它写同义词时(ä-> ae),它找不到任何建议。(Äpfe ->你是说"Äpfel"吗?and Aepfel -> no words found)
也有包含多个这些字母的单词,所以我正在寻找一种方法来创建一个单词的所有组合,并对每个单词进行拼写检查。
。有人写"aeußerst":->检查aeuserst, ä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。
选项2:如果一个单词包含多个变音符,则不需要创建它的所有变音符组合。您只需要在字典生成和拼写更正期间始终将所有变音符ä/ö/ü/ß替换为它们的转录ae/oe/ue/ss :
CreateDictionaryEntry(key.Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss") , "")
Correct(word.ToLower().Replace("ä", "ae").Replace("ö", "oe").Replace("ü", "ue").Replace("ß", "ss") ,"");