org.apache.commons.codec.language
Class Metaphone
- Encoder, StringEncoder
Encodes 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.
Version:
- Apache Software Foundation
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
|
Metaphone() - Creates an instance of the Metaphone encoder
|
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.
|
frontv
private String frontv
Variable used in Metaphone algorithm
maxCodeLen
private int maxCodeLen
The max code length for metaphone is 4
varson
private String varson
Variable used in Metaphone algorithm
vowels
private String vowels
Five values in the English language
Metaphone
public Metaphone()
Creates an instance of the Metaphone encoder
encode
public Object encode(Object pObject)
throws EncoderException
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 EncoderException if the
supplied object is not of type java.lang.String.
- encode in interface Encoder
pObject
- Object to encode
- An object (or type java.lang.String) containing the
metaphone code which corresponds to the String supplied.
EncoderException
- if the parameter supplied is not
of type java.lang.String
encode
public String encode(String pString)
Encodes a String using the Metaphone algorithm.
- encode in interface StringEncoder
pString
- String object to encode
- The metaphone code corresponding to the String supplied
getMaxCodeLen
public int getMaxCodeLen()
Returns the maxCodeLen.
- int
isLastChar
private boolean isLastChar(int wdsz,
int n)
isMetaphoneEqual
public boolean isMetaphoneEqual(String str1,
String str2)
Tests is the metaphones of two strings are identical.
str1
- First of two strings to comparestr2
- Second of two strings to compare
- true if the metaphones of these strings are identical,
false otherwise.
isNextChar
private boolean isNextChar(StringBuffer string,
int index,
char c)
isPreviousChar
private boolean isPreviousChar(StringBuffer string,
int index,
char c)
isVowel
private boolean isVowel(StringBuffer string,
int index)
metaphone
public String metaphone(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.
txt
- String to find the metaphone code for
- A metaphone code corresponding to the String supplied
regionMatch
private boolean regionMatch(StringBuffer string,
int index,
String test)
setMaxCodeLen
public void setMaxCodeLen(int maxCodeLen)
Sets the maxCodeLen.
maxCodeLen
- The maxCodeLen to set
commons-codec version 1.3 - Copyright © 2002-2004 - Apache Software Foundation