Java Code Examples for org.apache.commons.lang3.StringUtils.getLevenshteinDistance()

The following are Jave code examples for showing how to use getLevenshteinDistance() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alexa-skill   File: NewEventSpeechlet.java   View Source Code Vote up 6 votes
private String findCalendarName(final String calendarName) {
  final String nCalendarName = calendarName.toLowerCase();
  Map<String, Integer> distances = new HashMap<>();

  for(String curCalendarName : getCalendarNames()) {
    String nCurCalendarName = curCalendarName.toLowerCase();
    int distance = StringUtils.getLevenshteinDistance(nCalendarName, nCurCalendarName);

    if(distance <= 3 || nCurCalendarName.contains(nCalendarName)) {
      distances.put(curCalendarName, distance);
    }
  }

  if(distances.size() == 1) {
    return distances.keySet().stream().findFirst().get();
  }

  return null;
}
 
Example 2
Project: Airachnid-Burp-Extension   File: RequestSender.java   View Source Code Vote up 5 votes
/**
     * Testing if the responses of two requests are similar. This is the not the same as the same, rather there is a
     * threshold set in the static parameters of the class.
     * @param firstString
     * @param secondString
     * @return Test if similar
     */
    private static boolean testSimilar(String firstString, String secondString) {
//        int fuzzyDist = StringUtils.getFuzzyDistance(firstString, secondString, Locale.getDefault());
        double jaroDist = StringUtils.getJaroWinklerDistance(firstString, secondString);
        int levenDist = StringUtils.getLevenshteinDistance(firstString, secondString);

//        BurpExtender.print("============================================");
//        BurpExtender.print("Fuzzy Distance:" + fuzzyDist);
//        BurpExtender.print("        Jaro Winkler Distance:" + jaroDist);
//        BurpExtender.print("        Levenshtein Distance:" + levenDist);
//        BurpExtender.print("============================================");

        return jaroDist >= JARO_THRESHOLD || levenDist <= LEVENSHTEIN_THRESHOLD;
    }
 
Example 3
Project: hive-udf-backports   File: GenericUDFLevenshtein.java   View Source Code Vote up 5 votes
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
  String str0 = getStringValue(arguments, 0, converters);
  String str1 = getStringValue(arguments, 1, converters);

  if (str0 == null || str1 == null) {
    return null;
  }

  int dist = StringUtils.getLevenshteinDistance(str0, str1);
  output.set(dist);
  return output;
}
 
Example 4
Project: Stargraph   File: LevenshteinRanker.java   View Source Code Vote up 4 votes
@Override
double computeStringDistance(CharSequence s1, CharSequence s2) {
    return StringUtils.getLevenshteinDistance(s1, s2);
}
 
Example 5
Project: bibliometrics   File: Article.java   View Source Code Vote up 4 votes
private int levenshteinDistance(String s1, String s2) {
    return StringUtils.getLevenshteinDistance(s1, s2);
}