public class Metaphone
extends java.lang.Object
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 Text:Metaphone-1.96. They have had undocumented changes from the originally published algorithm. For more information, see CODEC-57.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
FRONTV
Variable used in Metaphone algorithm
|
private int |
maxCodeLen
The max code length for metaphone is 4
|
private static java.lang.String |
VARSON
Variable used in Metaphone algorithm
|
private static java.lang.String |
VOWELS
Five values in the English language
|
Constructor and Description |
---|
Metaphone()
Creates an instance of the Metaphone encoder
|
Modifier and Type | Method and Description |
---|---|
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.
|
int |
getMaxCodeLen()
Returns the maxCodeLen.
|
private boolean |
isLastChar(int wdsz,
int n) |
boolean |
isMetaphoneEqual(java.lang.String str1,
java.lang.String str2)
Tests is the metaphones of two strings are identical.
|
private boolean |
isNextChar(java.lang.StringBuilder string,
int index,
char c) |
private boolean |
isPreviousChar(java.lang.StringBuilder string,
int index,
char c) |
private boolean |
isVowel(java.lang.StringBuilder string,
int index) |
java.lang.String |
metaphone(java.lang.String txt)
Find the metaphone value of a String.
|
private boolean |
regionMatch(java.lang.StringBuilder string,
int index,
java.lang.String test) |
void |
setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.
|
private static final java.lang.String VOWELS
private static final java.lang.String FRONTV
private static final java.lang.String VARSON
private int maxCodeLen
public java.lang.String metaphone(java.lang.String txt)
txt
- String to find the metaphone code forprivate boolean isVowel(java.lang.StringBuilder string, int index)
private boolean isPreviousChar(java.lang.StringBuilder string, int index, char c)
private boolean isNextChar(java.lang.StringBuilder string, int index, char c)
private boolean regionMatch(java.lang.StringBuilder string, int index, java.lang.String test)
private boolean isLastChar(int wdsz, int n)
public java.lang.Object encode(java.lang.Object pObject) throws EncoderException
pObject
- Object to encodeEncoderException
- if the parameter supplied is not
of type java.lang.Stringpublic java.lang.String encode(java.lang.String pString)
pString
- String object to encodepublic boolean isMetaphoneEqual(java.lang.String str1, java.lang.String str2)
str1
- First of two strings to comparestr2
- Second of two strings to comparetrue
if the metaphones of these strings are identical,
false
otherwise.public int getMaxCodeLen()
public void setMaxCodeLen(int maxCodeLen)
maxCodeLen
- The maxCodeLen to set