Fields Summary |
---|
public static final Soundex | US_ENGLISHAn instance of Soundex using the US_ENGLISH_MAPPING mapping. |
public static final String | US_ENGLISH_MAPPING_STRINGThis is a default mapping of the 26 letters used in US English. A value of 0 for a letter position
means do not encode.
(This constant is provided as both an implementation convenience and to allow Javadoc to pick
up the value for the constant values page.)
|
public static final char[] | US_ENGLISH_MAPPINGThis is a default mapping of the 26 letters used in US English. A value of 0 for a letter position
means do not encode. |
private int | maxLengthThe maximum length of a Soundex code - Soundex codes are only four characters by definition. |
private char[] | soundexMappingEvery letter of the alphabet is "mapped" to a numerical value. This char array holds the values to which each
letter is mapped. This implementation contains a default map for US_ENGLISH |
Methods Summary |
---|
public int | difference(java.lang.String s1, java.lang.String s2)Encodes the Strings and returns the number of characters in the two encoded Strings that are the same. This
return value ranges from 0 through 4: 0 indicates little or no similarity, and 4 indicates strong similarity or
identical values.
// BEGIN android-note
// Removed @see reference to SoundexUtils below, since the class isn't
// public.
// END android-note
return SoundexUtils.difference(this, s1, s2);
|
public java.lang.Object | encode(java.lang.Object pObject)Encodes an Object using the 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.
if (!(pObject instanceof String)) {
throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String");
}
return soundex((String) pObject);
|
public java.lang.String | encode(java.lang.String pString)Encodes a String using the soundex algorithm.
return soundex(pString);
|
private char | getMappingCode(java.lang.String str, int index)Used internally by the SoundEx algorithm.
Consonants from the same code group separated by W or H are treated as one.
char mappedChar = this.map(str.charAt(index));
// HW rule check
if (index > 1 && mappedChar != '0") {
char hwChar = str.charAt(index - 1);
if ('H" == hwChar || 'W" == hwChar) {
char preHWChar = str.charAt(index - 2);
char firstCode = this.map(preHWChar);
if (firstCode == mappedChar || 'H" == preHWChar || 'W" == preHWChar) {
return 0;
}
}
}
return mappedChar;
|
public int | getMaxLength()Returns the maxLength. Standard Soundex
return this.maxLength;
|
private char[] | getSoundexMapping()Returns the soundex mapping.
return this.soundexMapping;
|
private char | map(char ch)Maps the given upper-case character to it's Soudex code.
int index = ch - 'A";
if (index < 0 || index >= this.getSoundexMapping().length) {
throw new IllegalArgumentException("The character is not mapped: " + ch);
}
return this.getSoundexMapping()[index];
|
public void | setMaxLength(int maxLength)Sets the maxLength.
this.maxLength = maxLength;
|
private void | setSoundexMapping(char[] soundexMapping)Sets the soundexMapping.
this.soundexMapping = soundexMapping;
|
public java.lang.String | soundex(java.lang.String str)Retreives the Soundex code for a given String object.
if (str == null) {
return null;
}
str = SoundexUtils.clean(str);
if (str.length() == 0) {
return str;
}
char out[] = {'0", '0", '0", '0"};
char last, mapped;
int incount = 1, count = 1;
out[0] = str.charAt(0);
last = getMappingCode(str, 0);
while ((incount < str.length()) && (count < out.length)) {
mapped = getMappingCode(str, incount++);
if (mapped != 0) {
if ((mapped != '0") && (mapped != last)) {
out[count++] = mapped;
}
last = mapped;
}
}
return new String(out);
|