Author: ggregory
Date: Sun Aug 2 22:45:30 2009
New Revision: 800153
URL: http://svn.apache.org/viewvc?rev=800153&view=rev
Log:
[CODEC-84] Double Metaphone bugs in alternative encoding. Apply patch. Thank you Niall.
Modified:
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java
Modified: commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java?rev=800153&r1=800152&r2=800153&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
(original)
+++ commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/DoubleMetaphone.java
Sun Aug 2 22:45:30 2009
@@ -452,7 +452,7 @@
if ((contains(value, 0 ,4, "VAN ", "VON ") || contains(value, 0, 3, "SCH")) ||
contains(value, index + 1, 2, "ET")) {
//-- obvious germanic --//
result.append('K');
- } else if (contains(value, index + 1, 4, "IER")) {
+ } else if (contains(value, index + 1, 3, "IER")) {
result.append('J');
} else {
result.append('J', 'K');
@@ -561,14 +561,16 @@
private int handleL(String value,
DoubleMetaphoneResult result,
int index) {
- result.append('L');
if (charAt(value, index + 1) == 'L') {
if (conditionL0(value, index)) {
- result.appendAlternate(' ');
+ result.appendPrimary('L');
+ } else {
+ result.append('L');
}
index += 2;
} else {
index++;
+ result.append('L');
}
return index;
}
@@ -857,7 +859,7 @@
if (index == value.length() - 3 &&
contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE")) {
return true;
- } else if ((contains(value, index - 1, 2, "AS", "OS") ||
+ } else if ((contains(value, value.length() - 2, 2, "AS", "OS") ||
contains(value, value.length() - 1, 1, "A", "O")) &&
contains(value, index - 1, 4, "ALLE")) {
return true;
@@ -1002,10 +1004,9 @@
}
/**
- * Determines whether <code>value</code> contains any of the criteria
- starting
- * at index <code>start</code> and matching up to length <code>length</code>
- */
+ * Determines whether <code>value</code> contains any of the criteria starting
at index <code>start</code> and
+ * matching up to length <code>length</code>
+ */
protected static boolean contains(String value, int start, int length,
String[] criteria) {
boolean result = false;
Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java?rev=800153&r1=800152&r2=800153&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/language/DoubleMetaphone2Test.java
Sun Aug 2 22:45:30 2009
@@ -106,7 +106,7 @@
new String[] {"Andrews", "ANTR", "ANTR"},
new String[] {"Andreyco", "ANTR", "ANTR"},
new String[] {"Andriesse", "ANTR", "ANTR"},
-// new String[] {"Angier", "ANJ", "ANJR"}, /* Failing Secondary, result=ANKR
*/
+ new String[] {"Angier", "ANJ", "ANJR"},
new String[] {"Annabel", "ANPL", "ANPL"},
new String[] {"Anne", "AN", "AN"},
new String[] {"Anstye", "ANST", "ANST"},
@@ -1232,7 +1232,7 @@
new String[] {"bough", "P", "P"},
new String[] {"breaux", "PR", "PR"},
new String[] {"broughton", "PRTN", "PRTN"},
-// new String[] {"cabrillo", "KPRL", "KPR"}, /* Failing Secondary, result=KPRL
*/
+ new String[] {"cabrillo", "KPRL", "KPR"},
new String[] {"caesar", "SSR", "SSR"},
new String[] {"cagney", "KKN", "KKN"},
new String[] {"campbell", "KMPL", "KMPL"},
@@ -1249,7 +1249,7 @@
new String[] {"edge", "AJ", "AJ"},
new String[] {"filipowicz", "FLPT", "FLPF"},
new String[] {"focaccia", "FKX", "FKX"},
-// new String[] {"gallegos", "KLKS", "KKS"}, /* Failing Secondary, result=KLKS
*/
+ new String[] {"gallegos", "KLKS", "KKS"},
new String[] {"gambrelli", "KMPR", "KMPR"},
new String[] {"geithain", "K0N", "JTN"},
new String[] {"ghiradelli", "JRTL", "JRTL"},
@@ -1272,7 +1272,7 @@
new String[] {"queen", "KN", "KN"},
new String[] {"raspberry", "RSPR", "RSPR"},
new String[] {"resnais", "RSN", "RSNS"},
-// new String[] {"rogier", "RJ", "RJR"}, /* Failing Secondary, result=RKR */
+ new String[] {"rogier", "RJ", "RJR"},
new String[] {"rough", "RF", "RF"},
new String[] {"san jacinto", "SNHS", "SNHS"},
new String[] {"schenker", "XNKR", "SKNK"},
|