Example usage for org.apache.commons.codec.language Metaphone isMetaphoneEqual

List of usage examples for org.apache.commons.codec.language Metaphone isMetaphoneEqual

Introduction

In this page you can find the example usage for org.apache.commons.codec.language Metaphone isMetaphoneEqual.

Prototype

public boolean isMetaphoneEqual(String str1, String str2) 

Source Link

Document

Tests is the metaphones of two strings are identical.

Usage

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;
}