com.sun.mdm.index.phonetic.impl
Class Metaphone

java.lang.Object
  extended bycom.sun.mdm.index.phonetic.impl.Metaphone
All Implemented Interfaces:
PhoneticEncoder

public class Metaphone
extends java.lang.Object
implements PhoneticEncoder

Encodes a string into a metaphone value. The initial Java implementation, William B. Brogden. December, 1997 Permission given by wbrogden for code to be used anywhere. "Hanging on the Metaphone" by Lawrence Philips Computer Language of Dec. 1990, p 39


Field Summary
static java.lang.String ENCODING_TYPE
          informative String about the encoding type this encoder does
 
Constructor Summary
Metaphone()
          Creates an instance of the Metaphone encoder
 
Method Summary
 java.lang.Object encode(java.lang.Object pObject)
          Encodes an Object using the metaphone algorithm.
 java.lang.String encode(java.lang.String pString)
          Encodes a String using the Metaphone algorithm.
 java.lang.String encode(java.lang.String value, java.lang.String domain)
          Encode the value using Metaphone.
 java.lang.String getEncodingType()
           
 int getMaxCodeLen()
          Returns the maxCodeLen.
 boolean isMetaphoneEqual(java.lang.String str1, java.lang.String str2)
          Tests is the metaphones of two strings are identical.
 java.lang.String metaphone(java.lang.String txt)
          Find the metaphone value of a String.
 void setMaxCodeLen(int maxCodeLen)
          Sets the maxCodeLen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_TYPE

public static final java.lang.String ENCODING_TYPE
informative String about the encoding type this encoder does

See Also:
Constant Field Values
Constructor Detail

Metaphone

public Metaphone()
Creates an instance of the Metaphone encoder

Method Detail

encode

public java.lang.Object encode(java.lang.Object pObject)
                        throws PhoneticEncoderException
Encodes an Object using the metaphone algorithm. This method is provided in order to satisfy the requirements of the Encoder interface, and will throw an PhoneticEncoderException if the supplied object is not of type java.lang.String.

Parameters:
pObject - Object to encode
Returns:
An object (or type java.lang.String) containing the metaphone code which corresponds to the String supplied.
Throws:
PhoneticEncoderException - if the parameter supplied is not of type java.lang.String

encode

public java.lang.String encode(java.lang.String pString)
Encodes a String using the Metaphone algorithm.

Specified by:
encode in interface PhoneticEncoder
Parameters:
pString - String object to encode
Returns:
The metaphone code corresponding to the String supplied
Throws:
PhoneticEncoderException - thrown if a Metaphone specific exception is encountered.

encode

public java.lang.String encode(java.lang.String value,
                               java.lang.String domain)
Encode the value using Metaphone.

Specified by:
encode in interface PhoneticEncoder
Parameters:
value - String to encode
domain - locality
Returns:
An encoded String
Throws:
PhoneticEncoderException - thrown if there is an exception during the encoding process.

getEncodingType

public java.lang.String getEncodingType()
Description copied from interface: PhoneticEncoder
Getter for the encoding type

Specified by:
getEncodingType in interface PhoneticEncoder
Returns:
the encoding type the Phonetic Encoder implements (such as NYSIIS or Soundex) This value is for information purposes and is not enforced to be of the same value as the 'encoding type' listed in the PhoneticEncodersConfiguration for the encoder class instance. As a result it should not be used for calls to the Phoneticizer.

getMaxCodeLen

public int getMaxCodeLen()
Returns the maxCodeLen.

Returns:
int

isMetaphoneEqual

public boolean isMetaphoneEqual(java.lang.String str1,
                                java.lang.String str2)
Tests is the metaphones of two strings are identical.

Parameters:
str1 - First of two strings to compare
str2 - Second of two strings to compare
Returns:
true if the metaphones of these strings are identical, false otherwise.

metaphone

public java.lang.String metaphone(java.lang.String txt)
Find the metaphone value of a String. This is similar to the soundex algorithm, but better at finding similar sounding words. All input is converted to upper case. Limitations: Input format is expected to be a single ASCII word with only characters in the A - Z range, no punctuation or numbers.

Parameters:
txt - String to find the metaphone code for
Returns:
A metaphone code corresponding to the String supplied

setMaxCodeLen

public void setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.

Parameters:
maxCodeLen - The maxCodeLen to set


Sun Microsystems, Inc.