我有全名的名单,并试图比较/搜索匹配语音相似的全名;我在c#
中使用Double metaphone
说我的清单是这样的;
Abdul Hameed Khan
Shadab Akbar
Nawab Zameer Ahmed Baloch
Richard Hyden
Abdullah Habib
Abu Saleh Muhammad
Ravi Kumar
Ameet Kumar Rathore
Amit Shah
当我尝试搜索Double Metaphone
时,它将仅搜索初始单词(名称)。
如果我写 Hameed ,如何进行此搜索,这应该返回Abdul Hameed Khan。目前只返回名字。 还有一件事,如何在这个算法中比较阿拉伯语或乌尔都语名称。
这里是外码工作;
Hashtable wordsMap = new Hashtable();
FileStream wordsFile = File.OpenRead("..\\..\\..\\names.txt");
StreamReader reader = new StreamReader(wordsFile);
String word = reader.ReadLine();
while (word != null)
{
DoubleMetaphone mp = new DoubleMetaphone(word);
//Associate word with primary key
ArrayList words = (ArrayList)wordsMap[mp.PrimaryKey];
if (words == null)
{
words = new ArrayList();
wordsMap[mp.PrimaryKey] = words;
}
words.Add(word);
//Associate with with alternate key also
if (mp.AlternateKey != null)
{
words = (ArrayList)wordsMap[mp.AlternateKey];
if (words == null)
{
words = new ArrayList();
wordsMap[mp.AlternateKey] = words;
}
words.Add(word);
}
//Read the next word
word = reader.ReadLine();
}
//Begin prompting for search words
while (true)
{
System.Console.Write("\nEnter search term (q to quit): ");
String searchWord = System.Console.ReadLine().Trim();
if (searchWord.Length == 0 || searchWord == "q")
{
break;
}
DoubleMetaphone searchMphone = new DoubleMetaphone(searchWord);
//Search for matches to the primary key
ArrayList matches = (ArrayList)wordsMap[searchMphone.PrimaryKey];
if (matches != null)
{
foreach (String matchingWord in matches)
{
System.Console.WriteLine("\tFound: {0}", matchingWord);
}
}
//Search for matches to the alt, if present
if (searchMphone.AlternateKey != null)
{
matches = (ArrayList)wordsMap[searchMphone.AlternateKey];
if (matches != null)
{
foreach (String matchingWord in matches)
{
System.Console.WriteLine("\tFound: {0}", matchingWord);
}
}
}
}
此源代码作为参考使用:https://www.codeproject.com/Articles/4624/Implement-Phonetic-Sounds-like-Name-Searches-wit