Java Code Examples for info.debatty.java.stringsimilarity.NormalizedLevenshtein

The following examples show how to use info.debatty.java.stringsimilarity.NormalizedLevenshtein. These examples are extracted from open source projects. 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 Project: odyssey   Source File: StringCompareUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method to compare to strings using normalized levenshtein distance.
 * <p>
 * If the COMPARE_THRESHOLD is violated a simple contains check will be applied.
 *
 * @param expected The expected string.
 * @param actual   The actual string.
 * @return True if the comparison succeed otherwise false.
 */
public static boolean compareStrings(final String expected, final String actual) {
    final NormalizedLevenshtein comparator = new NormalizedLevenshtein();

    double distance = comparator.distance(expected, actual);

    if (distance < COMPARE_THRESHOLD) {
        return true;
    } else {
        return actual.toLowerCase().contains(expected.toLowerCase()) || expected.toLowerCase().contains(actual.toLowerCase());
    }
}
 
Example 2
Source Project: VileBot   Source File: Trivia.java    License: MIT License 5 votes vote down vote up
private boolean isCorrect( String answer )
{
    String formattedUserAnswer = formatAnswer( answer );
    String formattedActualAnswer = formatAnswer( this.answer );
    double distance = new NormalizedLevenshtein().distance( formattedActualAnswer, formattedUserAnswer );
    return distance < 0.5;
}
 
Example 3
Source Project: scava   Source File: StringSimilarity.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public IBool codeIsSimilar(IString snippet1, IString snippet2, IReal threshold, IEvaluatorContext eval) {
	NormalizedLevenshtein levenshtein = new NormalizedLevenshtein();
	double distance = levenshtein.distance(snippet1.getValue(), snippet2.getValue());
	return factory.bool(distance <= (1 - threshold.doubleValue()));
}
 
Example 4
Source Project: scava   Source File: StringSimilarity.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public IReal levenshteinSimilarity(IString snippet1, IString snippet2, IEvaluatorContext eval) {
	NormalizedLevenshtein levenshtein = new NormalizedLevenshtein();
	double distance = levenshtein.distance(snippet1.getValue(), snippet2.getValue());
	return factory.real(1 - distance);
}