Skip to content

Commit 4504196

Browse files
committed
[CODEC-125] Implement a Beider-Morse phonetic matching codec. Apply Matthew's patch https://issues.apache.org/jira/secure/attachment/12489569/fixmeInvariant.patch. This patch hoists the l-invariant code out of the loop over l. The d'ortley test input string exercises this branch. The "van helsing" input string should be exercising the alternate branch. Thank you MP!
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1154541 13f79535-47bb-0310-9956-ffa450edef68
1 parent dfff43a commit 4504196

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

src/java/org/apache/commons/codec/language/bm/PhoneticEngine.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
287287
input = input.toLowerCase(Locale.ENGLISH).replace('-', ' ').trim();
288288

289289
if (this.nameType == NameType.GENERIC) {
290+
if (input.length() >= 2 && input.substring(0, 2).equals("d'")) { // check for d'
291+
String remainder = input.substring(2);
292+
String combined = "d" + remainder;
293+
return "(" + encode(remainder) + ")-(" + encode(combined) + ")";
294+
}
290295
for (String l : NAME_PREFIXES.get(this.nameType)) {
291296
// handle generic prefixes
292297
if (input.startsWith(l + " ")) {
@@ -295,12 +300,6 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
295300
String combined = l + remainder; // input with prefix without space
296301
return "(" + encode(remainder) + ")-(" + encode(combined) + ")";
297302
}
298-
// fixme: this case is invariant on l
299-
else if (input.length() >= 2 && input.substring(0, 2).equals("d'")) { // check for d'
300-
String remainder = input.substring(2);
301-
String combined = "d" + remainder;
302-
return "(" + encode(remainder) + ")-(" + encode(combined) + ")";
303-
}
304303
}
305304
}
306305

0 commit comments

Comments
 (0)