org.apache.commons.codec.language
public class Metaphone extends Object implements StringEncoder
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.
Modifier and Type | Field and Description |
---|---|
private String |
frontv
Variable used in Metaphone algorithm
|
private int |
maxCodeLen
The max code length for metaphone is 4
|
private String |
varson
Variable used in Metaphone algorithm
|
private 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 |
---|---|
Object |
encode(Object pObject)
Encodes an Object using the metaphone algorithm.
|
String |
encode(String pString)
Encodes a String using the Metaphone algorithm.
|
int |
getMaxCodeLen()
Returns the maxCodeLen.
|
private boolean |
isLastChar(int wdsz,
int n) |
boolean |
isMetaphoneEqual(String str1,
String str2)
Tests is the metaphones of two strings are identical.
|
private boolean |
isNextChar(StringBuffer string,
int index,
char c) |
private boolean |
isPreviousChar(StringBuffer string,
int index,
char c) |
private boolean |
isVowel(StringBuffer string,
int index) |
String |
metaphone(String txt)
Find the metaphone value of a String.
|
private boolean |
regionMatch(StringBuffer string,
int index,
String test) |
void |
setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.
|
private String vowels
private String frontv
private String varson
private int maxCodeLen
public String metaphone(String txt)
txt
- String to find the metaphone code forprivate boolean isVowel(StringBuffer string, int index)
private boolean isPreviousChar(StringBuffer string, int index, char c)
private boolean isNextChar(StringBuffer string, int index, char c)
private boolean regionMatch(StringBuffer string, int index, String test)
private boolean isLastChar(int wdsz, int n)
public Object encode(Object pObject) throws EncoderException
encode
in interface Encoder
pObject
- Object to encodeEncoderException
- if the parameter supplied is not
of type java.lang.Stringpublic String encode(String pString)
encode
in interface StringEncoder
pString
- String object to encodepublic boolean isMetaphoneEqual(String str1, String str2)
str1
- First of two strings to comparestr2
- Second of two strings to comparepublic int getMaxCodeLen()
public void setMaxCodeLen(int maxCodeLen)
maxCodeLen
- The maxCodeLen to setcommons-codec version 1.3 - Copyright © 2002-2004 - Apache Software Foundation