Class StringSimilarity


  • public class StringSimilarity
    extends Object
    Holds methods for computing the fuzzy string similarity between the query parameter and the available parameter of the given resource.
    • Method Detail

      • findSimilarParameters

        public static String findSimilarParameters​(String parameter,
                                                   List<String> possibleParameters)
        Computes a string similarity (Fuzzy Score algorithm) between the requested parameter and the possible parameters of the resource. It returns a String with a suggestion of possible parameters with a fuzzy score higher than 4. Comparisons with fuzzy score lower than 5 are not considered. If all comparisons give a fuzzy score lower than 5, it returns only a message of "unknown parameter" without suggestions.

        For example:

        • Given the false parameter "metadata" for the resource "groupByTag", it returns the suggestions "showMetadata" and "timeout", which are the only two matches with a score higher than 4.
        • Given the false parameter "groupByKe" for the resource "groupByKey", it returns the suggestion "groupByKeys", which is the only parameter with a matching score higher than 4 valid for this resource. Since the available parameter "groupByKey" is not valid for this resource, it will not be taken in consideration as suggestion parameter for this resource.
        • Given the false parameter "qwerty" for the resource "elementsFullHistory/geometry", since the matching score is lower than 5 in every match with the possible parameters, it returns only a message of "unknown parameter" without suggestions.

        Warning: Given typical mistyped parameters like "froupByKeys" or "fgroupByKeys" for the resource "groupByKey", it returns only a message of "unknown parameter" without suggestions despite the similarity to the right available parameter. This is because the Fuzzy Score algorithm matches the chars of the two strings from left to right.

        Parameters:
        parameter - - request parameter to compare
        possibleParameters - - list of possible parameters
        Returns:
        a String containing up to two suggested parameter if available.