pt.tumba.spell
Class Phonetic

java.lang.Object
  extended by pt.tumba.spell.Phonetic

public class Phonetic
extends java.lang.Object

Implementation of Phonetic similarity algorithms (Soundex, Metaphone and Double Metaphone), used to reduce matching problems from wrong spellings.

A Soundex search algorithm takes a word, such as a person's name, as input and produces a character string which identifies a set of words that are (roughly) phonetically alike. It is very handy for searching large databases when the user has incomplete data.

The original Soundex algorithm was patented by Margaret O'Dell and Robert C. Russell in 1918. The method is based on the six phonetic classifications of human speech sounds (bilabial, labiodental, dental, alveolar, velar, and glottal), which in turn are based on where you put your lips and tongue to make the sounds.

As for the metaphone algorithm, it encodes English words phonetically, by reducing them to 16 consonant sounds. It originally appeared in the December 1990 issue of Computer Language by Lawrence Philips. Vowels are minimized as much as possible, and consenants that have similiar sounds are converted to the same consenant for example, 'v' and 'f' are both converted to 'f'.

The double metaphone algorithm is a better variant, coding English words (and foreign words often heard in the United States) phonetically by reducing them to 12 consonant sounds. It was also proposed by Lawrence Philips, in an C/C++ Users Journal(tm) article entitled The Double Metaphone Search Algorithm.

Author:
Bruno Martins

Field Summary
private static java.lang.String[] list1
           
private static java.lang.String[] list10
           
private static java.lang.String[] list11
           
private static java.lang.String[] list12
           
private static java.lang.String[] list13
           
private static java.lang.String[] list14
           
private static java.lang.String[] list15
           
private static java.lang.String[] list16
           
private static java.lang.String[] list17
           
private static java.lang.String[] list18
           
private static java.lang.String[] list19
           
private static java.lang.String[] list2
           
private static java.lang.String[] list20
           
private static java.lang.String[] list21
           
private static java.lang.String[] list22
           
private static java.lang.String[] list23
           
private static java.lang.String[] list24
           
private static java.lang.String[] list25
           
private static java.lang.String[] list27
           
private static java.lang.String[] list28
           
private static java.lang.String[] list29
           
private static java.lang.String[] list3
           
private static java.lang.String[] list30
           
private static java.lang.String[] list31
           
private static java.lang.String[] list32
           
private static java.lang.String[] list33
           
private static java.lang.String[] list34
           
private static java.lang.String[] list35
           
private static java.lang.String[] list36
           
private static java.lang.String[] list37
           
private static java.lang.String[] list38
           
private static java.lang.String[] list39
           
private static java.lang.String[] list4
           
private static java.lang.String[] list40
           
private static java.lang.String[] list41
           
private static java.lang.String[] list42
           
private static java.lang.String[] list43
           
private static java.lang.String[] list44
           
private static java.lang.String[] list45
           
private static java.lang.String[] list46
           
private static java.lang.String[] list47
           
private static java.lang.String[] list48
           
private static java.lang.String[] list5
           
private static java.lang.String[] list50
           
private static java.lang.String[] list51
           
private static java.lang.String[] list52
           
private static java.lang.String[] list53
           
private static java.lang.String[] list54
           
private static java.lang.String[] list55
           
private static java.lang.String[] list56
           
private static java.lang.String[] list57
           
private static java.lang.String[] list58
           
private static java.lang.String[] list59
           
private static java.lang.String[] list6
           
private static java.lang.String[] list60
           
private static java.lang.String[] list61
           
private static java.lang.String[] list62
           
private static java.lang.String[] list63
           
private static java.lang.String[] list64
           
private static java.lang.String[] list65
           
private static java.lang.String[] list66
           
private static java.lang.String[] list67
           
private static java.lang.String[] list68
           
private static java.lang.String[] list69
           
private static java.lang.String[] list7
           
private static java.lang.String[] list70
           
private static java.lang.String[] list71
           
private static java.lang.String[] list72
           
private static java.lang.String[] list73
           
private static java.lang.String[] list74
           
