info.debatty.java.stringsimilarity.NormalizedLevenshtein Java Examples

The following examples show how to use info.debatty.java.stringsimilarity.NormalizedLevenshtein. 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: StringCompareUtils.java    From odyssey with 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 File: Trivia.java    From VileBot with 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 File: StringSimilarity.java    From scava with 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 File: StringSimilarity.java    From scava with 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);
}