Class RefinedSoundex

  • All Implemented Interfaces:
    Encoder, StringEncoder

    public class RefinedSoundex
    extends java.lang.Object
    implements StringEncoder
    Encodes a string into a Refined Soundex value. A refined soundex code is optimized for spell checking words. Soundex method originally developed by Margaret Odell and Robert Russell.

    This class is immutable and thread-safe.

    • Constructor Summary

      Constructors 
      Constructor Description
      RefinedSoundex()
      Creates an instance of the RefinedSoundex object using the default US English mapping.
      RefinedSoundex​(char[] mapping)
      Creates a refined soundex instance using a custom mapping.
      RefinedSoundex​(java.lang.String mapping)
      Creates a refined Soundex instance using a custom mapping.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int difference​(java.lang.String s1, java.lang.String s2)
      Returns the number of characters in the two encoded Strings that are the same.
      java.lang.Object encode​(java.lang.Object obj)
      Encodes an Object using the refined soundex algorithm.
      java.lang.String encode​(java.lang.String str)
      Encodes a String using the refined soundex algorithm.
      java.lang.String soundex​(java.lang.String str)
      Retrieves the Refined Soundex code for a given String object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • US_ENGLISH_MAPPING_STRING

        public static final java.lang.String US_ENGLISH_MAPPING_STRING
        Mapping:
         0: A E I O U Y H W
         1: B P
         2: F V
         3: C K S
         4: G J
         5: Q X Z
         6: D T
         7: L
         8: M N
         9: R
         
        Since:
        1.4
        See Also:
        Constant Field Values
      • US_ENGLISH

        public static final RefinedSoundex US_ENGLISH
        This static variable contains an instance of the RefinedSoundex using the US_ENGLISH mapping.
    • Constructor Detail

      • RefinedSoundex

        public RefinedSoundex()
        Creates an instance of the RefinedSoundex object using the default US English mapping.
      • RefinedSoundex

        public RefinedSoundex​(char[] mapping)
        Creates a refined soundex instance using a custom mapping. This constructor can be used to customize the mapping, and/or possibly provide an internationalized mapping for a non-Western character set.
        Parameters:
        mapping - Mapping array to use when finding the corresponding code for a given character
      • RefinedSoundex

        public RefinedSoundex​(java.lang.String mapping)
        Creates a refined Soundex instance using a custom mapping. This constructor can be used to customize the mapping, and/or possibly provide an internationalized mapping for a non-Western character set.
        Parameters:
        mapping - Mapping string to use when finding the corresponding code for a given character
        Since:
        1.4
    • Method Detail

      • difference

        public int difference​(java.lang.String s1,
                              java.lang.String s2)
                       throws EncoderException
        Returns the number of characters in the two encoded Strings that are the same. This return value ranges from 0 to the length of the shortest encoded String: 0 indicates little or no similarity, and 4 out of 4 (for example) indicates strong similarity or identical values. For refined Soundex, the return value can be greater than 4.
        Parameters:
        s1 - A String that will be encoded and compared.
        s2 - A String that will be encoded and compared.
        Returns:
        The number of characters in the two encoded Strings that are the same from 0 to to the length of the shortest encoded String.
        Throws:
        EncoderException - if an error occurs encoding one of the strings
        Since:
        1.3
        See Also:
        SoundexUtils.difference(StringEncoder,String,String), MS T-SQL DIFFERENCE
      • encode

        public java.lang.Object encode​(java.lang.Object obj)
                                throws EncoderException
        Encodes an Object using the refined soundex algorithm. This method is provided in order to satisfy the requirements of the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String.
        Specified by:
        encode in interface Encoder
        Parameters:
        obj - Object to encode
        Returns:
        An object (or type java.lang.String) containing the refined soundex code which corresponds to the String supplied.
        Throws:
        EncoderException - if the parameter supplied is not of type java.lang.String
      • encode

        public java.lang.String encode​(java.lang.String str)
        Encodes a String using the refined soundex algorithm.
        Specified by:
        encode in interface StringEncoder
        Parameters:
        str - A String object to encode
        Returns:
        A Soundex code corresponding to the String supplied
      • soundex

        public java.lang.String soundex​(java.lang.String str)
        Retrieves the Refined Soundex code for a given String object.
        Parameters:
        str - String to encode using the Refined Soundex algorithm
        Returns:
        A soundex code for the String supplied