Class NormalizedLevenshteinAlgorithm

java.lang.Object
tk.airshipcraft.commonlib.utils.search.NormalizedLevenshteinAlgorithm
All Implemented Interfaces:
StringDistance

public final class NormalizedLevenshteinAlgorithm extends Object implements StringDistance
Implements the normalized Levenshtein distance algorithm, which calculates a similarity score based on the minimum number of single-character edits required to change one byte array into the other. The normalization is performed by dividing the Levenshtein distance by the length of the longest array, producing a score between 0 and 1, where 0 indicates identical arrays and 1 indicates maximum dissimilarity.
Since:
2023-06-23
Version:
1.0.0
Author:
notzune
  • Constructor Details

    • NormalizedLevenshteinAlgorithm

      public NormalizedLevenshteinAlgorithm()
  • Method Details

    • calculate

      public double calculate(byte @NotNull [] x, byte @NotNull [] y)
      Calculates the normalized Levenshtein distance between two byte arrays. This distance reflects the similarity of the arrays, normalized to a value between 0 and 1.
      Specified by:
      calculate in interface StringDistance
      Parameters:
      x - The first byte array.
      y - The second byte array.
      Returns:
      The normalized Levenshtein distance, a value between 0 and 1.