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