Example usage for org.apache.commons.text.similarity LevenshteinDistance LevenshteinDistance

List of usage examples for org.apache.commons.text.similarity LevenshteinDistance LevenshteinDistance

Introduction

In this page you can find the example usage for org.apache.commons.text.similarity LevenshteinDistance LevenshteinDistance.

Prototype

public LevenshteinDistance() 

Source Link

Document

This returns the default instance that uses a version of the algorithm that does not use a threshold parameter.

Usage

From source file:org.talend.utils.string.Levenshtein.java

public static double getLevenshteinScore(String inputStr, String outputColumnName) {
    double LevenshteinScore = 0.0;

    double maxLength = (inputStr.length() > outputColumnName.length()) ? inputStr.length()
            : outputColumnName.length();
    LevenshteinDistance ld = new LevenshteinDistance();
    double LevenshteinDistance = ld.apply(outputColumnName, inputStr);

    // one can overwrite to have his own version
    if (inputStr.contains(outputColumnName) || outputColumnName.contains(inputStr)) {
        LevenshteinScore = (maxLength - LevenshteinDistance + 1) / (maxLength + 1);
    } else {/*from   w w w  .  j ava2s  .c  om*/
        LevenshteinScore = 1 - (LevenshteinDistance / maxLength);
    }
    return LevenshteinScore;
}