public class ColognePhonetic extends Object implements StringEncoder
Implements the Kölner Phonetik (Cologne Phonetic) algorithm issued by Hans Joachim Postel in 1969.
The Kölner Phonetik is a phonetic algorithm which is optimized for the German language. It is related to the well-known soundex algorithm.
Letter | Context | Code |
---|---|---|
A, E, I, J, O, U, Y | 0 | |
H | - | |
B | 1 | |
P | not before H | |
D, T | not before C, S, Z | 2 |
F, V, W | 3 | |
P | before H | |
G, K, Q | 4 | |
C | at onset before A, H, K, L, O, Q, R, U, X | |
before A, H, K, O, Q, U, X except after S, Z | ||
X | not after C, K, Q | 48 |
L | 5 | |
M, N | 6 | |
R | 7 | |
S, Z | 8 | |
C | after S, Z | |
at onset except before A, H, K, L, O, Q, R, U, X | ||
not before A, H, K, O, Q, U, X | ||
D, T | before C, S, Z | |
X | after C, K, Q |
(Source: Wikipedia (de): Kölner Phonetik -- Buchstabencodes)
"M
üller-L
üdenscheidt" => "MULLERLUDENSCHEIDT" => "6005507500206880022"
"6005507500206880022" => "6050750206802"
"6050750206802" => "65752682"
Modifier and Type | Class and Description |
---|---|
private class |
ColognePhonetic.CologneBuffer
This class is not thread-safe; the field
ColognePhonetic.CologneBuffer.length is mutable. |
private class |
ColognePhonetic.CologneInputBuffer |
private class |
ColognePhonetic.CologneOutputBuffer |
Modifier and Type | Field and Description |
---|---|
private static char[] |
AEIJOUY |
private static char[] |
AHKLOQRUX |
private static char[] |
AHOUKQX |
private static char[] |
CKQ |
private static char[] |
GKQ |
private static char[][] |
PREPROCESS_MAP
Maps some Germanic characters to plain for internal processing.
|
private static char[] |
SCZ |
private static char[] |
SZ |
private static char[] |
TDX |
private static char[] |
WFPV |
Constructor and Description |
---|
ColognePhonetic() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
arrayContains(char[] arr,
char key) |
String |
colognePhonetic(String text)
Implements the Kölner Phonetik algorithm.
|
Object |
encode(Object object)
Encodes an "Object" and returns the encoded content as an Object.
|
String |
encode(String text)
Encodes a String and returns a String.
|
boolean |
isEncodeEqual(String text1,
String text2) |
private String |
preprocess(String text)
Converts the string to upper case and replaces germanic characters as defined in
PREPROCESS_MAP . |
private static final char[] AEIJOUY
private static final char[] SCZ
private static final char[] WFPV
private static final char[] GKQ
private static final char[] CKQ
private static final char[] AHKLOQRUX
private static final char[] SZ
private static final char[] AHOUKQX
private static final char[] TDX
private static final char[][] PREPROCESS_MAP
public ColognePhonetic()
private static boolean arrayContains(char[] arr, char key)
public String colognePhonetic(String text)
Implements the Kölner Phonetik algorithm.
In contrast to the initial description of the algorithm, this implementation does the encoding in one pass.
text
- public Object encode(Object object) throws EncoderException
Encoder
byte[]
or String
s depending on the implementation used.encode
in interface Encoder
object
- An object to encodeEncoderException
- An encoder exception is thrown if the encoder experiences a failure condition during the encoding
process.public String encode(String text)
StringEncoder
encode
in interface StringEncoder
text
- the String to encodepublic boolean isEncodeEqual(String text1, String text2)
private String preprocess(String text)
PREPROCESS_MAP
.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses