Skip to content

Commit

Permalink
reduce processing time of long strings with [nomer append globi-corre…
Browse files Browse the repository at this point in the history
…ct] related to #182
  • Loading branch information
Jorrit Poelen committed Jul 3, 2024
1 parent 42f3f79 commit 5a02185
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

public class AllLowerCaseUndoer implements NameSuggester {

final private Pattern pattern = Pattern.compile("(([a-z]){2,}\\s*)+");
final private Pattern pattern = Pattern.compile("(?<first>[a-z]{2,})(?<remainder>.*)");

@Override
public String suggest(final String name) {
String suggestion = name;
Matcher matcher = pattern.matcher(name);
if (matcher.matches()) {
suggestion = StringUtils.capitalize(StringUtils.lowerCase(name));
suggestion = StringUtils.capitalize(matcher.group("first")) +
matcher.group("remainder");
}
return suggestion;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.eol.globi.taxon;

import org.apache.commons.lang.StringUtils;
import org.junit.Ignore;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -25,4 +27,38 @@ public void doNothing() {
assertThat(corrected, is("Homo Sapiens"));
}

@Test(timeout = 10)
public void longName() {
String aLongName = "7 small acorns or other seed found in cheek pouches during preparation. Seeds are brown, pointed at one end and flattened on the other, 0.75 x 0.6cm.";
String corrected = new AllLowerCaseUndoer().suggest(aLongName);
assertThat(corrected, is(aLongName));
}

@Ignore("this test fails. see https://github.com/globalbioticinteractions/nomer/issues/182")
@Test(timeout = 10)
public void capitalizeLongName() {
String aLongName = "acorns or found cheek pouches during preparation are brown pointed at end flattened the x cm";
String corrected = StringUtils.capitalize(aLongName);
assertThat(corrected, is(aLongName));
}


@Test(timeout = 10)
public void anotherLongName() {
String anotherLongName = "Acorns or found cheek pouches during preparation are brown pointed at end flattened the x cm";
String corrected
= new AllLowerCaseUndoer()
.suggest(anotherLongName);
assertThat(corrected, is(anotherLongName));
}

@Test(timeout = 10)
public void yetAnotherLongName() {
String anotherLongName = "Acorns or found cheek pouches during preparation are brown pointed at end flattened the x cm";
String corrected
= new AllLowerCaseUndoer()
.suggest(anotherLongName);
assertThat(corrected, is(anotherLongName));
}

}

0 comments on commit 5a02185

Please sign in to comment.