Home All Groups
commons-codec / org / apache / commons / codec / language / ColognePhonetic.html /

Class ColognePhonetic

  • All Implemented Interfaces:
    Encoder, StringEncoder

    public class ColognePhonetic
    extends Object
    implements StringEncoder
    Encodes a string into a Cologne Phonetic value.

    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.


    • Step 1:

      After preprocessing (conversion to upper case, transcription of germanic umlauts, removal of non alphabetical characters) the letters of the supplied text are replaced by their phonetic code according to the following table.
      (Source: Wikipedia (de): Kölner Phonetik -- Buchstabencodes)
      A, E, I, J, O, U, Y0
      Pnot before H
      D, Tnot before C, S, Z2
      F, V, W3
      Pbefore H
      G, K, Q4
      Cat onset before A, H, K, L, O, Q, R, U, X
      before A, H, K, O, Q, U, X except after S, Z
      Xnot after C, K, Q48
      M, N6
      S, Z8
      Cafter 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, Tbefore C, S, Z
      Xafter C, K, Q


      "Müller-Lüdenscheidt" => "MULLERLUDENSCHEIDT" => "6005507500206880022"
    • Step 2:

      Collapse of all multiple consecutive code digits.


      "6005507500206880022" => "6050750206802"
    • Step 3:

      Removal of all codes "0" except at the beginning. This means that two or more identical consecutive digits can occur if they occur after removing the "0" digits.


      "6050750206802" => "65752682"

    This class is thread-safe.

    See Also:
    Wikipedia (de): Kölner Phonetik (in German)
    • Constructor Detail

      • ColognePhonetic

        public ColognePhonetic()
    • Method Detail

      • colognePhonetic

        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 - The source text to encode
        the corresponding encoding according to the Kölner Phonetik algorithm
      • encode

        public Object encode(Object object)
                      throws EncoderException
        Description copied from interface: Encoder
        Encodes an "Object" and returns the encoded content as an Object. The Objects here may just be byte[] or Strings depending on the implementation used.
        Specified by:
        encode in interface  Encoder
        object - An object to encode
        An "encoded" Object
        EncoderException - An encoder exception is thrown if the encoder experiences a failure condition during the encoding process.
      • encode

        public String encode(String text)
        Description copied from interface: StringEncoder
        Encodes a String and returns a String.
        Specified by:
        encode in interface  StringEncoder
        text - the String to encode
        the encoded String
      • isEncodeEqual

        public boolean isEncodeEqual(String text1,
                                     String text2)
        Compares the first encoded string to the second encoded string.
        text1 - source text to encode before testing for equality.
        text2 - source text to encode before testing for equality.
        true if the encoding the first string equals the encoding of the second string, false otherwise

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.