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

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

Introduction

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

Prototype

public static double getJaroWinklerDistance(final CharSequence first, final CharSequence second) 

Source Link

Document

Find the Jaro Winkler Distance which indicates the similarity score between two Strings.

The Jaro measure is the weighted sum of percentage of matched characters from each file and transposed characters.

Usage

From source file:kenh.expl.functions.GetJaroWinklerDistance.java

public double process(String str1, String str2) {
    try {/*  ww w. j a va2 s .  c  om*/
        return StringUtils.getJaroWinklerDistance(str1, str2);
    } catch (Exception e) {
        return 0.0;
    }
}

From source file:de.upb.wdqa.wdvd.features.sentence.CommentCommentSimilarity.java

@Override
public FeatureFloatValue calculate(Revision revision) {
    Float result = null;//from www  .j  a v a  2 s . c om

    String curComment = revision.getParsedComment().getSuffixComment();

    Revision prevRevision = revision.getPreviousRevision();
    if ((curComment != null) && (prevRevision != null)) {
        String prevComment = prevRevision.getParsedComment().getSuffixComment();

        if (prevComment != null) {
            curComment = curComment.trim();
            prevComment = prevComment.trim();
            result = (float) StringUtils.getJaroWinklerDistance(curComment, prevComment);
        }
    }

    return new FeatureFloatValue(result);
}

From source file:de.upb.wdqa.wdvd.features.sentence.CommentLabelSimilarity.java

@Override
public FeatureFloatValue calculate(Revision revision) {
    Float result = null;//  www .  ja v  a  2 s  .  c  o  m

    String suffixComment = revision.getParsedComment().getSuffixComment();

    if (suffixComment != null) {
        suffixComment = suffixComment.trim();

        ItemDocument itemDocument = revision.getItemDocument();

        if (itemDocument != null) {
            ItemDocumentDbItem item = new ItemDocumentDbItem(itemDocument);

            String label = item.getLabel();

            if (label != null) {
                label = label.trim();
                result = (float) StringUtils.getJaroWinklerDistance(suffixComment, label);
            }
        }
    }

    return new FeatureFloatValue(result);
}

From source file:br.pucminas.ri.jsearch.querylog.LogController.java

synchronized public List<Log> getAllLike(String query) {
    List<Log> all = getAll();
    ArrayList<Log> result = new ArrayList<>();

    all.stream().filter((l) -> (StringUtils.getJaroWinklerDistance(query, l.getQuery()) >= 0.80))
            .forEachOrdered((l) -> {/*from  www  .j a va 2s.c o m*/
                result.add(l);
            });

    return result;
}

From source file:me.rojo8399.placeholderapi.impl.utils.TypeUtils.java

/**
 * Case insensitive//  ww  w.  j  ava 2 s.c o  m
 */
public static boolean closeTo(String a, String b) {
    if (a == null && b == null) {
        return true;
    }
    if (a == null || b == null) {
        return false;
    }
    if (a.isEmpty() && b.isEmpty()) {
        return true;
    }
    if (a.isEmpty() || b.isEmpty()) {
        return false;
    }
    if (a.equalsIgnoreCase(b)) {
        return true;
    }
    a = a.toLowerCase();
    b = b.toLowerCase();
    if (StringUtils.getJaroWinklerDistance(a, b) > 0.7) {
        return true;
    }
    if (a.contains(b) && b.length() > 1) {
        return true;
    }
    return b.contains(a) && a.length() > 1;
}

From source file:de.upb.wdqa.wdvd.features.sentence.CommentSitelinkSimilarity.java

@Override
public FeatureFloatValue calculate(Revision revision) {
    Float result = null;/*from   w  w  w  .j av a  2s .  c  o  m*/

    String suffixComment = revision.getParsedComment().getSuffixComment();

    if (suffixComment != null) {

        ItemDocument itemDocument = revision.getItemDocument();

        String englishSitelink = getEnglishSitelink(itemDocument);

        if (englishSitelink != null) {
            englishSitelink = englishSitelink.trim();
            suffixComment = suffixComment.trim();

            result = (float) StringUtils.getJaroWinklerDistance(englishSitelink, suffixComment);
        }
    }

    return new FeatureFloatValue(result);
}

