cds.util
Class Soundex

java.lang.Object
  extended bycds.util.Soundex

public class Soundex
extends java.lang.Object

Encodes words using the soundex phonetic algorithm. The primary method to call is Soundex.encode(String).

The main method encodes arguments to System.out.

Author:
Aaron Hansen

Field Summary
protected  boolean DropFinalSBoolean
           
protected  int LengthInt
           
private static java.lang.String LowerS
           
static int NO_MAX
           
protected  boolean PadBoolean
           
protected  int[] SoundexInts
           
private static java.lang.String UpperS
           
 
Constructor Summary
Soundex()
           
 
Method Summary
protected static int[] createArray()
          Creates the Soundex code table.
 java.lang.String encode(java.lang.String word)
          Returns the soundex code for the specified word.
 int getCode(char ch)
          Returns the Soundex code for the specified character.
 boolean getDropFinalS()
          If true, a final char of 's' or 'S' of the word being encoded will be dropped.
 int getLength()
          The length of code strings to build, 4 by default.
 boolean getPad()
          If true, appends zeros to a soundex code if the code is less than Soundex.getLength().
static void main(java.lang.String[] strings)
          Displays the codes for the parameters.
protected  java.lang.String reduce(java.lang.String word)
          Removes adjacent sounds.
 void setCode(char ch, int code)
          Allows you to modify the default code table
 void setDropFinalS(boolean bool)
          If true, a final char of 's' or 'S' of the word being encoded will be dropped.
 void setLength(int length)
          Sets the length of code strings to build. 4 by default.
 void setPad(boolean bool)
          If true, appends zeros to a soundex code if the code is less than Soundex.getLength().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MAX

public static final transient int NO_MAX
See Also:
Constant Field Values

DropFinalSBoolean

protected boolean DropFinalSBoolean

LengthInt

protected int LengthInt

PadBoolean

protected boolean PadBoolean

SoundexInts

protected int[] SoundexInts

LowerS

private static final java.lang.String LowerS
See Also:
Constant Field Values

UpperS

private static final java.lang.String UpperS
See Also:
Constant Field Values
Constructor Detail

Soundex

public Soundex()
Method Detail

encode

public java.lang.String encode(java.lang.String word)
Returns the soundex code for the specified word.

Parameters:
word - The word to encode.

getCode

public int getCode(char ch)
Returns the Soundex code for the specified character.

Parameters:
ch - Should be between A-Z or a-z
Returns:
-1 if the character has no phonetic code.

getDropFinalS

public boolean getDropFinalS()
If true, a final char of 's' or 'S' of the word being encoded will be dropped. By dropping the last s, lady and ladies for example, will encode the same. False by default.


getLength

public int getLength()
The length of code strings to build, 4 by default. If negative, length is unlimited.

See Also:
NO_MAX

getPad

public boolean getPad()
If true, appends zeros to a soundex code if the code is less than Soundex.getLength(). True by default.


setCode

public void setCode(char ch,
                    int code)
Allows you to modify the default code table

Parameters:
ch - The character to specify the code for.
code - The code to represent ch with, must be -1, or 1 thru 9

setDropFinalS

public void setDropFinalS(boolean bool)
If true, a final char of 's' or 'S' of the word being encoded will be dropped.


setLength

public void setLength(int length)
Sets the length of code strings to build. 4 by default.


setPad

public void setPad(boolean bool)
If true, appends zeros to a soundex code if the code is less than Soundex.getLength(). True by default.


createArray

protected static int[] createArray()
Creates the Soundex code table.


reduce

protected java.lang.String reduce(java.lang.String word)
Removes adjacent sounds.


main

public static void main(java.lang.String[] strings)
Displays the codes for the parameters.