SoundX Application In C#
using System;
using System.Collections;
namespace Com
{
/// <summary>
///Description for GSoundX.
///SoundX classifies words for how they sound by asssigning a short numeric
///code based on a group of letters.
///Take the first letter.
///Then, for each of the subsequent letters, score a code for the group it
///belongs to. There are 6 groups :
///Group Letters
///1 BFPV
///2 CGJKQSXZ
///3 DT
///4 L
///5 MN
///6 R
///Ignore all other letters and characters (vowels, h, punctuation, etc.)
//////If a code has already occurred, ignore it. Continue until you have 4 characters,
///if there are less, add zeroes until you have 4.
///And they all sound the same or similar.
/// </summary>
public class SoundX
{
static ArrayList aList1 = new ArrayList(4);
static ArrayList aList2 = new ArrayList(8);
static ArrayList aList3 = new ArrayList(2) ;
static ArrayList aList4 = new ArrayList(1);
static ArrayList aList5 = new ArrayList(2);
static ArrayList aList6 = new ArrayList(1);
static ArrayList aListExcep = new ArrayList(6);
private static void setArrayLists()
{
aListExcep.Add("A");
aListExcep.Add("E");
aListExcep.Add("I");
aListExcep.Add("O");
aListExcep.Add("U");
aListExcep.Add("H");
aList1.Add("B");
aList1.Add("F");
aList1.Add("P");
aList1.Add("V");
aList2.Add("C");
aList2.Add("G");
aList2.Add("J");
aList2.Add("K");
aList2.Add("Q");
aList2.Add("S");
aList2.Add("X");
aList2.Add("Z");
aList3.Add("D");
aList3.Add("T");
aList4.Add("L");
aList5.Add("M");
aList5.Add("N");
aList6.Add("R");
}
/// <summary>
/// This method does the core functionality of
/// geting the soundx code for the giving string
/// </summary>
///
| <param name="strInput" />The string value for which SoundX equivalent is needed. /// <returns>SoundX output string.</returns> public static String getSoundEX(String strInput) { setArrayLists(); String strReturn = ""; try { String strTemp = strInput.Substring(0,1).ToUpper(); if(strInput.Length > 0) { int iStrLen = 0; if(strInput.Length >= 4) { iStrLen = 4; } else { iStrLen = strInput.Length; } char[] chrEachChar = strInput.ToCharArray(0,iStrLen); ArrayList aListTemp = new ArrayList(iStrLen); foreach(char chr in chrEachChar) { String strTempChar = chr.ToString().ToUpper(); bool blnGoOn = true; //check if the character has been already counted if(aListTemp.Count > 0) { if(aListTemp.IndexOf(strTempChar) >= 0) { blnGoOn = false; } } else { //do not go in for the first character blnGoOn = false; } //add the char to the array so that //the consequetive entries are checked for. aListTemp.Add(strTempChar); if(blnGoOn == true) { if(aListExcep.IndexOf(strTempChar) < 0 ) //if the char is not a vowel or H { if(aList1.IndexOf(strTempChar)< 0) { if(aList2.IndexOf(strTempChar)< 0) { if(aList3.IndexOf(strTempChar)< 0) { if(aList4.IndexOf(strTempChar) < 0) { if(aList5.IndexOf(strTempChar) < 0) { if(aList6.IndexOf(strTempChar) >= 0) { strTemp = strTemp + "6"; } } else //array5 { strTemp = strTemp + "5"; } } else //array4 { strTemp = strTemp + "4"; } } else //array3 { strTemp = strTemp + "3"; } } else //array2 { strTemp = strTemp + "2"; } } else //array1 { strTemp = strTemp + "1"; } }//if the char is a vowel or H }//if the char has already been taken into account }//end for each if(strTemp.Length < 5) { int iLen = strTemp.Length; if(iLen == 1) { strTemp = strTemp + "0000"; } else if(iLen == 2) { strTemp = strTemp + "000"; } else if(iLen == 3) { strTemp = strTemp + "00"; } else if(iLen == 4) { strTemp = strTemp + "0"; } } strReturn = strTemp.Trim(); } else { strReturn = ""; } } catch(Exception exp) { strReturn = "ERR:" + exp.ToString(); } return(strReturn); } }} |












No comments yet... Be the first to leave a reply!