public class Metaphone extends Object implements StringEncoderEncodes a string into a Metaphone value.
Initial Java implementation by William B. Brogden. December, 1997. Permission given by wbrogden for code to be used anywhere.
Hanging on the Metaphone by Lawrence Philips in Computer Language of Dec. 1990, p 39.
Note, that this does not match the algorithm that ships with PHP, or the algorithm found in the Perl implementations:
They have had undocumented changes from the originally published algorithm. For more information, see CODEC-57.
This class is conditionally thread-safe. The instance field for maximum code length is mutable
setMaxCodeLen(int)but is not volatile, and accesses are not synchronized. If an instance of the class is shared between threads, the caller needs to ensure that suitable synchronization is used to ensure safe publication of the value between threads, and must not invoke
setMaxCodeLen(int)after initial setup.
Constructors Constructor and Description
Metaphone()Creates an instance of the Metaphone encoder
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description
encode(Object obj)Encodes an Object using the metaphone algorithm.
encode(String str)Encodes a String using the Metaphone algorithm.
getMaxCodeLen()Returns the maxCodeLen.
isMetaphoneEqual(String str1, String str2)Tests is the metaphones of two strings are identical.
metaphone(String txt)Find the metaphone value of a String.
setMaxCodeLen(int maxCodeLen)Sets the maxCodeLen.
metaphoneFind 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.
txt- String to find the metaphone code for
- A metaphone code corresponding to the String supplied
public Object encode(Object obj) throws EncoderExceptionEncodes an Object using the metaphone 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.
encodeEncodes a String using the Metaphone algorithm.
isMetaphoneEqualTests is the metaphones of two strings are identical.
str1- First of two strings to compare
str2- Second of two strings to compare
trueif the metaphones of these strings are identical,
public int getMaxCodeLen()Returns the maxCodeLen.
public void setMaxCodeLen(int maxCodeLen)Sets the maxCodeLen.
maxCodeLen- The maxCodeLen to set
Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.