ASP.NET
Topic: Phonetic entry in forms

Ireland .NET Developer Alliance :: Forums

Page 1 of 1 (11 items)

Posted by Paschal on

I want the users be able to enter any name in a textbox and the system searching phonetically.

For example a school name like St Patrick and if a user type St PatrOck or St Patric the system should be able to propose a choice.

I have to do that because schools name in Ireland are quite amazing like:MUIRE AN TSOLAIS NAOIDH or SCOIL AN CHLOCHAIR CILL BHEAGAN.

I heard about Soundex, but do you know any developement for ASP.Net ?


Posted by Marcus on 11-16-2004 12:35
I have a SoundEx implementaion in C# somewhere, let me know if you want me to dig it up. Marcus

Posted by Paschal on 11-16-2004 12:50
Yes Marcus I would appreciate that ! I have to implement this very soon.

Thanks

Posted by Marcus on

public class Soundex

{

 

       private Soundex()

       {

       }

 

       public static String SoundexCodeConverter(String s_String)

       {

              String s_word = s_String.ToUpper();

              StringBuilder s_soundexCode = new StringBuilder();

              int i_wordLength = s_word.Length;

 

              s_soundexCode.Append(s_word.Substring(0,1));

 

              for ( int i=1; i

              {

                     String s_transformedChar = Transform(s_word.Substring(i,1));

 

               

                     if (!s_transformedChar.Equals( s_soundexCode.ToString().Substring(s_soundexCode.Length - 1) ))

                     {

 

                   

                           if (!s_transformedChar.Equals("A") && !s_transformedChar.Equals("S"))

                           {

 

                                  if (!s_transformedChar.Equals(" "))

                                  {

                                          s_soundexCode.Append(s_transformedChar);

                                  }

                           }  

                     }

              }

 

              s_soundexCode.Append("0000");

 

              return s_soundexCode.ToString().Substring(0,4);

       }

}

 

 

private static String Transform(String s_String)

{

 

       switch (s_String)

       {

              case "A":

              case "E":

              case "I":

              case "O":

              case "U":

              case "Y":

                     return "A";

              case "H":

              case "W":

                     return "S";

              case "B":

              case "F":

              case "P":

              case "V":

                     return "1";

              case "C":

              case "G":

              case "J":

              case "K":

              case "Q":

              case "S":

              case "X":

              case "Z":

                     return "2";

              case "D":

              case "T":

                     return "3";

              case "L":

                     return "4";

              case "M":

              case "N":

                     return "5";

              case "R":

                     return "6";

       }

 

       return " ";  

}


Posted by Paschal on 11-16-2004 10:33
That's all [:D] I was expecting a huge algorithm
Thanks

Posted by cperrone on
If you are using SQL Server for your searces you may consider the SOUNDEX function in TSQL.
You can also use the DIFFERENCE function to check how much similar 2 terms sound based on their phonetic codes.
I've used the TSQL implementation in the past and to be honest it is far from perfect.
However, I have a more sofisticated version available if you still need a sql server implementation.
Otherwise, if you want to see 4 different C# implementations you could link to http://www.codeproject.com/csharp/soundex.asp


Posted by Paschal on
Can you give here your version Claudio ?

Posted by cperrone on
Ummmm, I just realized I can't really post the code here because it is copyrighted. It comes straight from Ken Henderson's " The Guru's Guide to Transact-SQL "
If you haven't got this book I'd highly recommend it - it's excellent.

Posted by Marcus on
Yes... Excellent book, I've got it too.

Posted by Paschal on 11-16-2004 11:40
Incredible I got it too and I missed this one :-)

Thanks

Posted by Brian Delahunty on
Looks like you've got the solution to this one already P, but just incase, it might be worth looking at fuzzy logic.. would be perfect for a phonetic matches. Some very good C# articles on fuzzy logic on the CodeProject