Class DaitchMokotoffSoundex
- All Implemented Interfaces:
Encoder
,StringEncoder
The Daitch-Mokotoff Soundex algorithm is a refinement of the Russel and American Soundex algorithms, yielding greater accuracy in matching especially Slavish and Yiddish surnames with similar pronunciation but differences in spelling.
The main differences compared to the other soundex variants are:
- coded names are 6 digits long
- the initial character of the name is coded
- rules to encoded multi-character n-grams
- multiple possible encodings for the same name (branching)
This implementation supports branching, depending on the used method:
encode(String)
- branching disabled, only the first code will be returnedsoundex(String)
- branching enabled, all codes will be returned, separated by '|'
Note: this implementation has additional branching rules compared to the original description of the algorithm. The
rules can be customized by overriding the default rules contained in the resource file
org/apache/commons/codec/language/dmrules.txt
.
This class is thread-safe.
- Since:
- 1.10
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Inner class representing a branch during DM soundex encoding.private static final class
Inner class for storing rules. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final String
private final boolean
Whether to use ASCII folding prior to encoding.Folding rules.private static final int
The code length of a DM soundex value.private static final String
private static final String
private static final String
The resource file containing the replacement and folding rulesprivate static final Map
<Character, List<DaitchMokotoffSoundex.Rule>> Transformation rules indexed by the first character of their pattern. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with ASCII-folding enabled.DaitchMokotoffSoundex
(boolean folding) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate String
Performs a cleanup of the input string before the actual soundex transformation.Encodes an Object using the Daitch-Mokotoff soundex algorithm without branching.Encodes a String using the Daitch-Mokotoff soundex algorithm without branching.private static void
parseRules
(Scanner scanner, String location, Map<Character, List<DaitchMokotoffSoundex.Rule>> ruleMapping, Map<Character, Character> asciiFoldings) Encodes a String using the Daitch-Mokotoff soundex algorithm with branching.private String[]
Perform the actual DM Soundex algorithm on the input string.private static String
stripQuotes
(String str)
-
Field Details
-
COMMENT
- See Also:
-
DOUBLE_QUOTE
- See Also:
-
MULTILINE_COMMENT_END
- See Also:
-
MULTILINE_COMMENT_START
- See Also:
-
RESOURCE_FILE
The resource file containing the replacement and folding rules- See Also:
-
MAX_LENGTH
private static final int MAX_LENGTHThe code length of a DM soundex value.- See Also:
-
RULES
Transformation rules indexed by the first character of their pattern. -
FOLDINGS
Folding rules. -
folding
private final boolean foldingWhether to use ASCII folding prior to encoding.
-
-
Constructor Details
-
DaitchMokotoffSoundex
public DaitchMokotoffSoundex()Creates a new instance with ASCII-folding enabled. -
DaitchMokotoffSoundex
public DaitchMokotoffSoundex(boolean folding) Creates a new instance.With ASCII-folding enabled, certain accented characters will be transformed to equivalent ASCII characters, e.g. รจ -> e.
- Parameters:
folding
- if ASCII-folding shall be performed before encoding
-
-
Method Details
-
parseRules
-
stripQuotes
-
cleanup
Performs a cleanup of the input string before the actual soundex transformation.Removes all whitespace characters and performs ASCII folding if enabled.
- Parameters:
input
- the input string to clean up- Returns:
- a cleaned up string
-
encode
Encodes an Object using the Daitch-Mokotoff soundex algorithm without branching.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 interfaceEncoder
- Parameters:
obj
- Object to encode- Returns:
- An object (of type java.lang.String) containing the DM soundex code, which corresponds to the String supplied.
- Throws:
EncoderException
- if the parameter supplied is not of type java.lang.StringIllegalArgumentException
- if a character is not mapped- See Also:
-
encode
Encodes a String using the Daitch-Mokotoff soundex algorithm without branching.- Specified by:
encode
in interfaceStringEncoder
- Parameters:
source
- A String object to encode- Returns:
- A DM Soundex code corresponding to the String supplied
- Throws:
IllegalArgumentException
- if a character is not mapped- See Also:
-
soundex
Encodes a String using the Daitch-Mokotoff soundex algorithm with branching.In case a string is encoded into multiple codes (see branching rules), the result will contain all codes, separated by '|'.
Example: the name "AUERBACH" is encoded as both
- 097400
- 097500
Thus the result will be "097400|097500".
- Parameters:
source
- A String object to encode- Returns:
- A string containing a set of DM Soundex codes corresponding to the String supplied
- Throws:
IllegalArgumentException
- if a character is not mapped
-
soundex
Perform the actual DM Soundex algorithm on the input string.- Parameters:
source
- A String object to encodebranching
- If branching shall be performed- Returns:
- A string array containing all DM Soundex codes corresponding to the String supplied depending on the selected branching mode
-