1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.strategy.cache.name;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.Iterator;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
|
20
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
21
|
import eu.etaxonomy.cdm.common.UTF8;
|
22
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23
|
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
26
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
27
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
28
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
29
|
import eu.etaxonomy.cdm.model.name.Rank;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
31
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
32
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
33
|
import eu.etaxonomy.cdm.model.term.Representation;
|
34
|
import eu.etaxonomy.cdm.ref.TypedEntityReference;
|
35
|
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
|
36
|
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
|
37
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
38
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImplRegExBase;
|
39
|
|
40
|
|
41
|
/**
|
42
|
* This class is a default implementation for the INonViralNameCacheStrategy<T extends NonViralName>
|
43
|
* interface.<BR>
|
44
|
* The method implements a cache strategy for botanical names so no method has to be overwritten by
|
45
|
* a subclass for botanic names.
|
46
|
* Where differing from this default botanic name strategy other subclasses should overwrite the
|
47
|
* existing methods, e.g. a CacheStrategy for zoological names should overwrite getAuthorAndExAuthor
|
48
|
* @author a.mueller
|
49
|
*/
|
50
|
public class TaxonNameDefaultCacheStrategy
|
51
|
extends NameCacheStrategyBase
|
52
|
implements INonViralNameCacheStrategy {
|
53
|
|
54
|
private static final Logger logger = Logger.getLogger(TaxonNameDefaultCacheStrategy.class);
|
55
|
private static final long serialVersionUID = -6577757501563212669L;
|
56
|
|
57
|
final static UUID uuid = UUID.fromString("1cdda0d1-d5bc-480f-bf08-40a510a2f223");
|
58
|
|
59
|
protected String nameAuthorSeperator = " ";
|
60
|
protected String basionymStart = "(";
|
61
|
protected String basionymEnd = ")";
|
62
|
protected String exAuthorSeperator = " ex ";
|
63
|
private static String NOTHO = "notho";
|
64
|
protected CharSequence basionymAuthorCombinationAuthorSeperator = " ";
|
65
|
|
66
|
protected String zooAuthorYearSeperator = ", ";
|
67
|
|
68
|
@Override
|
69
|
public UUID getUuid(){
|
70
|
return uuid;
|
71
|
}
|
72
|
|
73
|
// ************************** FACTORY ******************************/
|
74
|
|
75
|
public static TaxonNameDefaultCacheStrategy NewInstance(){
|
76
|
return new TaxonNameDefaultCacheStrategy();
|
77
|
}
|
78
|
|
79
|
|
80
|
// ************ CONSTRUCTOR *******************/
|
81
|
|
82
|
protected TaxonNameDefaultCacheStrategy(){
|
83
|
super();
|
84
|
}
|
85
|
|
86
|
/* **************** GETTER / SETTER **************************************/
|
87
|
|
88
|
/**
|
89
|
* String that separates the NameCache part from the AuthorCache part
|
90
|
* @return
|
91
|
*/
|
92
|
public String getNameAuthorSeperator() {
|
93
|
return nameAuthorSeperator;
|
94
|
}
|
95
|
public void setNameAuthorSeperator(String nameAuthorSeperator) {
|
96
|
this.nameAuthorSeperator = nameAuthorSeperator;
|
97
|
}
|
98
|
|
99
|
|
100
|
/**
|
101
|
* String the basionym author part starts with e.g. '('.
|
102
|
* This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymEnd() basionymEnd} attribute
|
103
|
* @return
|
104
|
*/
|
105
|
public String getBasionymStart() {
|
106
|
return basionymStart;
|
107
|
}
|
108
|
public void setBasionymStart(String basionymStart) {
|
109
|
this.basionymStart = basionymStart;
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* String the basionym author part ends with e.g. ')'.
|
114
|
* This should correspond with the {@link TaxonNameDefaultCacheStrategy#getBasionymStart() basionymStart} attribute
|
115
|
* @return
|
116
|
*/
|
117
|
public String getBasionymEnd() {
|
118
|
return basionymEnd;
|
119
|
}
|
120
|
public void setBasionymEnd(String basionymEnd) {
|
121
|
this.basionymEnd = basionymEnd;
|
122
|
}
|
123
|
|
124
|
|
125
|
/**
|
126
|
* String to separate ex author from author.
|
127
|
* @return
|
128
|
*/
|
129
|
public String getExAuthorSeperator() {
|
130
|
return exAuthorSeperator;
|
131
|
}
|
132
|
public void setExAuthorSeperator(String exAuthorSeperator) {
|
133
|
this.exAuthorSeperator = exAuthorSeperator;
|
134
|
}
|
135
|
|
136
|
|
137
|
/**
|
138
|
* String that separates the basionym/original_combination author part from the combination author part
|
139
|
* @return
|
140
|
*/
|
141
|
public CharSequence getBasionymAuthorCombinationAuthorSeperator() {
|
142
|
return basionymAuthorCombinationAuthorSeperator;
|
143
|
}
|
144
|
|
145
|
|
146
|
public void setBasionymAuthorCombinationAuthorSeperator( CharSequence basionymAuthorCombinationAuthorSeperator) {
|
147
|
this.basionymAuthorCombinationAuthorSeperator = basionymAuthorCombinationAuthorSeperator;
|
148
|
}
|
149
|
|
150
|
public String getZooAuthorYearSeperator() {
|
151
|
return zooAuthorYearSeperator;
|
152
|
}
|
153
|
public void setZooAuthorYearSeperator(String authorYearSeperator) {
|
154
|
this.zooAuthorYearSeperator = authorYearSeperator;
|
155
|
}
|
156
|
|
157
|
// ******************* Authorship ******************************/
|
158
|
|
159
|
@Override
|
160
|
public String getAuthorshipCache(TaxonName taxonName) {
|
161
|
if (taxonName == null){
|
162
|
return null;
|
163
|
}else if (taxonName.getNameType().isViral()){
|
164
|
return null;
|
165
|
}else if(taxonName.isProtectedAuthorshipCache() == true) {
|
166
|
//cache protected
|
167
|
return taxonName.getAuthorshipCache();
|
168
|
}else{
|
169
|
return getNonCacheAuthorshipCache(taxonName);
|
170
|
}
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Returns the authorshipcache string for the atomized authorship fields. Does not use the authorship field.
|
175
|
* @throws NullPointerException if nonViralName is null.
|
176
|
* @param taxonName
|
177
|
* @return
|
178
|
*/
|
179
|
protected String getNonCacheAuthorshipCache(TaxonName nonViralName){
|
180
|
if (nonViralName.getNameType().isZoological()){
|
181
|
return this.getZoologicalNonCacheAuthorshipCache(nonViralName);
|
182
|
}else{
|
183
|
String result = "";
|
184
|
INomenclaturalAuthor combinationAuthor = nonViralName.getCombinationAuthorship();
|
185
|
INomenclaturalAuthor exCombinationAuthor = nonViralName.getExCombinationAuthorship();
|
186
|
INomenclaturalAuthor basionymAuthor = nonViralName.getBasionymAuthorship();
|
187
|
INomenclaturalAuthor exBasionymAuthor = nonViralName.getExBasionymAuthorship();
|
188
|
String basionymPart = "";
|
189
|
String authorPart = "";
|
190
|
//basionym
|
191
|
if (basionymAuthor != null || exBasionymAuthor != null){
|
192
|
basionymPart = basionymStart + getAuthorAndExAuthor(basionymAuthor, exBasionymAuthor) + basionymEnd;
|
193
|
}
|
194
|
if (combinationAuthor != null || exCombinationAuthor != null){
|
195
|
authorPart = getAuthorAndExAuthor(combinationAuthor, exCombinationAuthor);
|
196
|
}
|
197
|
result = CdmUtils.concat(basionymAuthorCombinationAuthorSeperator, basionymPart, authorPart);
|
198
|
// if ("".equals(result)){
|
199
|
// result = null;
|
200
|
// }
|
201
|
return result;
|
202
|
}
|
203
|
}
|
204
|
|
205
|
protected String getZoologicalNonCacheAuthorshipCache(TaxonName nonViralName) {
|
206
|
if (nonViralName == null){
|
207
|
return null;
|
208
|
}
|
209
|
String result = "";
|
210
|
INomenclaturalAuthor combinationAuthor = nonViralName.getCombinationAuthorship();
|
211
|
INomenclaturalAuthor exCombinationAuthor = nonViralName.getExCombinationAuthorship();
|
212
|
INomenclaturalAuthor basionymAuthor = nonViralName.getBasionymAuthorship();
|
213
|
INomenclaturalAuthor exBasionymAuthor = nonViralName.getExBasionymAuthorship();
|
214
|
Integer publicationYear = nonViralName.getPublicationYear();
|
215
|
Integer originalPublicationYear = nonViralName.getOriginalPublicationYear();
|
216
|
|
217
|
String basionymPart = "";
|
218
|
String authorPart = "";
|
219
|
//basionym
|
220
|
if (basionymAuthor != null || exBasionymAuthor != null || originalPublicationYear != null ){
|
221
|
String authorAndEx = getAuthorAndExAuthor(basionymAuthor, exBasionymAuthor);
|
222
|
String originalPublicationYearString = originalPublicationYear == null ? null : String.valueOf(originalPublicationYear);
|
223
|
String authorAndExAndYear = CdmUtils.concat(zooAuthorYearSeperator, authorAndEx, originalPublicationYearString );
|
224
|
basionymPart = basionymStart + authorAndExAndYear + basionymEnd;
|
225
|
}
|
226
|
if (combinationAuthor != null || exCombinationAuthor != null){
|
227
|
String authorAndEx = getAuthorAndExAuthor(combinationAuthor, exCombinationAuthor);
|
228
|
String publicationYearString = publicationYear == null ? null : String.valueOf(publicationYear);
|
229
|
authorPart = CdmUtils.concat(zooAuthorYearSeperator, authorAndEx, publicationYearString);
|
230
|
}
|
231
|
result = CdmUtils.concat(basionymAuthorCombinationAuthorSeperator, basionymPart, authorPart);
|
232
|
if (result == null){
|
233
|
result = "";
|
234
|
}
|
235
|
return result;
|
236
|
}
|
237
|
|
238
|
|
239
|
/**
|
240
|
* Returns the AuthorCache part for a combination of an author and an ex author. This applies on
|
241
|
* combination authors as well as on basionym/orginal combination authors.
|
242
|
* The correct order is exAuthor ex author though some botanist do not know about and do it the
|
243
|
* other way round. (see 46.4-46.6 ICBN (Vienna Code, 2006))
|
244
|
*
|
245
|
* @param author the author
|
246
|
* @param exAuthor the ex-author
|
247
|
* @return
|
248
|
*/
|
249
|
protected String getAuthorAndExAuthor(INomenclaturalAuthor author, INomenclaturalAuthor exAuthor){
|
250
|
String authorString = "";
|
251
|
String exAuthorString = "";
|
252
|
if (author != null){
|
253
|
authorString = CdmUtils.Nz(author.getNomenclaturalTitle());
|
254
|
}
|
255
|
if (exAuthor != null){
|
256
|
exAuthorString = CdmUtils.Nz(exAuthor.getNomenclaturalTitle());
|
257
|
exAuthorString += exAuthorSeperator;
|
258
|
}
|
259
|
String result = exAuthorString + authorString;
|
260
|
return result;
|
261
|
}
|
262
|
|
263
|
|
264
|
|
265
|
/**
|
266
|
* Checks if the given name should include the author in it's cached version.<BR>
|
267
|
* This is usually the case but not for <i>species aggregates</i>.
|
268
|
* @param nonViralName
|
269
|
* @return
|
270
|
*/
|
271
|
protected boolean nameIncludesAuthorship(INonViralName nonViralName){
|
272
|
Rank rank = nonViralName.getRank();
|
273
|
if (rank != null && rank.isSpeciesAggregate()){
|
274
|
return false;
|
275
|
}else{
|
276
|
return true;
|
277
|
}
|
278
|
}
|
279
|
|
280
|
// ************* TAGGED NAME ***************************************/
|
281
|
|
282
|
@Override
|
283
|
public List<TaggedText> getTaggedFullTitle(TaxonName nonViralName) {
|
284
|
List<TaggedText> tags = new ArrayList<>();
|
285
|
|
286
|
//null
|
287
|
if (nonViralName == null){
|
288
|
return null;
|
289
|
}
|
290
|
|
291
|
//protected full title cache
|
292
|
if (nonViralName.isProtectedFullTitleCache()){
|
293
|
tags.add(new TaggedText(TagEnum.fullName, nonViralName.getFullTitleCache()));
|
294
|
return tags;
|
295
|
}
|
296
|
|
297
|
//title cache
|
298
|
// String titleCache = nonViralName.getTitleCache();
|
299
|
List<TaggedText> titleTags = getTaggedTitle(nonViralName);
|
300
|
tags.addAll(titleTags);
|
301
|
|
302
|
//reference
|
303
|
String microReference = nonViralName.getNomenclaturalMicroReference();
|
304
|
INomenclaturalReference ref = nonViralName.getNomenclaturalReference();
|
305
|
String referenceCache = null;
|
306
|
if (ref != null){
|
307
|
Reference reference = HibernateProxyHelper.deproxy(ref, Reference.class);
|
308
|
referenceCache = reference.getNomenclaturalCitation(microReference);
|
309
|
}
|
310
|
//add to tags
|
311
|
if (isNotBlank(referenceCache)){
|
312
|
if (! referenceCache.trim().startsWith("in ")){
|
313
|
String refConcat = ", ";
|
314
|
tags.add(new TaggedText(TagEnum.separator, refConcat));
|
315
|
}
|
316
|
tags.add(new TaggedText(TagEnum.reference, referenceCache));
|
317
|
}
|
318
|
|
319
|
addOriginalSpelling(tags, nonViralName);
|
320
|
|
321
|
//nomenclatural status
|
322
|
tags.addAll(getNomStatusTags(nonViralName, true, false));
|
323
|
return tags;
|
324
|
|
325
|
}
|
326
|
|
327
|
|
328
|
/**
|
329
|
* @param nonViralName
|
330
|
* @param tags
|
331
|
* @return
|
332
|
*/
|
333
|
@Override
|
334
|
public List<TaggedText> getNomStatusTags(TaxonName nonViralName, boolean includeSeparatorBefore,
|
335
|
boolean includeSeparatorAfter) {
|
336
|
|
337
|
Set<NomenclaturalStatus> ncStati = nonViralName.getStatus();
|
338
|
Iterator<NomenclaturalStatus> iterator = ncStati.iterator();
|
339
|
List<TaggedText> nomStatusTags = new ArrayList<>();
|
340
|
while (iterator.hasNext()) {
|
341
|
NomenclaturalStatus ncStatus = iterator.next();
|
342
|
// since the NewInstance method of nomencatural status allows null as parameter
|
343
|
// we have to check for null values here
|
344
|
String nomStatusStr = "not defined";
|
345
|
if(ncStatus.getType() != null){
|
346
|
NomenclaturalStatusType statusType = ncStatus.getType();
|
347
|
List<Language> prefLangs = Arrays.asList(new Language[]{Language.LATIN(), Language.DEFAULT()});
|
348
|
Representation repr = statusType.getPreferredRepresentation(prefLangs);
|
349
|
if (repr != null){
|
350
|
if(!Language.LATIN().equals(repr.getLanguage())){
|
351
|
String message = "No latin representation available for nom. status. " + statusType.getTitleCache();
|
352
|
logger.info(message);
|
353
|
}
|
354
|
nomStatusStr = repr.getAbbreviatedLabel();
|
355
|
}else{
|
356
|
String message = "No representation available for nom. status. " + statusType.getTitleCache();
|
357
|
logger.warn(message);
|
358
|
nomStatusStr = statusType.getTitleCache();
|
359
|
}
|
360
|
}else if(isNotBlank(ncStatus.getRuleConsidered())){
|
361
|
nomStatusStr = ncStatus.getRuleConsidered();
|
362
|
}
|
363
|
String statusSeparator = ", ";
|
364
|
if (includeSeparatorBefore){
|
365
|
nomStatusTags.add(new TaggedText(TagEnum.separator, statusSeparator));
|
366
|
}
|
367
|
nomStatusTags.add(new TaggedText(TagEnum.nomStatus, nomStatusStr, new TypedEntityReference<>(ncStatus.getClass(), ncStatus.getUuid())));
|
368
|
if (includeSeparatorAfter){
|
369
|
nomStatusTags.add(new TaggedText(TagEnum.postSeparator, ","));
|
370
|
}
|
371
|
}
|
372
|
return nomStatusTags;
|
373
|
}
|
374
|
|
375
|
@Override
|
376
|
public List<TaggedText> getTaggedTitle(TaxonName taxonName) {
|
377
|
if (taxonName == null){
|
378
|
return null;
|
379
|
}
|
380
|
|
381
|
List<TaggedText> tags = new ArrayList<>();
|
382
|
|
383
|
if (taxonName.isViral()){
|
384
|
return getViralTaggedTitle(taxonName);
|
385
|
}
|
386
|
//TODO how to handle protected fullTitleCache here?
|
387
|
if (taxonName.isProtectedTitleCache()){
|
388
|
//protected title cache
|
389
|
tags.add(new TaggedText(TagEnum.name, taxonName.getTitleCache()));
|
390
|
return tags;
|
391
|
}else if (taxonName.isHybridFormula()){
|
392
|
//hybrid formula
|
393
|
String hybridSeparator = NonViralNameParserImplRegExBase.hybridSign;
|
394
|
boolean isFirst = true;
|
395
|
List<HybridRelationship> rels = taxonName.getOrderedChildRelationships();
|
396
|
for (HybridRelationship rel: rels){
|
397
|
if (! isFirst){
|
398
|
tags.add(new TaggedText(TagEnum.hybridSign, hybridSeparator));
|
399
|
}
|
400
|
isFirst = false;
|
401
|
tags.addAll(getTaggedTitle(rel.getParentName()));
|
402
|
}
|
403
|
return tags;
|
404
|
}else if (taxonName.isAutonym()){
|
405
|
//Autonym
|
406
|
tags.addAll(handleTaggedAutonym(taxonName));
|
407
|
}else{ //not Autonym
|
408
|
List<TaggedText> nameTags = getTaggedName(taxonName);
|
409
|
tags.addAll(nameTags);
|
410
|
String authorCache = getAuthorshipCache(taxonName);
|
411
|
if (isNotBlank(authorCache)){
|
412
|
tags.add(new TaggedText(TagEnum.authors, authorCache));
|
413
|
}
|
414
|
}
|
415
|
|
416
|
return tags;
|
417
|
}
|
418
|
|
419
|
/**
|
420
|
* @param taxonName
|
421
|
* @return
|
422
|
*/
|
423
|
private List<TaggedText> getViralTaggedTitle(TaxonName viralName) {
|
424
|
List<TaggedText> tags = new ArrayList<>();
|
425
|
if (viralName.isProtectedTitleCache()){
|
426
|
//protected title cache
|
427
|
tags.add(new TaggedText(TagEnum.name, viralName.getTitleCache()));
|
428
|
return tags;
|
429
|
}else{
|
430
|
if (isNotBlank(viralName.getAcronym())){
|
431
|
//this is not according to the code
|
432
|
tags.add(new TaggedText(TagEnum.name, viralName.getAcronym()));
|
433
|
}
|
434
|
return tags;
|
435
|
}
|
436
|
}
|
437
|
|
438
|
/**
|
439
|
* Returns the tag list of the name part (without author and reference).
|
440
|
* @param nonViralName
|
441
|
* @return
|
442
|
*/
|
443
|
@Override
|
444
|
public List<TaggedText> getTaggedName(TaxonName nonViralName) {
|
445
|
if (nonViralName == null){
|
446
|
return null;
|
447
|
}else if (nonViralName.isViral()){
|
448
|
return null;
|
449
|
}
|
450
|
List<TaggedText> tags = new ArrayList<>();
|
451
|
Rank rank = nonViralName.getRank();
|
452
|
|
453
|
if (nonViralName.isProtectedNameCache()){
|
454
|
tags.add(new TaggedText(TagEnum.name, nonViralName.getNameCache()));
|
455
|
}else if (nonViralName.isHybridFormula()){
|
456
|
//hybrid formula
|
457
|
String hybridSeparator = NonViralNameParserImplRegExBase.hybridSign;
|
458
|
boolean isFirst = true;
|
459
|
List<HybridRelationship> rels = nonViralName.getOrderedChildRelationships();
|
460
|
for (HybridRelationship rel: rels){
|
461
|
if (! isFirst){
|
462
|
tags.add(new TaggedText(TagEnum.hybridSign, hybridSeparator));
|
463
|
}
|
464
|
isFirst = false;
|
465
|
tags.addAll(getTaggedName(rel.getParentName()));
|
466
|
}
|
467
|
return tags;
|
468
|
|
469
|
}else if (rank == null){
|
470
|
tags = getRanklessTaggedNameCache(nonViralName);
|
471
|
// }else if (nonViralName.isInfragenericUnranked()){
|
472
|
// result = getUnrankedInfragenericNameCache(nonViralName);
|
473
|
}else if (rank.isInfraSpecific()){
|
474
|
tags = getInfraSpeciesTaggedNameCache(nonViralName);
|
475
|
}else if (rank.isSpecies() || isAggregateWithAuthorship(nonViralName, rank) ){ //exception see #4288
|
476
|
tags = getSpeciesTaggedNameCache(nonViralName);
|
477
|
}else if (rank.isInfraGeneric()){
|
478
|
tags = getInfraGenusTaggedNameCache(nonViralName);
|
479
|
}else if (rank.isGenus()){
|
480
|
tags = getGenusOrUninomialTaggedNameCache(nonViralName);
|
481
|
}else if (rank.isSupraGeneric()){
|
482
|
tags = getGenusOrUninomialTaggedNameCache(nonViralName);
|
483
|
}else{
|
484
|
tags = getRanklessTaggedNameCache(nonViralName);
|
485
|
logger.warn("Rank does not belong to a rank class: " + rank.getTitleCache() + ". Used rankless nameCache for name " + nonViralName.getUuid());
|
486
|
}
|
487
|
//TODO handle appended phrase here instead of different places, check first if this is true for all
|
488
|
//cases
|
489
|
|
490
|
return tags;
|
491
|
|
492
|
}
|
493
|
|
494
|
|
495
|
|
496
|
|
497
|
//***************************** PRIVATES ***************************************/
|
498
|
|
499
|
|
500
|
private boolean isAggregateWithAuthorship(TaxonName nonViralName, Rank rank) {
|
501
|
if (rank == null){
|
502
|
return false;
|
503
|
}else{
|
504
|
return rank.isSpeciesAggregate() && ( isNotBlank(nonViralName.getAuthorshipCache()) || nonViralName.getNomenclaturalReference() != null );
|
505
|
}
|
506
|
}
|
507
|
|
508
|
|
509
|
/**
|
510
|
* Returns the tag list for an autonym taxon.
|
511
|
*
|
512
|
* @see NonViralName#isAutonym()
|
513
|
* @see BotanicalName#isAutonym()
|
514
|
* @param nonViralName
|
515
|
* @return
|
516
|
*/
|
517
|
private List<TaggedText> handleTaggedAutonym(TaxonName nonViralName) {
|
518
|
List<TaggedText> tags = null;
|
519
|
if (nonViralName.isInfraSpecific()){
|
520
|
//species part
|
521
|
tags = getSpeciesTaggedNameCache(nonViralName);
|
522
|
|
523
|
//author
|
524
|
String authorCache = getAuthorshipCache(nonViralName);
|
525
|
if (isNotBlank(authorCache)){
|
526
|
tags.add(new TaggedText(TagEnum.authors, authorCache));
|
527
|
}
|
528
|
|
529
|
//infra species marker
|
530
|
if (nonViralName.getRank() == null || !nonViralName.getRank().isInfraSpecific()){
|
531
|
//TODO handle exception
|
532
|
logger.warn("Rank for autonym does not exist or is not lower than species !!");
|
533
|
}else{
|
534
|
String infraSpeciesMarker = nonViralName.getRank().getAbbreviation();
|
535
|
if (nonViralName.isTrinomHybrid()){
|
536
|
infraSpeciesMarker = CdmUtils.concat("", NOTHO, infraSpeciesMarker);
|
537
|
}
|
538
|
if (isNotBlank(infraSpeciesMarker)){
|
539
|
tags.add(new TaggedText(TagEnum.rank, infraSpeciesMarker));
|
540
|
}
|
541
|
}
|
542
|
|
543
|
//infra species
|
544
|
String infraSpeciesPart = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet()).trim();
|
545
|
if (isNotBlank(infraSpeciesPart)){
|
546
|
tags.add(new TaggedText(TagEnum.name, infraSpeciesPart));
|
547
|
}
|
548
|
|
549
|
} else if (nonViralName.isInfraGeneric()){
|
550
|
//genus part
|
551
|
tags =getGenusOrUninomialTaggedNameCache(nonViralName);
|
552
|
|
553
|
//author
|
554
|
String authorCache = getAuthorshipCache(nonViralName);
|
555
|
if (isNotBlank(authorCache)){
|
556
|
tags.add(new TaggedText(TagEnum.authors, authorCache));
|
557
|
}
|
558
|
|
559
|
//infra species marker
|
560
|
if (nonViralName.getRank() == null || !nonViralName.getRank().isInfraGeneric()){
|
561
|
//TODO handle exception
|
562
|
logger.warn("Rank for autonym does not exist or is not lower than species !!");
|
563
|
}else{
|
564
|
Rank rank = nonViralName.getRank();
|
565
|
String infraGenericMarker = rank.getAbbreviation();
|
566
|
if (rank.equals(Rank.SECTION_BOTANY()) || rank.equals(Rank.SUBSECTION_BOTANY())){
|
567
|
infraGenericMarker = infraGenericMarker.replace("(bot.)", "");
|
568
|
}
|
569
|
if (isNotBlank(infraGenericMarker)){
|
570
|
tags.add(new TaggedText(TagEnum.rank, infraGenericMarker));
|
571
|
}
|
572
|
}
|
573
|
|
574
|
//infra genus
|
575
|
String infraGenericPart = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim();
|
576
|
if (isNotBlank(infraGenericPart)){
|
577
|
tags.add(new TaggedText(TagEnum.name, infraGenericPart));
|
578
|
}
|
579
|
}
|
580
|
|
581
|
return tags;
|
582
|
}
|
583
|
|
584
|
|
585
|
|
586
|
/**
|
587
|
* Returns the tag list for rankless taxa.
|
588
|
* @param nonViralName
|
589
|
* @return
|
590
|
*/
|
591
|
protected List<TaggedText> getRanklessTaggedNameCache(INonViralName nonViralName){
|
592
|
List<TaggedText> tags = getUninomialTaggedPart(nonViralName);
|
593
|
String speciesEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim();
|
594
|
if (isNotBlank(speciesEpi)){
|
595
|
tags.add(new TaggedText(TagEnum.name, speciesEpi));
|
596
|
}
|
597
|
|
598
|
String infraSpeciesEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet());
|
599
|
if (isNotBlank(infraSpeciesEpi)){
|
600
|
tags.add(new TaggedText(TagEnum.name, infraSpeciesEpi));
|
601
|
}
|
602
|
|
603
|
//result += " (rankless)";
|
604
|
addAppendedTaggedPhrase(tags, nonViralName);
|
605
|
return tags;
|
606
|
}
|
607
|
|
608
|
/**
|
609
|
* Returns the tag list for the first epithet (including a hybrid sign if required).
|
610
|
* @param nonViralName
|
611
|
* @return
|
612
|
*/
|
613
|
private List<TaggedText> getUninomialTaggedPart(INonViralName nonViralName) {
|
614
|
List<TaggedText> tags = new ArrayList<>();
|
615
|
|
616
|
if (nonViralName.isMonomHybrid()){
|
617
|
addHybridPrefix(tags);
|
618
|
}
|
619
|
|
620
|
String uninomial = CdmUtils.Nz(nonViralName.getGenusOrUninomial()).trim();
|
621
|
if (isNotBlank(uninomial)){
|
622
|
tags.add(new TaggedText(TagEnum.name, uninomial));
|
623
|
}
|
624
|
|
625
|
return tags;
|
626
|
}
|
627
|
|
628
|
/**
|
629
|
* Returns the tag list for an genus or higher taxon.
|
630
|
*
|
631
|
* @param nonViralName
|
632
|
* @return
|
633
|
*/
|
634
|
protected List<TaggedText> getGenusOrUninomialTaggedNameCache(INonViralName nonViralName){
|
635
|
List<TaggedText> tags = getUninomialTaggedPart(nonViralName);
|
636
|
addAppendedTaggedPhrase(tags, nonViralName);
|
637
|
return tags;
|
638
|
}
|
639
|
|
640
|
/**
|
641
|
* Returns the tag list for an infrageneric taxon (including species aggregates).
|
642
|
*
|
643
|
* @see #getSpeciesAggregateTaggedCache(NonViralName)
|
644
|
* @param nonViralName
|
645
|
* @return
|
646
|
*/
|
647
|
protected List<TaggedText> getInfraGenusTaggedNameCache(INonViralName nonViralName){
|
648
|
Rank rank = nonViralName.getRank();
|
649
|
if (rank != null && rank.isSpeciesAggregate() && isBlank(nonViralName.getAuthorshipCache())){
|
650
|
return getSpeciesAggregateTaggedCache(nonViralName);
|
651
|
}
|
652
|
|
653
|
//genus
|
654
|
List<TaggedText> tags = getUninomialTaggedPart(nonViralName);
|
655
|
|
656
|
//marker
|
657
|
String infraGenericMarker;
|
658
|
if (rank != null){
|
659
|
try {
|
660
|
infraGenericMarker = rank.getInfraGenericMarker();
|
661
|
if (rank.equals(Rank.SECTION_BOTANY()) || rank.equals(Rank.SUBSECTION_BOTANY())){
|
662
|
infraGenericMarker = infraGenericMarker.replace("(bot.)", "");
|
663
|
}
|
664
|
} catch (UnknownCdmTypeException e) {
|
665
|
infraGenericMarker = "'unhandled infrageneric rank'";
|
666
|
}
|
667
|
}else{
|
668
|
infraGenericMarker = "'undefined infrageneric rank'";
|
669
|
}
|
670
|
String infraGenEpi = CdmUtils.Nz(nonViralName.getInfraGenericEpithet()).trim();
|
671
|
if (nonViralName.isBinomHybrid()){
|
672
|
infraGenericMarker = CdmUtils.concat("", NOTHO, infraGenericMarker);
|
673
|
}
|
674
|
|
675
|
addInfraGenericPart(nonViralName, tags, infraGenericMarker, infraGenEpi);
|
676
|
|
677
|
addAppendedTaggedPhrase(tags, nonViralName);
|
678
|
return tags;
|
679
|
}
|
680
|
|
681
|
|
682
|
/**
|
683
|
* Default implementation for the infrageneric part of a name.
|
684
|
* This is usually the infrageneric marker and the infrageneric epitheton. But may be
|
685
|
* implemented differently e.g. for zoological names the infrageneric epitheton
|
686
|
* may be surrounded by brackets and the marker left out.
|
687
|
* @param nonViralName
|
688
|
* @param tags
|
689
|
* @param infraGenericMarker
|
690
|
*/
|
691
|
protected void addInfraGenericPart(
|
692
|
@SuppressWarnings("unused") INonViralName name,
|
693
|
List<TaggedText> tags,
|
694
|
String infraGenericMarker,
|
695
|
String infraGenEpi) {
|
696
|
//add marker
|
697
|
tags.add(new TaggedText(TagEnum.rank, infraGenericMarker));
|
698
|
|
699
|
//add epitheton
|
700
|
if (isNotBlank(infraGenEpi)){
|
701
|
tags.add(new TaggedText(TagEnum.name, infraGenEpi));
|
702
|
}
|
703
|
}
|
704
|
|
705
|
/**
|
706
|
* Returns the tag list for a species aggregate (or similar) taxon.<BR>
|
707
|
* Possible ranks for a <i>species aggregate</i> are "aggr.", "species group", ...
|
708
|
* @param nonViralName
|
709
|
* @return
|
710
|
*/
|
711
|
protected List<TaggedText> getSpeciesAggregateTaggedCache(INonViralName nonViralName){
|
712
|
if (! isBlank(nonViralName.getAuthorshipCache())){
|
713
|
List<TaggedText> result = getSpeciesTaggedNameCache(nonViralName);
|
714
|
return result;
|
715
|
}
|
716
|
|
717
|
|
718
|
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName);
|
719
|
|
720
|
addSpeciesAggregateTaggedEpithet(tags, nonViralName);
|
721
|
addAppendedTaggedPhrase(tags, nonViralName);
|
722
|
return tags;
|
723
|
}
|
724
|
|
725
|
/**
|
726
|
* Adds the aggregate tag to the tag list.
|
727
|
* @param tags
|
728
|
* @param nonViralName
|
729
|
*/
|
730
|
private void addSpeciesAggregateTaggedEpithet(List<TaggedText> tags, INonViralName nonViralName) {
|
731
|
String marker;
|
732
|
try {
|
733
|
marker = nonViralName.getRank().getInfraGenericMarker();
|
734
|
} catch (UnknownCdmTypeException e) {
|
735
|
marker = "'unknown aggregat type'";
|
736
|
}
|
737
|
if (isNotBlank(marker)){
|
738
|
tags.add(new TaggedText(TagEnum.rank, marker));
|
739
|
}
|
740
|
}
|
741
|
|
742
|
|
743
|
/**
|
744
|
* Returns the tag list for a species taxon.
|
745
|
* @param nonViralName
|
746
|
* @return
|
747
|
*/
|
748
|
protected List<TaggedText> getSpeciesTaggedNameCache(INonViralName nonViralName){
|
749
|
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName);
|
750
|
addAppendedTaggedPhrase(tags, nonViralName);
|
751
|
return tags;
|
752
|
}
|
753
|
|
754
|
protected List<TaggedText> getInfraSpeciesTaggedNameCache(TaxonName name){
|
755
|
if (name.getNameType().isZoological()){
|
756
|
boolean includeMarker =includeInfraSpecificMarkerForZooNames(name);
|
757
|
return getInfraSpeciesTaggedNameCache(name, includeMarker);
|
758
|
}else{
|
759
|
return getInfraSpeciesTaggedNameCache(name, true);
|
760
|
}
|
761
|
}
|
762
|
|
763
|
protected boolean includeInfraSpecificMarkerForZooNames(TaxonName name){
|
764
|
return ! (name.isAutonym()); //only exclude marker if autonym, see also ZooNameNoMarkerCacheStrategy
|
765
|
}
|
766
|
|
767
|
/**
|
768
|
* Creates the tag list for an infraspecific taxon. If include is true the result will contain
|
769
|
* the infraspecific marker (e.g. "var.")
|
770
|
* @param nonViralName
|
771
|
* @param includeMarker
|
772
|
* @return
|
773
|
*/
|
774
|
protected List<TaggedText> getInfraSpeciesTaggedNameCache(INonViralName nonViralName, boolean includeMarker){
|
775
|
List<TaggedText> tags = getGenusAndSpeciesTaggedPart(nonViralName);
|
776
|
if (includeMarker || nonViralName.isTrinomHybrid()){
|
777
|
String marker = (nonViralName.getRank().getAbbreviation()).trim().replace("null", "");
|
778
|
if (nonViralName.isTrinomHybrid()){
|
779
|
marker = CdmUtils.concat("", NOTHO, marker);
|
780
|
}
|
781
|
if (isNotBlank(marker)){
|
782
|
tags.add(new TaggedText(TagEnum.rank, marker));
|
783
|
}
|
784
|
|
785
|
}
|
786
|
String infrSpecEpi = CdmUtils.Nz(nonViralName.getInfraSpecificEpithet());
|
787
|
|
788
|
infrSpecEpi = infrSpecEpi.trim().replace("null", "");
|
789
|
|
790
|
if (isNotBlank(infrSpecEpi)){
|
791
|
tags.add(new TaggedText(TagEnum.name, infrSpecEpi));
|
792
|
}
|
793
|
|
794
|
addAppendedTaggedPhrase(tags, nonViralName);
|
795
|
return tags;
|
796
|
}
|
797
|
|
798
|
|
799
|
/**
|
800
|
* Adds a tag for the hybrid sign and an empty separator to avoid trailing whitespaces.
|
801
|
* @param tags
|
802
|
*/
|
803
|
private void addHybridPrefix(List<TaggedText> tags) {
|
804
|
tags.add(new TaggedText(TagEnum.hybridSign, NonViralNameParserImplRegExBase.hybridSign));
|
805
|
tags.add(new TaggedText(TagEnum.separator, "")); //no whitespace separator
|
806
|
}
|
807
|
|
808
|
/**
|
809
|
* Creates the tag list for the genus and species part.
|
810
|
* @param nonViralName
|
811
|
* @return
|
812
|
*/
|
813
|
private List<TaggedText> getGenusAndSpeciesTaggedPart(INonViralName nonViralName) {
|
814
|
//Uninomial
|
815
|
List<TaggedText> tags = getUninomialTaggedPart(nonViralName);
|
816
|
|
817
|
//InfraGenericEpi
|
818
|
boolean hasInfraGenericEpi = isNotBlank(nonViralName.getInfraGenericEpithet());
|
819
|
if (hasInfraGenericEpi){
|
820
|
String infrGenEpi = nonViralName.getInfraGenericEpithet().trim();
|
821
|
if (nonViralName.isBinomHybrid()){
|
822
|
//maybe not correct but not really expected to happen
|
823
|
infrGenEpi = UTF8.HYBRID + infrGenEpi;
|
824
|
}
|
825
|
infrGenEpi = "(" + infrGenEpi + ")";
|
826
|
tags.add(new TaggedText(TagEnum.name, infrGenEpi));
|
827
|
}
|
828
|
|
829
|
//Species Epi
|
830
|
String specEpi = CdmUtils.Nz(nonViralName.getSpecificEpithet()).trim();
|
831
|
if (! hasInfraGenericEpi && nonViralName.isBinomHybrid() ||
|
832
|
hasInfraGenericEpi && nonViralName.isTrinomHybrid()){
|
833
|
addHybridPrefix(tags);
|
834
|
}
|
835
|
if (isNotBlank(specEpi)){
|
836
|
tags.add(new TaggedText(TagEnum.name, specEpi));
|
837
|
}
|
838
|
return tags;
|
839
|
}
|
840
|
|
841
|
/**
|
842
|
* Adds the tag for the appended phrase if an appended phrase exists
|
843
|
* @param tags
|
844
|
* @param nonViralName
|
845
|
*/
|
846
|
protected void addAppendedTaggedPhrase(List<TaggedText> tags, INonViralName nonViralName){
|
847
|
String appendedPhrase = nonViralName ==null ? null : nonViralName.getAppendedPhrase();
|
848
|
if (isNotBlank(appendedPhrase)){
|
849
|
tags.add(new TaggedText(TagEnum.name, appendedPhrase));
|
850
|
}
|
851
|
}
|
852
|
|
853
|
@Override
|
854
|
public String getLastEpithet(TaxonName taxonName) {
|
855
|
Rank rank = taxonName.getRank();
|
856
|
if(rank.isGenus() || rank.isSupraGeneric()) {
|
857
|
return taxonName.getGenusOrUninomial();
|
858
|
} else if(rank.isInfraGeneric()) {
|
859
|
return taxonName.getInfraGenericEpithet();
|
860
|
} else if(rank.isSpecies()) {
|
861
|
return taxonName.getSpecificEpithet();
|
862
|
} else {
|
863
|
return taxonName.getInfraSpecificEpithet();
|
864
|
}
|
865
|
}
|
866
|
|
867
|
@Override
|
868
|
protected List<TaggedText> doGetTaggedTitle(TaxonName taxonName) {
|
869
|
List<TaggedText> tags = new ArrayList<>();
|
870
|
if (taxonName.getNameType().isViral()){
|
871
|
String acronym = taxonName.getAcronym();
|
872
|
tags.add(new TaggedText(TagEnum.name, acronym));
|
873
|
return tags;
|
874
|
}else if (taxonName.isHybridFormula()){
|
875
|
//hybrid formula
|
876
|
String hybridSeparator = NonViralNameParserImplRegExBase.hybridSign;
|
877
|
boolean isFirst = true;
|
878
|
List<HybridRelationship> rels = taxonName.getOrderedChildRelationships();
|
879
|
for (HybridRelationship rel: rels){
|
880
|
if (! isFirst){
|
881
|
tags.add(new TaggedText(TagEnum.hybridSign, hybridSeparator));
|
882
|
}
|
883
|
isFirst = false;
|
884
|
tags.addAll(getTaggedTitle(rel.getParentName()));
|
885
|
}
|
886
|
return tags;
|
887
|
}else if (taxonName.isAutonym()){
|
888
|
//Autonym
|
889
|
tags.addAll(handleTaggedAutonym(taxonName));
|
890
|
}else{ //not Autonym
|
891
|
List<TaggedText> nameTags = getTaggedName(taxonName);
|
892
|
tags.addAll(nameTags);
|
893
|
String authorCache = getAuthorshipCache(taxonName);
|
894
|
if (isNotBlank(authorCache)){
|
895
|
tags.add(new TaggedText(TagEnum.authors, authorCache));
|
896
|
}
|
897
|
}
|
898
|
return tags;
|
899
|
}
|
900
|
|
901
|
}
|