From source file:hudson.tasks.junit.GroupedCaseResults.java

public boolean similar(CaseResult cr, double minDist) {

    if (StringUtils.getJaroWinklerDistance(repErrorMessage, cr.getShortErrorMessage()) >= minDist) {
        return true;
    } else {//w  ww.j  a v a 2s  . co  m
        return false;
    }
}

From source file:hu.petabyte.redflags.engine.gear.indicator.helper.KMonitorInstitutions.java

public String findOrgName(String rfName) {
    if (null == rfName) {
        return null;
    }//  w w  w . java  2s.  c  om

    rfName = norm(rfName);
    String rfNameNoSuffix = CompanyNameUtils.removeSuffixes(rfName);
    String rfNamePattern = rfNameNoSuffix.replaceAll(" |$", "( \\\\w+)* ").trim();

    String foundKmName = null;
    double foundKmNameDist = 0.0;
    for (String kmName : institutions) {

        String originalKmName = kmName;
        kmName = norm(kmName);
        String kmNameNoSuffix = CompanyNameUtils.removeSuffixes(kmName);
        String kmNamePattern = kmNameNoSuffix.replaceAll(" |$", "( \\\\w+)* ").trim();
        if (CompanyNameUtils.matchSuffixesNorm(rfName, kmName)) {
            if (rfNameNoSuffix.matches(kmNamePattern) || kmNameNoSuffix.matches(rfNamePattern)) {

                double dist = StringUtils.getJaroWinklerDistance(kmName, rfName);
                if (dist > foundKmNameDist) {
                    foundKmNameDist = dist;
                    foundKmName = originalKmName;
                }
            }
        }
    }

    // nkormnyzatok javtsa
    if (null != foundKmName && rfName.startsWith("budapest fovaros ")) {
        String[] rfWords = rfName.split(" ");
        String[] fWords = norm(foundKmName).split(" ");
        int commonPrefixWords = 0;
        for (int i = 0; i < 3; i++) {
            if (i < rfWords.length && i < fWords.length && rfWords[i].equals(fWords[i])) {
                commonPrefixWords++;
            }
        }
        if (commonPrefixWords < 3) {
            foundKmName = null;
        }
    }

    return foundKmName;
}

From source file:com.moviejukebox.plugin.poster.MovieMeterPosterPlugin.java

@Override
public String getIdFromMovieInfo(String title, String year) {
    String id = UNKNOWN;/*from  w ww. j av  a  2  s . c om*/

    LOG.debug("Looking for MovieMeter ID for {} ({})", title, year);
    List<SearchResult> results;
    try {
        results = api.search(title);
    } catch (MovieMeterException ex) {
        LOG.warn("Failed to get Movie Meter search results for {} ({}): {}", title, year, ex.getMessage(), ex);
        return id;
    }

    if (results.isEmpty()) {
        return id;
    }

    int fYear = NumberUtils.toInt(year, 0);
    double maxMatch = 0.0;

    for (SearchResult sr : results) {
        // if we have a year, check that first
        if (fYear > 0 && sr.getYear() != fYear) {
            continue;
        }

        // Check for best text similarity
        double result = StringUtils.getJaroWinklerDistance(title, sr.getTitle());
        if (result > maxMatch) {
            LOG.trace("Better match found for {} ({}) = {} ({}) [{}]", title, year, sr.getTitle(), sr.getYear(),
                    maxMatch);
            maxMatch = result;
            // Update the best result
            id = Integer.toString(sr.getId());
        }
    }

    if (isValidString(id)) {
        LOG.debug("MovieMeter ID '{}' found for {} ({}), Match confidence: {}", id, title, year, maxMatch);
    }

    return id;
}

From source file:Applicant.java

public double Compare_Strings(String stringA, String stringB) {

    return StringUtils.getJaroWinklerDistance(stringA, stringB);
}