private static java.lang.String[] list75
           
private static java.lang.String[] list76
           
private static java.lang.String[] list77
           
private static java.lang.String[] list78
           
private static java.lang.String[] list79
           
private static java.lang.String[] list8
           
private static java.lang.String[] list80
           
private static java.lang.String[] list81
           
private static java.lang.String[] list82
           
private static java.lang.String[] list83
           
private static java.lang.String[] list84
           
private static java.lang.String[] list85
           
private static java.lang.String[] list86
           
private static java.lang.String[] list87
           
private static java.lang.String[] list88
           
private static java.lang.String[] list89
           
private static java.lang.String[] list9
           
private static java.lang.String[] list90
           
private static java.lang.String[] list91
           
private static java.lang.String[] list92
           
private static java.lang.String[] list93
           
private static java.lang.String[] list94
           
private static java.lang.String[] list95
           
private static java.lang.String[] myList
           
private static char[] replaceList
           
private static java.lang.String[] soundexCodes
          The transformation codes used for the soundex algorithm.
private static Phonetic theInstance
          The single instance of this class.
 
Constructor Summary
private Phonetic()
          Sole constructor, private because this is a Singleton class.
 
Method Summary
static java.lang.String getDoubleMetaphone(java.lang.String word)
          Calculates the Double Metaphone value of a given String.
static Phonetic getInstance()
          Return the single instance of this class.
static java.lang.String getMetaphone(java.lang.String word)
          Calculate the Metaphone value of a given String.
private static char getNum(char c)
          Gets the index for the attribute of the Soundex transformation codes corresponding to a given char.
static java.lang.String getSoundex(java.lang.String word)
          Calculate the Soundex value of a given String.
static boolean SlavoGermanic(java.lang.String in)
          Checks if a given word is slavo-germanic.
private static boolean stringAt(java.lang.String string, int start, int length, java.lang.String[] list)
          Checks if part of a given String is equal to any of the String objects supplied in a List.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theInstance

private static final Phonetic theInstance
The single instance of this class.


soundexCodes

private static final java.lang.String[] soundexCodes
The transformation codes used for the soundex algorithm.


replaceList

private static char[] replaceList

myList

private static final java.lang.String[] myList

list1

private static final java.lang.String[] list1

list2

private static final java.lang.String[] list2

list3

private static final java.lang.String[] list3

list4

private static final java.lang.String[] list4

list5

private static final java.lang.String[] list5

list6

private static final java.lang.String[] list6

list7

private static final java.lang.String[] list7

list8

private static final java.lang.String[] list8

list9

private static final java.lang.String[] list9

list10

private static final java.lang.String[] list10

list11

private static final java.lang.String[] list11

list12

private static final java.lang.String[] list12

list13

private static final java.lang.String[] list13

list14

private static final java.lang.String[] list14

list15

private static final java.lang.String[] list15

list16

private static final java.lang.String[] list16

list17

private static final java.lang.String[] list17

list18

private static final java.lang.String[] list18

list19

private static final java.lang.String[] list19

list20

private static final java.lang.String[] list20

list21

private static final java.lang.String[] list21

list22

private static final java.lang.String[] list22

list23

private static final java.lang.String[] list23

list24

private static final java.lang.String[] list24

list25

private static final java.lang.String[] list25

list27

private static final java.lang.String[] list27

list28

private static final java.lang.String[] list28

list29

private static final java.lang.String[] list29

list30

private static final java.lang.String[] list30

list31

private static final java.lang.String[] list31

list32

private static final java.lang.String[] list32

list33

private static final java.lang.String[] list33

list34

private static final java.lang.String[] list34

list35

private static final java.lang.String[] list35

list36

private static final java.lang.String[] list36

list37

private static final java.lang.String[] list37

list38

private static final java.lang.String[] list38

list39

private static final java.lang.String[] list39

list40

private static final java.lang.String[] list40

list41

private static final java.lang.String[] list41

list42

private static final java.lang.String[] list42

list43

private static final java.lang.String[] list43

list44

private static final java.lang.String[] list44

list45

private static final java.lang.String[] list45

