Skip to content

Commit a5dfe5c

Browse files
committed
[CODEC-84] Double Metaphone bugs in alternative encoding. Apply patch. Thank you Niall.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@800153 13f79535-47bb-0310-9956-ffa450edef68
1 parent d7b0185 commit a5dfe5c

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/java/org/apache/commons/codec/language/DoubleMetaphone.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ private int handleG(String value,
452452
if ((contains(value, 0 ,4, "VAN ", "VON ") || contains(value, 0, 3, "SCH")) || contains(value, index + 1, 2, "ET")) {
453453
//-- obvious germanic --//
454454
result.append('K');
455-
} else if (contains(value, index + 1, 4, "IER")) {
455+
} else if (contains(value, index + 1, 3, "IER")) {
456456
result.append('J');
457457
} else {
458458
result.append('J', 'K');
@@ -561,14 +561,16 @@ private int handleJ(String value, DoubleMetaphoneResult result, int index,
561561
private int handleL(String value,
562562
DoubleMetaphoneResult result,
563563
int index) {
564-
result.append('L');
565564
if (charAt(value, index + 1) == 'L') {
566565
if (conditionL0(value, index)) {
567-
result.appendAlternate(' ');
566+
result.appendPrimary('L');
567+
} else {
568+
result.append('L');
568569
}
569570
index += 2;
570571
} else {
571572
index++;
573+
result.append('L');
572574
}
573575
return index;
574576
}
@@ -857,7 +859,7 @@ private boolean conditionL0(String value, int index) {
857859
if (index == value.length() - 3 &&
858860
contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE")) {
859861
return true;
860-
} else if ((contains(value, index - 1, 2, "AS", "OS") ||
862+
} else if ((contains(value, value.length() - 2, 2, "AS", "OS") ||
861863
contains(value, value.length() - 1, 1, "A", "O")) &&
862864
contains(value, index - 1, 4, "ALLE")) {
863865
return true;
@@ -1002,10 +1004,9 @@ private static boolean contains(String value, int start, int length,
10021004
}
10031005

10041006
/**
1005-
* Determines whether <code>value</code> contains any of the criteria
1006-
starting
1007-
* at index <code>start</code> and matching up to length <code>length</code>
1008-
*/
1007+
* Determines whether <code>value</code> contains any of the criteria starting at index <code>start</code> and
1008+
* matching up to length <code>length</code>
1009+
*/
10091010
protected static boolean contains(String value, int start, int length,
10101011
String[] criteria) {
10111012
boolean result = false;

src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void testDoubleMetaphoneAlternate() {
106106
new String[] {"Andrews", "ANTR", "ANTR"},
107107
new String[] {"Andreyco", "ANTR", "ANTR"},
108108
new String[] {"Andriesse", "ANTR", "ANTR"},
109-
// new String[] {"Angier", "ANJ", "ANJR"}, /* Failing Secondary, result=ANKR */
109+
new String[] {"Angier", "ANJ", "ANJR"},
110110
new String[] {"Annabel", "ANPL", "ANPL"},
111111
new String[] {"Anne", "AN", "AN"},
112112
new String[] {"Anstye", "ANST", "ANST"},
@@ -1232,7 +1232,7 @@ public void testDoubleMetaphoneAlternate() {
12321232
new String[] {"bough", "P", "P"},
12331233
new String[] {"breaux", "PR", "PR"},
12341234
new String[] {"broughton", "PRTN", "PRTN"},
1235-
// new String[] {"cabrillo", "KPRL", "KPR"}, /* Failing Secondary, result=KPRL */
1235+
new String[] {"cabrillo", "KPRL", "KPR"},
12361236
new String[] {"caesar", "SSR", "SSR"},
12371237
new String[] {"cagney", "KKN", "KKN"},
12381238
new String[] {"campbell", "KMPL", "KMPL"},
@@ -1249,7 +1249,7 @@ public void testDoubleMetaphoneAlternate() {
12491249
new String[] {"edge", "AJ", "AJ"},
12501250
new String[] {"filipowicz", "FLPT", "FLPF"},
12511251
new String[] {"focaccia", "FKX", "FKX"},
1252-
// new String[] {"gallegos", "KLKS", "KKS"}, /* Failing Secondary, result=KLKS */
1252+
new String[] {"gallegos", "KLKS", "KKS"},
12531253
new String[] {"gambrelli", "KMPR", "KMPR"},
12541254
new String[] {"geithain", "K0N", "JTN"},
12551255
new String[] {"ghiradelli", "JRTL", "JRTL"},
@@ -1272,7 +1272,7 @@ public void testDoubleMetaphoneAlternate() {
12721272
new String[] {"queen", "KN", "KN"},
12731273
new String[] {"raspberry", "RSPR", "RSPR"},
12741274
new String[] {"resnais", "RSN", "RSNS"},
1275-
// new String[] {"rogier", "RJ", "RJR"}, /* Failing Secondary, result=RKR */
1275+
new String[] {"rogier", "RJ", "RJR"},
12761276
new String[] {"rough", "RF", "RF"},
12771277
new String[] {"san jacinto", "SNHS", "SNHS"},
12781278
new String[] {"schenker", "XNKR", "SKNK"},

0 commit comments

Comments
 (0)