I wrote a method that helps to match names that represent the same person but are written in different ways (full name or short version), for example:
Paul Samuelson-Smith
and Paul Smith
would be considered equal based on my method:
private static boolean equalName(String name_2, String name_1){
boolean equality1 = true;
name_1 = name_1.replace("&", " ").replace("-", " ");
String [] names1 = name_1.split(" ");
for (int i = 0; i < names1.length ; i ++) {
if (!name_2.contains(names1[i])) {equality1 = false; break;}
}
boolean equality2 = true;
name_2 = name_2.replace("&", " ").replace("-", " ");
String [] names2 = name_2.split(" ");
for (int i = 0; i < names2.length ; i ++) {
if (!name_1.contains(names2[i])) {equality2 = false; break;}
}
return equality1 || equality2;
}
However I still have a problem with what if there is a typo in a name, say Paul Samuelson-Smith
and Paull Smith
are the same person. My question is is there any API that would help account for possible typos? How can I improve my method?