Codec Language : Code « Apache Common « Java

Codec Language

import org.apache.commons.codec.*;
import org.apache.commons.codec.language.*;

public class LanguageUsage{

  public static void main(String args[]){
    LanguageUsage codec = new LanguageUsage();
    }catch(Exception e){

  public void start() throws EncoderException, DecoderException{

    String word1 = "Wilson";
    String word2 = "Wylson";
    String foreignWord1 = "Otto";
    String foreignWord2 = "Auto";

    Soundex sndx = new Soundex();
    DoubleMetaphone doubleMetaphone = new DoubleMetaphone();

    System.err.println("Soundex Code for Wilson is: " + sndx.encode("Wilson"));
    System.err.println("Soundex Code for Wylson is: " + sndx.encode("Wylson"));

    // Use the StringEncoderComparator to compare these two Strings
    StringEncoderComparator comparator1 = new StringEncoderComparator(sndx);
    System.err.println("Are Wilson and Wylson same based on Soundex? "
      +"Wilson", "Wylson"));

    System.err.println("Are Auto and Otto same based on Soundex? "
      +"Auto", "Otto"));

    StringEncoderComparator comparator2 =
      new StringEncoderComparator(doubleMetaphone);

    System.err.println("Are Auto and Otto same based on DoubleMetaphone? "
      +"Auto", "Otto"));

    System.err.println("Double Metaphone primary code for Schmidt: " +

    System.err.println("Double Metaphone secondary code for Schmidt: " +
      doubleMetaphone.doubleMetaphone("Schmidt", true));

       73 k)

Related examples in the same category

1.Codec Digest
2.Codec Net: URL encode and decode