Class StringComparisonUtil
java.lang.Object
com.ssgllc.fish.service.util.registered.StringComparisonUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublestatic doublestatic StringdoubleMetaphone(String value) The primary Double Metaphone code of a value.static StringdoubleMetaphoneAlt(String value) The alternate Double Metaphone code of a value.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).static booleandoubleMetaphoneMatch(String name, String nameToCompare) Whether two values match phonetically under Double Metaphone.static booleanisSoundexMatch(String name, String nameToCompare) Whether two values match phonetically under Soundex — i.e. their Soundex codes are equal (case-insensitively).static doublejaccardDist(String str, String strToCompare) static doublejaccardSim(String str, String strToCompare) static doublejaroWinklerDist(String str, String strToCompare) static doublestatic StringThe Soundex code of a value, for storing on an entity and matching in a blocking-set query (e.g. block ons.firstNameSoundex = {#soundex(firstName)}).
-
Method Details
-
cosSim
-
jaccardSim
-
jaroWinklerDist
-
jaccardDist
-
cosDist
-
levDist
-
isSoundexMatch
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 (viasoundex(String)), so accented/punctuated names don't error. The Double Metaphone equivalent — which also catches initial-sound variants like C/K that Soundex splits — isdoubleMetaphoneMatch(String, String).- Parameters:
name- the first valuenameToCompare- 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
The Soundex code of a value, for storing on an entity and matching in a blocking-set query (e.g. block ons.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
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) usedoubleMetaphoneCodes(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
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 alongsidedoubleMetaphone(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
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
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 (mirrorsisSoundexMatch(java.lang.String, java.lang.String)). The Soundex equivalent of this is the existingisSoundexMatch.- Parameters:
name- the first valuenameToCompare- 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")
-