我有全名列表,并尝试比较/搜索匹配的拼音全名;我Double metaphone
在我的 C# 中使用
说我的清单是这样的;
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