Class StringComparisonUtil

java.lang.Object
com.ssgllc.fish.service.util.registered.StringComparisonUtil

@Component public final class StringComparisonUtil extends Object
  • Method Details

    • cosSim

      public static double cosSim(String str, String strToCompare)
    • jaccardSim

      public static double jaccardSim(String str, String strToCompare)
    • jaroWinklerDist

      public static double jaroWinklerDist(String str, String strToCompare)
    • jaccardDist

      public static double jaccardDist(String str, String strToCompare)
    • cosDist

      public static double cosDist(String str, String strToCompare)
    • levDist

      public static double levDist(String str, String strToCompare)
    • isSoundexMatch

      public static boolean isSoundexMatch(String name, String nameToCompare)
      Whether two values match phonetically under Soundex — i.e. their Soundex codes are equal (case-insensitively). Two nulls match; one null does not. Non-letter characters are stripped before encoding (via soundex(String)), so accented/punctuated names don't error. The Double Metaphone equivalent — which also catches initial-sound variants like C/K that Soundex splits — is doubleMetaphoneMatch(String, String).
      Parameters:
      name - the first value
      nameToCompare - the second value
      Returns:
      true if the two share the same Soundex code

      Groovy example:
      stringComparisonUtil.isSoundexMatch("Smith", "Smyth")
      SpEL example:
      #isSoundexMatch("Smith", "Smyth")
    • soundex

      public static String soundex(String value)
      The Soundex code of a value, for storing on an entity and matching in a blocking-set query (e.g. block on s.firstNameSoundex = {#soundex(firstName)}). Accented characters are folded to their ASCII base (e.g. Muñoz → Munoz, François → Francois) and any remaining non-letters stripped before encoding, so accented and unaccented spellings encode alike. Returns null for a null, blank, or letter-free input.
      Parameters:
      value - the value to encode
      Returns:
      the Soundex code, or null if there are no letters to encode

      Groovy example:
      stringComparisonUtil.soundex("Robert")
      SpEL example:
      #soundex("Robert")
    • doubleMetaphone

      public static String doubleMetaphone(String value)
      The primary Double Metaphone code of a value. Use this to populate a stored/computed phonetic column (firstNameDmeta = #doubleMetaphone(firstName)) that a blocking-set query then matches against. For the query side (matching on either pronunciation) use doubleMetaphoneCodes(String). Returns null for a null/blank input or a value with no encodable letters.
      Parameters:
      value - the value to encode
      Returns:
      the primary Double Metaphone code, or null if none

      Groovy example:
      stringComparisonUtil.doubleMetaphone("Smith")
      SpEL example:
      #doubleMetaphone("Smith")
    • doubleMetaphoneAlt

      public static String doubleMetaphoneAlt(String value)
      The alternate Double Metaphone code of a value. Double Metaphone emits a second code for names with two plausible pronunciations (often different-origin names); when there is no distinct alternate it equals the primary. Store this alongside doubleMetaphone(String) as a second phonetic column so a blocking-set query can match candidates on either pronunciation. Returns null for a null/blank input or a value with no encodable letters.
      Parameters:
      value - the value to encode
      Returns:
      the alternate Double Metaphone code, or null if none

      Groovy example:
      stringComparisonUtil.doubleMetaphoneAlt("Angelo")
      SpEL example:
      #doubleMetaphoneAlt("Angelo")
    • doubleMetaphoneCodes

      public static Set<String> doubleMetaphoneCodes(String value)
      The Double Metaphone codes of a value — the primary plus the alternate encoding, deduplicated (one entry when they coincide, two when the name has two plausible pronunciations). Intended for the query side of a blocking-set query so a record matches candidates on either pronunciation, e.g. s.firstNameDmeta in ({#doubleMetaphoneCodes(firstName)}). Never returns null; returns an empty set for a null/blank input or a value with no encodable letters.
      Parameters:
      value - the value to encode
      Returns:
      the distinct primary/alternate Double Metaphone codes; empty if none

      Groovy example:
      stringComparisonUtil.doubleMetaphoneCodes("Zhang")
      SpEL example:
      #doubleMetaphoneCodes("Zhang")
    • doubleMetaphoneMatch

      public static boolean doubleMetaphoneMatch(String name, String nameToCompare)
      Whether two values match phonetically under Double Metaphone. Matches when they share any code — primary or alternate — on either side (so it catches names that agree on only one of their two plausible pronunciations), which is looser and more recall-friendly than comparing primary codes alone. Two nulls match; one null does not (mirrors isSoundexMatch(java.lang.String, java.lang.String)). The Soundex equivalent of this is the existing isSoundexMatch.
      Parameters:
      name - the first value
      nameToCompare - the second value
      Returns:
      true if the two are phonetically equal under Double Metaphone

      Groovy example:
      stringComparisonUtil.doubleMetaphoneMatch("Smith", "Schmidt")
      SpEL example:
      #doubleMetaphoneMatch("Smith", "Schmidt")