# Blogs

Normally when we have to match or compare strings, we give so much focus on spelling for exact match. Today's world of Artifical Intelligence and Machine Learning, comparing with spelling only can miss out so much information that we cannot imagine.
Very often, people misspells and due to the reason we may not get required output.
Phonetic/Soundex algorithms can become very useful in comparing and matching words by their pronunciation instead of spelling check. In the beginning phonetic/soundex algorithms were implemented in order to analyse US census data.
Phonetic algorithms and few other algorithms have been playing important role in spelling correction, database record mapping and search recommendations( we can see when we misspell in the google search box and corrects and recommends).
I have written simple Phonetic/Soundex Algorithm in Java Programming language for your reference.
```    ```
/**
* Phonetic/Soundex Algorithm for AI & Machine Learning
* Creators Institute of Business & Technology
* Lalitpur, Nepal
*/
public class App{

public static String soundex(String text){
int length=text.length();
String output=""+text.charAt(0);
String number="";
for(int i=0;i<length;i++){
char c=text.charAt(i);
if(c!='a' && c!='e' && c!='i'
&& c!='o' && c!='u' && c!='y' && c!='h'
&& c!='w'){
if(c=='b' || c=='f' || c=='p' || c=='v'){
number +=1;
}else if(c=='c' || c=='g' || c=='j' || c=='k'
|| c=='q' || c=='s' || c=='x' || c=='z'){
number +=2;
}else if(c=='d' || c=='t'){
number +=3;
}else if(c=='l'){
number +=4;
}else if(c=='m' || c=='n'){
number +=5;
}else if(c=='r'){
number +=6;
}else{
number +=0;
}
}
}
for(int i=1;i<number.length();i++){
if (number.charAt(i) != number.charAt(i-1)
&& number.charAt(i) != '0')
output +=number.charAt(i);
}
return (output+"0000").substring(0,4);
}
public static void main(String[] args){
String text="java";

System.out.println(soundex("java"));
System.out.println(soundex("jabha"));
System.out.println(soundex("jaba"));
System.out.println(soundex("jeba"));

}
}
```
```
Output
j100
j100
j100
j100
happy Coding !!!