Example usage for org.apache.commons.lang3 StringUtils getFuzzyDistance

List of usage examples for org.apache.commons.lang3 StringUtils getFuzzyDistance

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils getFuzzyDistance.

Prototype

public static int getFuzzyDistance(final CharSequence term, final CharSequence query, final Locale locale) 

Source Link

Document

Find the Fuzzy Distance which indicates the similarity score between two Strings.

This string matching algorithm is similar to the algorithms of editors such as Sublime Text, TextMate, Atom and others.

Usage

From source file:it.tidalwave.bluemarine2.metadata.impl.audio.musicbrainz.MusicBrainzAudioMedatataImporter.java

/*******************************************************************************************************************
 *
 *
 *
 *
 ******************************************************************************************************************/
public static int similarity(final @Nonnull String a, final @Nonnull String b) {
    int score = StringUtils.getFuzzyDistance(a.toLowerCase(), b.toLowerCase(), Locale.UK);
    ////from ww  w.  j  a  v  a  2s .  com
    // While this is a hack, it isn't so ugly as it might appear. The idea is to give a lower score to
    // collections and records with a generic title, hoping that a better one is picked.
    // FIXME: put into a map and then into an external resource with the delta score associated.
    // FIXME: with the filtering on collection size, this might be useless?
    //
    if (a.matches("^Great Violin Concertos.*") || a.matches("^CBS Great Performances.*")) {
        score -= 50;
    }

    if (a.matches("^Piano Concertos$") || a.matches("^Klavierkonzerte$")) {
        score -= 30;
    }

    return score;
}

From source file:net.stargraph.rank.impl.FuzzyRanker.java

@Override
double computeStringDistance(CharSequence s1, CharSequence s2) {
    return StringUtils.getFuzzyDistance(s1, s2, Locale.getDefault());
}