List of usage examples for org.apache.commons.codec.language Metaphone isMetaphoneEqual
public boolean isMetaphoneEqual(String str1, String str2)
From source file:org.eobjects.datacleaner.phonetic.PhoneticSimilarityFinder.java
public boolean matches(String value, SimilarityGroup similarityGroup) { // first do exact matching for (String similarityGroupValue : similarityGroup.getValues()) { if (value.equals(similarityGroupValue)) { return true; }/*w ww . j a va 2 s. co m*/ } Soundex soundex = new Soundex(); RefinedSoundex refinedSoundex = new RefinedSoundex(); Metaphone metaphone = new Metaphone(); double threshold; if (matchMode == MatchMode.STRICT) { threshold = STRICT_SIMILARITY_THRESHOLD; } else { threshold = LOOSE_SIMILARITY_THRESHOLD; } int soundexThreshold = (int) Math.round(threshold * 4); for (String similarityGroupValue : similarityGroup.getValues()) { boolean metaphoneEquals = metaphone.isMetaphoneEqual(value, similarityGroupValue); if (metaphoneEquals) { return true; } try { int soundexDiff = soundex.difference(value, similarityGroupValue); if (soundexDiff >= soundexThreshold) { return true; } } catch (Exception e) { logger.error("Could not determine soundex difference", e); } int refinedSoundexThreshold = (int) Math .round(threshold * Math.min(value.length(), similarityGroupValue.length())); try { int refinedSoundexDiff = refinedSoundex.difference(value, similarityGroupValue); if (refinedSoundexDiff >= refinedSoundexThreshold) { return true; } } catch (Exception e) { logger.error("Could not determine refined soundex difference", e); } } return false; }