list46

private static final java.lang.String[] list46

list47

private static final java.lang.String[] list47

list48

private static final java.lang.String[] list48

list50

private static final java.lang.String[] list50

list51

private static final java.lang.String[] list51

list52

private static final java.lang.String[] list52

list53

private static final java.lang.String[] list53

list54

private static final java.lang.String[] list54

list55

private static final java.lang.String[] list55

list56

private static final java.lang.String[] list56

list57

private static final java.lang.String[] list57

list58

private static final java.lang.String[] list58

list59

private static final java.lang.String[] list59

list60

private static final java.lang.String[] list60

list61

private static final java.lang.String[] list61

list62

private static final java.lang.String[] list62

list63

private static final java.lang.String[] list63

list64

private static final java.lang.String[] list64

list65

private static final java.lang.String[] list65

list66

private static final java.lang.String[] list66

list67

private static final java.lang.String[] list67

list68

private static final java.lang.String[] list68

list69

private static final java.lang.String[] list69

list70

private static final java.lang.String[] list70

list71

private static final java.lang.String[] list71

list72

private static final java.lang.String[] list72

list73

private static final java.lang.String[] list73

list74

private static final java.lang.String[] list74

list75

private static final java.lang.String[] list75

list76

private static final java.lang.String[] list76

list77

private static final java.lang.String[] list77

list78

private static final java.lang.String[] list78

list79

private static final java.lang.String[] list79

list80

private static final java.lang.String[] list80

list81

private static final java.lang.String[] list81

list82

private static final java.lang.String[] list82

list83

private static final java.lang.String[] list83

list84

private static final java.lang.String[] list84

list85

private static final java.lang.String[] list85

list86

private static final java.lang.String[] list86

list87

private static final java.lang.String[] list87

list88

private static final java.lang.String[] list88

list89

private static final java.lang.String[] list89

list90

private static final java.lang.String[] list90

list91

private static final java.lang.String[] list91

list92

private static final java.lang.String[] list92

list93

private static final java.lang.String[] list93

list94

private static final java.lang.String[] list94

list95

private static final java.lang.String[] list95
Constructor Detail

Phonetic

private Phonetic()
Sole constructor, private because this is a Singleton class.

Method Detail

getInstance

public static Phonetic getInstance()
Return the single instance of this class.

Returns:
An instance of Phonetic.

getMetaphone

public static java.lang.String getMetaphone(java.lang.String word)
Calculate the Metaphone value of a given String. This method transforms the parameter into a String according to the Metaphone algorithm.

Parameters:
word - The String to transform.
Returns:
The Metaphone equivalent of the String.

getNum

private static char getNum(char c)
Gets the index for the attribute of the Soundex transformation codes corresponding to a given char.

Parameters:
c - A character.
Returns:
The index for the attribute of the Soundex transformation codes.

getSoundex

public static java.lang.String getSoundex(java.lang.String word)
Calculate the Soundex value of a given String. This method transforms the parameter into a String according to the Soundex algorithm.

Parameters:
word - The String to transform.
Returns:
The Soundex equivalent of the String.

SlavoGermanic

public static final boolean SlavoGermanic(java.lang.String in)
Checks if a given word is slavo-germanic.

Parameters:
in - A String with the word.
Returns:
true if the String corresponds to a slavo-germanic word and false otherwise.

stringAt

private static boolean stringAt(java.lang.String string,
                                int start,
                                int length,
                                java.lang.String[] list)
Checks if part of a given String is equal to any of the String objects supplied in a List.

Parameters:
string - The input String.
start - Starting position of the input String to check.
length - Lengh of the String to check, starting at the given starting position.
list - The List of String objects to check.
Returns:
true if part of a given String is equal to any of the strings supplied in a list and false otherwise.

getDoubleMetaphone

public static java.lang.String getDoubleMetaphone(java.lang.String word)
Calculates the Double Metaphone value of a given String. This method transforms the parameter into a String according to the Double Metaphone algorithm.

Parameters:
word - The String to transform.
Returns:
The Double Metaphone equivalent of the String.