Class StringSimilarity

java.lang.Object
dev.demeng.pluginbase.text.StringSimilarity

public class StringSimilarity extends Object
Utility class for calculating string similarity using various algorithms. Useful for implementing fuzzy matching, command suggestions, and typo correction.
  • Constructor Details

    • StringSimilarity

      public StringSimilarity()
  • Method Details

    • levenshteinDistance

      public static int levenshteinDistance(@NotNull @NotNull String s1, @NotNull @NotNull String s2)
      Calculates the Levenshtein distance between two strings. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
      Parameters:
      s1 - The first string
      s2 - The second string
      Returns:
      The Levenshtein distance between the two strings
    • similarity

      public static double similarity(@NotNull @NotNull String s1, @NotNull @NotNull String s2)
      Calculates the similarity percentage between two strings based on Levenshtein distance. Returns a value between 0.0 (completely different) and 1.0 (identical).
      Parameters:
      s1 - The first string
      s2 - The second string
      Returns:
      A similarity score between 0.0 and 1.0
    • isSimilar

      public static boolean isSimilar(@NotNull @NotNull String s1, @NotNull @NotNull String s2, double threshold)
      Checks if two strings are similar enough based on a threshold. Useful for determining if a string is "close enough" to another for fuzzy matching purposes.
      Parameters:
      s1 - The first string
      s2 - The second string
      threshold - The minimum similarity score (0.0 to 1.0) required to consider strings similar
      Returns:
      true if the similarity score is greater than or equal to the threshold