net.ricecode.similarity.StringSimilarityService Java Examples

The following examples show how to use net.ricecode.similarity.StringSimilarityService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StringUtils.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the difference of two strings.
 *
 * @param first  First string
 * @param second Second string
 *
 * @return The difference value
 */
public static double getDifference(String first, String second) {
    // Make sure the strings are valid.
    if (first == null || second == null) {
        return 1.0;
    }

    // Create a string similarity service instance, to allow comparison
    StringSimilarityService service = new StringSimilarityServiceImpl(new LevenshteinDistanceStrategy());

    // Determine the difference value, return the result
    return Math.abs(service.score(first, second) - 1.0);
}