1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.codec.language;
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class Caverphone2 extends AbstractCaverphone {
33
34 private static final String TEN_1 = "1111111111";
35
36
37
38
39
40
41
42
43 @Override
44 public String encode(final String source) {
45 String txt = source;
46 if (SoundexUtils.isEmpty(txt)) {
47 return TEN_1;
48 }
49
50
51 txt = txt.toLowerCase(java.util.Locale.ENGLISH);
52
53
54 txt = txt.replaceAll("[^a-z]", "");
55
56
57 txt = txt.replaceAll("e$", "");
58
59
60 txt = txt.replaceAll("^cough", "cou2f");
61 txt = txt.replaceAll("^rough", "rou2f");
62 txt = txt.replaceAll("^tough", "tou2f");
63 txt = txt.replaceAll("^enough", "enou2f");
64 txt = txt.replaceAll("^trough", "trou2f");
65
66 txt = txt.replaceAll("^gn", "2n");
67
68
69 txt = txt.replaceAll("mb$", "m2");
70
71
72 txt = txt.replace("cq", "2q");
73 txt = txt.replace("ci", "si");
74 txt = txt.replace("ce", "se");
75 txt = txt.replace("cy", "sy");
76 txt = txt.replace("tch", "2ch");
77 txt = txt.replace("c", "k");
78 txt = txt.replace("q", "k");
79 txt = txt.replace("x", "k");
80 txt = txt.replace("v", "f");
81 txt = txt.replace("dg", "2g");
82 txt = txt.replace("tio", "sio");
83 txt = txt.replace("tia", "sia");
84 txt = txt.replace("d", "t");
85 txt = txt.replace("ph", "fh");
86 txt = txt.replace("b", "p");
87 txt = txt.replace("sh", "s2");
88 txt = txt.replace("z", "s");
89 txt = txt.replaceAll("^[aeiou]", "A");
90 txt = txt.replaceAll("[aeiou]", "3");
91 txt = txt.replace("j", "y");
92 txt = txt.replaceAll("^y3", "Y3");
93 txt = txt.replaceAll("^y", "A");
94 txt = txt.replace("y", "3");
95 txt = txt.replace("3gh3", "3kh3");
96 txt = txt.replace("gh", "22");
97 txt = txt.replace("g", "k");
98 txt = txt.replaceAll("s+", "S");
99 txt = txt.replaceAll("t+", "T");
100 txt = txt.replaceAll("p+", "P");
101 txt = txt.replaceAll("k+", "K");
102 txt = txt.replaceAll("f+", "F");
103 txt = txt.replaceAll("m+", "M");
104 txt = txt.replaceAll("n+", "N");
105 txt = txt.replace("w3", "W3");
106 txt = txt.replace("wh3", "Wh3");
107 txt = txt.replaceAll("w$", "3");
108 txt = txt.replace("w", "2");
109 txt = txt.replaceAll("^h", "A");
110 txt = txt.replace("h", "2");
111 txt = txt.replace("r3", "R3");
112 txt = txt.replaceAll("r$", "3");
113 txt = txt.replace("r", "2");
114 txt = txt.replace("l3", "L3");
115 txt = txt.replaceAll("l$", "3");
116 txt = txt.replace("l", "2");
117
118
119 txt = txt.replace("2", "");
120 txt = txt.replaceAll("3$", "A");
121 txt = txt.replace("3", "");
122
123
124 txt += TEN_1;
125
126
127 return txt.substring(0, TEN_1.length());
128 }
129
130 }