import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNodeStatus;
import eu.etaxonomy.cdm.model.term.IdentifierType;
+import eu.etaxonomy.cdm.strategy.cache.agent.TeamDefaultCacheStrategy;
/**
* Classification or taxon tree exporter into WFO Backbone format.
//authorship
//TODO 3 handle empty authorship cache warning
- csvLine[table.getIndex(WfoBackboneExportTable.NAME_AUTHORSHIP)] = normalizedAuthor(name);
+ csvLine[table.getIndex(WfoBackboneExportTable.NAME_AUTHORSHIP)]
+ = normalizedAuthor(state, name);
//family (use familystr if provided, otherwise try to compute from the family taxon
String familyStr = state.getFamilyStr();
return wfoId;
}
- //TODO 2 make it public somewhere in author formatter
- private String normalizedAuthor(TaxonName name) {
- if (isBlank(name.getAuthorshipCache())) {
+ private String normalizedAuthor(WfoBackboneExportState state, TaxonName name) {
+ if (name == null) {
return null;
+ } else if (state.getConfig().isNormalizeAuthorsToIpniStandard()) {
+ return TeamDefaultCacheStrategy.removeWhitespaces(name.getAuthorshipCache());
+ } else {
+ String result = name.getAuthorshipCache();
+ if (result == null) {
+ return null;
+ }else {
+ return result.replaceAll("\\s+", " ").trim();
+ }
}
- String result = name.getAuthorshipCache();
- result = result.replaceAll("\\.\\s+", ".")
- .replaceAll("\\.\\&", ". &")
- .replaceAll("\\.ex\\s+", ". ex ")
- ;
- return result;
}
private Set<TaxonName> getOrthographicVariants(TaxonName name) {
//authorship, take from mainname if it does not exist
//TODO 3 take from csvLine of both names
- if (isBlank(normalizedAuthor(name))) {
- csvLine[table.getIndex(WfoBackboneExportTable.NAME_AUTHORSHIP)] = normalizedAuthor(mainName);
+ if (isBlank(normalizedAuthor(state, name))) {
+ csvLine[table.getIndex(WfoBackboneExportTable.NAME_AUTHORSHIP)]
+ = normalizedAuthor(state, mainName);
}
//nom. ref, take from main name if it does not exist
private String sourceLinkBaseUrl = null;
+ private boolean normalizeAuthorsToIpniStandard = true;
+
private static final WfoBackboneExportTransformer transformer = new WfoBackboneExportTransformer();
//************************* FACTORY ******************************/
public void setSourceLinkBaseUrl(String sourceLinkBaseUrl) {
this.sourceLinkBaseUrl = sourceLinkBaseUrl;
}
+
+ public boolean isNormalizeAuthorsToIpniStandard() {
+ return normalizeAuthorsToIpniStandard;
+ }
+ public void setNormalizeAuthorsToIpniStandard(boolean normalizeAuthorsToIpniStandard) {
+ this.normalizeAuthorsToIpniStandard = normalizeAuthorsToIpniStandard;
+ }
}
\ No newline at end of file
/**
* @author AM
*/
-public class TeamDefaultCacheStrategy extends StrategyBase implements INomenclaturalAuthorCacheStrategy<Team> {
+public class TeamDefaultCacheStrategy
+ extends StrategyBase
+ implements INomenclaturalAuthorCacheStrategy<Team> {
private static final long serialVersionUID = 8375295443642690479L;
@SuppressWarnings("unused")
return str + ET_AL_TEAM_CONCATINATION_ABBREV + "al.";
}
+ /**
+ * Removes the whitespaces in an authorship string
+ * to be compliant with IPNI abbreviated authorship
+ * standard.
+ * @param authorship
+ * @return the authorship without certain whitespaces
+ */
+ public static String removeWhitespaces(String authorship) {
+ if (authorship == null) {
+ return null;
+ }
+ String result = authorship
+ .replaceAll("\\.\\s+", ".") //remove whitespace after "."
+ .replaceAll("\\.\\&", ". &") //... but add whitespace before "&"
+ .replaceAll("\\.ex\\s", ". ex ") //...and add whitespace between "." and "ex "
+ .replaceAll("\\s+", " ") //replace multiple whitespaces by a single one
+ .replaceAll("\\s+,", ",") //remove whitespaces before ","
+ .trim() //trim
+ ;
+ return result;
+ }
+
}
\ No newline at end of file
person1.setGivenName("O.");
Assert.assertEquals("team1 title cache should be P1FN, O.", "P1FN, O.", team1.getTitleCache());
}
+
+ @Test
+ public final void testRemoveWhitespaces() {
+ String author = null;
+ Assert.assertEquals(null, TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = " ";
+ Assert.assertEquals("", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "Mill. ";
+ Assert.assertEquals("Mill.", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = " Miller ";
+ Assert.assertEquals("Result should always be trimed", "Miller", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "A. Mill.";
+ Assert.assertEquals("A.Mill.", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "A. Mill.";
+ Assert.assertEquals("A.Mill.", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "A. Mill.";
+ Assert.assertEquals("A.Mill.", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "A. Mill. & B. Kohl.-Haber";
+ Assert.assertEquals("A.Mill. & B.Kohl.-Haber", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = "A. Mill. ,J. N. Bohl. f.& B. Kohl.-Haber";
+ Assert.assertEquals("A.Mill.,J.N.Bohl.f. & B.Kohl.-Haber", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ author = " (Ab. ex CD. , All , Bet & J.Vall.) A. Mill.ex Kohl.";
+ Assert.assertEquals("(Ab. ex CD., All, Bet & J.Vall.) A.Mill. ex Kohl.", TeamDefaultCacheStrategy.removeWhitespaces(author));
+
+ }
}