1
|
/**
|
2
|
* Copyright (C) 2009 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
|
|
10
|
package eu.etaxonomy.cdm.strategy.parser;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
import java.util.regex.Matcher;
|
15
|
import java.util.regex.Pattern;
|
16
|
|
17
|
import org.apache.commons.lang.StringUtils;
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.joda.time.DateTimeFieldType;
|
20
|
import org.joda.time.Partial;
|
21
|
|
22
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
23
|
import eu.etaxonomy.cdm.model.agent.Person;
|
24
|
import eu.etaxonomy.cdm.model.agent.Team;
|
25
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.common.IParsable;
|
28
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
29
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
30
|
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
|
31
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
32
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
33
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
34
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
35
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
36
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
37
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
38
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
39
|
import eu.etaxonomy.cdm.model.name.Rank;
|
40
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
41
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
42
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
43
|
import eu.etaxonomy.cdm.model.reference.IBook;
|
44
|
import eu.etaxonomy.cdm.model.reference.IBookSection;
|
45
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
46
|
import eu.etaxonomy.cdm.model.reference.IVolumeReference;
|
47
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
48
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
49
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
50
|
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
|
51
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
52
|
|
53
|
|
54
|
/**
|
55
|
* @author a.mueller
|
56
|
*
|
57
|
*/
|
58
|
public class NonViralNameParserImpl extends NonViralNameParserImplRegExBase implements INonViralNameParser<INonViralName> {
|
59
|
private static final Logger logger = Logger.getLogger(NonViralNameParserImpl.class);
|
60
|
|
61
|
// good intro: http://java.sun.com/docs/books/tutorial/essential/regex/index.html
|
62
|
|
63
|
final static boolean MAKE_EMPTY = true;
|
64
|
final static boolean MAKE_NOT_EMPTY = false;
|
65
|
|
66
|
private final boolean authorIsAlwaysTeam = false;
|
67
|
|
68
|
public static NonViralNameParserImpl NewInstance(){
|
69
|
return new NonViralNameParserImpl();
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public INonViralName parseSimpleName(String simpleName){
|
74
|
return parseSimpleName(simpleName, null, null);
|
75
|
}
|
76
|
|
77
|
@Override
|
78
|
public INonViralName parseSimpleName(String simpleName, NomenclaturalCode code, Rank rank){
|
79
|
//"parseSimpleName() not yet implemented. Uses parseFullName() instead");
|
80
|
return parseFullName(simpleName, code, rank);
|
81
|
}
|
82
|
|
83
|
public void parseSimpleName(INonViralName nameToBeFilled, String simpleNameString, Rank rank, boolean makeEmpty){
|
84
|
//"parseSimpleName() not yet implemented. Uses parseFullName() instead");
|
85
|
parseFullName(nameToBeFilled, simpleNameString, rank, makeEmpty);
|
86
|
}
|
87
|
|
88
|
public INonViralName getNonViralNameInstance(String fullString, NomenclaturalCode code){
|
89
|
return getNonViralNameInstance(fullString, code, null);
|
90
|
}
|
91
|
|
92
|
public INonViralName getNonViralNameInstance(String fullString, NomenclaturalCode code, Rank rank){
|
93
|
INonViralName result = null;
|
94
|
if(code ==null) {
|
95
|
boolean isBotanicalName = anyBotanicFullNamePattern.matcher(fullString).find();
|
96
|
boolean isZoologicalName = anyZooFullNamePattern.matcher(fullString).find();;
|
97
|
boolean isBacteriologicalName = false;
|
98
|
boolean isCultivatedPlantName = false;
|
99
|
if ( (isBotanicalName || isCultivatedPlantName) && ! isZoologicalName && !isBacteriologicalName){
|
100
|
if (isBotanicalName){
|
101
|
result = TaxonNameFactory.NewBotanicalInstance(rank);
|
102
|
}else{
|
103
|
result = TaxonNameFactory.NewCultivarInstance(rank);
|
104
|
}
|
105
|
}else if ( isZoologicalName /*&& ! isBotanicalName*/ && !isBacteriologicalName && !isCultivatedPlantName){
|
106
|
result = TaxonNameFactory.NewZoologicalInstance(rank);
|
107
|
}else if ( isZoologicalName && ! isBotanicalName && !isBacteriologicalName && !isCultivatedPlantName){
|
108
|
result = TaxonNameFactory.NewBacterialInstance(rank);
|
109
|
}else {
|
110
|
result = TaxonNameFactory.NewNonViralInstance(rank);
|
111
|
}
|
112
|
} else {
|
113
|
switch (code) {
|
114
|
case ICNAFP:
|
115
|
result = TaxonNameFactory.NewBotanicalInstance(rank);
|
116
|
break;
|
117
|
case ICZN:
|
118
|
result = TaxonNameFactory.NewZoologicalInstance(rank);
|
119
|
break;
|
120
|
case ICNCP:
|
121
|
logger.warn("ICNCP parsing not yet implemented");
|
122
|
result = TaxonNameFactory.NewCultivarInstance(rank);
|
123
|
break;
|
124
|
case ICNB:
|
125
|
logger.warn("ICNB not yet implemented");
|
126
|
result = TaxonNameFactory.NewBacterialInstance(rank);
|
127
|
break;
|
128
|
case ICVCN:
|
129
|
logger.error("Viral name is not a NonViralName !!");
|
130
|
break;
|
131
|
default:
|
132
|
// FIXME Unreachable code
|
133
|
logger.error("Unknown Nomenclatural Code !!");
|
134
|
}
|
135
|
}
|
136
|
return result;
|
137
|
}
|
138
|
|
139
|
@Override
|
140
|
public NonViralName parseReferencedName(String fullReferenceString) {
|
141
|
return parseReferencedName(fullReferenceString, null, null);
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public NonViralName parseReferencedName(String fullReferenceString, NomenclaturalCode nomCode, Rank rank) {
|
146
|
if (fullReferenceString == null){
|
147
|
return null;
|
148
|
}else{
|
149
|
INonViralName result = getNonViralNameInstance(fullReferenceString, nomCode, rank);
|
150
|
parseReferencedName(result, fullReferenceString, rank, MAKE_EMPTY);
|
151
|
return (NonViralName)result;
|
152
|
}
|
153
|
}
|
154
|
|
155
|
private String standardize(INonViralName nameToBeFilled, String fullReferenceString, boolean makeEmpty){
|
156
|
//Check null and standardize
|
157
|
if (fullReferenceString == null){
|
158
|
//return null;
|
159
|
return null;
|
160
|
}
|
161
|
if (makeEmpty){
|
162
|
makeEmpty(nameToBeFilled);
|
163
|
}
|
164
|
fullReferenceString = fullReferenceString.replaceAll(oWs , " ");
|
165
|
fullReferenceString = fullReferenceString.trim();
|
166
|
if ("".equals(fullReferenceString)){
|
167
|
fullReferenceString = null;
|
168
|
}
|
169
|
return fullReferenceString;
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* Returns the regEx to be used for the full-name depending on the code
|
174
|
* @param nameToBeFilled
|
175
|
* @return
|
176
|
*/
|
177
|
private String getCodeSpecificFullNameRegEx(INonViralName nameToBeFilledOrig){
|
178
|
INonViralName nameToBeFilled = CdmBase.deproxy(nameToBeFilledOrig);
|
179
|
if (nameToBeFilled instanceof ZoologicalName){
|
180
|
return anyZooFullName;
|
181
|
}else if (nameToBeFilled instanceof BotanicalName) {
|
182
|
return anyBotanicFullName;
|
183
|
}else if (nameToBeFilled instanceof NonViralName) {
|
184
|
return anyBotanicFullName; //TODO ?
|
185
|
}else{
|
186
|
logger.warn("nameToBeFilled class not supported ("+nameToBeFilled.getClass()+")");
|
187
|
return null;
|
188
|
}
|
189
|
}
|
190
|
|
191
|
/**
|
192
|
* Returns the regEx to be used for the fsimple-name depending on the code
|
193
|
* @param nameToBeFilled
|
194
|
* @return
|
195
|
*/
|
196
|
private String getCodeSpecificSimpleNameRegEx(INonViralName nameToBeFilled){
|
197
|
nameToBeFilled = CdmBase.deproxy(nameToBeFilled);
|
198
|
|
199
|
if (nameToBeFilled instanceof ZoologicalName){
|
200
|
return anyZooName;
|
201
|
}else if (nameToBeFilled instanceof NonViralName){
|
202
|
return anyZooName; //TODO ?
|
203
|
}else if (nameToBeFilled instanceof BotanicalName) {
|
204
|
return anyBotanicName;
|
205
|
}else{
|
206
|
logger.warn("nameToBeFilled class not supported ("+nameToBeFilled.getClass()+")");
|
207
|
return null;
|
208
|
}
|
209
|
}
|
210
|
|
211
|
private Matcher getMatcher(String regEx, String matchString){
|
212
|
Pattern pattern = Pattern.compile(regEx);
|
213
|
Matcher matcher = pattern.matcher(matchString);
|
214
|
return matcher;
|
215
|
}
|
216
|
|
217
|
@Override
|
218
|
public void parseReferencedName(INonViralName nameToBeFilled, String fullReferenceStringOrig, Rank rank, boolean makeEmpty) {
|
219
|
//standardize
|
220
|
String fullReferenceString = standardize(nameToBeFilled, fullReferenceStringOrig, makeEmpty);
|
221
|
if (fullReferenceString == null){
|
222
|
return;
|
223
|
}
|
224
|
// happens already in standardize(...)
|
225
|
// makeProblemEmpty(nameToBeFilled);
|
226
|
|
227
|
//make nomenclatural status and replace it by empty string
|
228
|
fullReferenceString = parseNomStatus(fullReferenceString, nameToBeFilled, makeEmpty);
|
229
|
nameToBeFilled.setProblemEnds(fullReferenceString.length());
|
230
|
|
231
|
//get full name reg
|
232
|
String localFullNameRegEx = getCodeSpecificFullNameRegEx(nameToBeFilled);
|
233
|
//get full name reg
|
234
|
String localSimpleNameRegEx = getCodeSpecificSimpleNameRegEx(nameToBeFilled);
|
235
|
|
236
|
//separate name and reference part
|
237
|
String nameAndRefSeparatorRegEx = "(^" + localFullNameRegEx + ")("+ referenceSeperator + ")";
|
238
|
Matcher nameAndRefSeparatorMatcher = getMatcher (nameAndRefSeparatorRegEx, fullReferenceString);
|
239
|
|
240
|
Matcher onlyNameMatcher = getMatcher (localFullNameRegEx, fullReferenceString);
|
241
|
Matcher hybridMatcher = hybridFormulaPattern.matcher(fullReferenceString);
|
242
|
Matcher onlySimpleNameMatcher = getMatcher (localSimpleNameRegEx, fullReferenceString);
|
243
|
|
244
|
if (onlyNameMatcher.matches()){
|
245
|
makeEmpty = false;
|
246
|
parseFullName(nameToBeFilled, fullReferenceString, rank, makeEmpty);
|
247
|
} else if (nameAndRefSeparatorMatcher.find()){
|
248
|
makeNameWithReference(nameToBeFilled, fullReferenceString, nameAndRefSeparatorMatcher, rank, makeEmpty);
|
249
|
}else if (hybridMatcher.matches() ){
|
250
|
//I do not remember why we need makeEmpty = false for onlyNameMatcher,
|
251
|
//but for hybridMatcher we need to remove old Hybrid Relationships if necessary, therefore
|
252
|
//I removed it from here
|
253
|
parseFullName(nameToBeFilled, fullReferenceString, rank, makeEmpty);
|
254
|
}else if (onlySimpleNameMatcher.matches()){
|
255
|
makeEmpty = false;
|
256
|
parseFullName(nameToBeFilled, fullReferenceString, rank, makeEmpty); //simpleName not yet implemented
|
257
|
}else{
|
258
|
makeNoFullRefMatch(nameToBeFilled, fullReferenceString, rank);
|
259
|
}
|
260
|
//problem handling. Start and end solved in subroutines
|
261
|
if (! nameToBeFilled.hasProblem()){
|
262
|
makeProblemEmpty(nameToBeFilled);
|
263
|
}
|
264
|
}
|
265
|
|
266
|
private void makeProblemEmpty(IParsable parsable){
|
267
|
boolean hasCheckRank = parsable.hasProblem(ParserProblem.CheckRank);
|
268
|
parsable.setParsingProblem(0);
|
269
|
if (hasCheckRank){
|
270
|
parsable.addParsingProblem(ParserProblem.CheckRank);
|
271
|
}
|
272
|
parsable.setProblemStarts(-1);
|
273
|
parsable.setProblemEnds(-1);
|
274
|
}
|
275
|
|
276
|
private void makeNoFullRefMatch(INonViralName nameToBeFilled, String fullReferenceString, Rank rank){
|
277
|
//try to parse first part as name, but keep in mind full string is not parsable
|
278
|
int start = 0;
|
279
|
|
280
|
String localFullName = getCodeSpecificFullNameRegEx(nameToBeFilled);
|
281
|
Matcher fullNameMatcher = getMatcher (pStart + localFullName, fullReferenceString);
|
282
|
if (fullNameMatcher.find()){
|
283
|
String fullNameString = fullNameMatcher.group(0);
|
284
|
nameToBeFilled.setProtectedNameCache(false);
|
285
|
parseFullName(nameToBeFilled, fullNameString, rank, false);
|
286
|
String sure = nameToBeFilled.getNameCache();
|
287
|
start = sure.length();
|
288
|
}
|
289
|
|
290
|
// String localSimpleName = getLocalSimpleName(nameToBeFilled);
|
291
|
// Matcher simpleNameMatcher = getMatcher (start + localSimpleName, fullReferenceString);
|
292
|
// if (simpleNameMatcher.find()){
|
293
|
// String simpleNameString = simpleNameMatcher.group(0);
|
294
|
// parseFullName(nameToBeFilled, simpleNameString, rank, false);
|
295
|
// start = simpleNameString.length();
|
296
|
// }
|
297
|
|
298
|
//don't parse if name can't be separated
|
299
|
nameToBeFilled.addParsingProblem(ParserProblem.NameReferenceSeparation);
|
300
|
nameToBeFilled.setTitleCache(fullReferenceString, true);
|
301
|
nameToBeFilled.setFullTitleCache(fullReferenceString, true);
|
302
|
// FIXME Quick fix, otherwise search would not deliver results for unparsable names
|
303
|
nameToBeFilled.setNameCache(fullReferenceString, true);
|
304
|
// END
|
305
|
nameToBeFilled.setProblemStarts(start);
|
306
|
nameToBeFilled.setProblemEnds(fullReferenceString.length());
|
307
|
logger.info("no applicable parsing rule could be found for \"" + fullReferenceString + "\"");
|
308
|
}
|
309
|
|
310
|
private void makeNameWithReference(INonViralName nameToBeFilled,
|
311
|
String fullReferenceString,
|
312
|
Matcher nameAndRefSeparatorMatcher,
|
313
|
Rank rank,
|
314
|
boolean makeEmpty){
|
315
|
|
316
|
String nameAndSeparator = nameAndRefSeparatorMatcher.group(0);
|
317
|
String name = nameAndRefSeparatorMatcher.group(1);
|
318
|
String referenceString = fullReferenceString.substring(nameAndRefSeparatorMatcher.end());
|
319
|
|
320
|
// is reference an in ref?
|
321
|
String separator = nameAndSeparator.substring(name.length());
|
322
|
boolean isInReference = separator.matches(inReferenceSeparator);
|
323
|
|
324
|
//parse subparts
|
325
|
|
326
|
int oldProblemEnds = nameToBeFilled.getProblemEnds();
|
327
|
parseFullName(nameToBeFilled, name, rank, makeEmpty);
|
328
|
nameToBeFilled.setProblemEnds(oldProblemEnds);
|
329
|
|
330
|
//zoological new combinations should not have a nom. reference to be parsed
|
331
|
if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
|
332
|
IZoologicalName zooName = CdmBase.deproxy(nameToBeFilled, ZoologicalName.class);
|
333
|
//is name new combination?
|
334
|
if (zooName.getBasionymAuthorship() != null || zooName.getOriginalPublicationYear() != null){
|
335
|
ParserProblem parserProblem = ParserProblem.NewCombinationHasPublication;
|
336
|
zooName.addParsingProblem(parserProblem);
|
337
|
nameToBeFilled.setProblemStarts((nameToBeFilled.getProblemStarts()> -1) ? nameToBeFilled.getProblemStarts(): name.length());
|
338
|
nameToBeFilled.setProblemEnds(Math.max(fullReferenceString.length(), nameToBeFilled.getProblemEnds()));
|
339
|
}
|
340
|
}
|
341
|
|
342
|
parseReference(nameToBeFilled, referenceString, isInReference);
|
343
|
INomenclaturalReference ref = nameToBeFilled.getNomenclaturalReference();
|
344
|
|
345
|
//problem start
|
346
|
int start = nameToBeFilled.getProblemStarts();
|
347
|
int nameLength = name.length();
|
348
|
int nameAndSeparatorLength = nameAndSeparator.length();
|
349
|
int fullRefLength = nameToBeFilled.getFullTitleCache().length();
|
350
|
|
351
|
if (nameToBeFilled.isProtectedTitleCache() || nameToBeFilled.getParsingProblems().contains(ParserProblem.CheckRank)){
|
352
|
start = Math.max(0, start);
|
353
|
}else{
|
354
|
if (ref != null && ref.getParsingProblem()!=0){
|
355
|
start = Math.max(nameAndSeparatorLength, start);
|
356
|
//TODO search within ref
|
357
|
}
|
358
|
}
|
359
|
|
360
|
//end
|
361
|
int end = nameToBeFilled.getProblemEnds();
|
362
|
|
363
|
if (ref != null && ref.getParsingProblem()!=0){
|
364
|
end = Math.min(nameAndSeparatorLength + ref.getProblemEnds(), end);
|
365
|
}else{
|
366
|
if (nameToBeFilled.isProtectedTitleCache() ){
|
367
|
end = Math.min(end, nameAndSeparatorLength);
|
368
|
//TODO search within name
|
369
|
}
|
370
|
}
|
371
|
nameToBeFilled.setProblemStarts(start);
|
372
|
nameToBeFilled.setProblemEnds(end);
|
373
|
|
374
|
//delegate has problem to name
|
375
|
if (ref != null && ref.getParsingProblem()!=0){
|
376
|
nameToBeFilled.addParsingProblems(ref.getParsingProblem());
|
377
|
}
|
378
|
|
379
|
Reference nomRef;
|
380
|
if ( (nomRef = (Reference)nameToBeFilled.getNomenclaturalReference()) != null ){
|
381
|
nomRef.setAuthorship(nameToBeFilled.getCombinationAuthorship());
|
382
|
}
|
383
|
}
|
384
|
|
385
|
//TODO make it an Array of status
|
386
|
/**
|
387
|
* Extracts a {@link NomenclaturalStatus} from the reference String and adds it to the @link {@link TaxonNameBase}.
|
388
|
* The nomenclatural status part ist deleted from the reference String.
|
389
|
* @return String the new (shortend) reference String
|
390
|
*/
|
391
|
public String parseNomStatus(String fullString, INonViralName nameToBeFilled, boolean makeEmpty) {
|
392
|
Set<NomenclaturalStatusType> existingStatusTypeSet = new HashSet<NomenclaturalStatusType>();
|
393
|
Set<NomenclaturalStatusType> newStatusTypeSet = new HashSet<NomenclaturalStatusType>();
|
394
|
for (NomenclaturalStatus existingStatus : nameToBeFilled.getStatus()){
|
395
|
existingStatusTypeSet.add(existingStatus.getType());
|
396
|
}
|
397
|
|
398
|
String statusString;
|
399
|
Pattern hasStatusPattern = Pattern.compile("(" + pNomStatusPhrase + ")");
|
400
|
Matcher hasStatusMatcher = hasStatusPattern.matcher(fullString);
|
401
|
|
402
|
if (hasStatusMatcher.find()) {
|
403
|
String statusPhrase = hasStatusMatcher.group(0);
|
404
|
|
405
|
Pattern statusPattern = Pattern.compile(pNomStatus);
|
406
|
Matcher statusMatcher = statusPattern.matcher(statusPhrase);
|
407
|
statusMatcher.find();
|
408
|
statusString = statusMatcher.group(0);
|
409
|
try {
|
410
|
TaxonNameBase<?,?> nameToBeFilledCasted = TaxonNameBase.castAndDeproxy(nameToBeFilled);
|
411
|
NomenclaturalStatusType nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusString, nameToBeFilledCasted);
|
412
|
if (! existingStatusTypeSet.contains(nomStatusType)){
|
413
|
NomenclaturalStatus nomStatus = NomenclaturalStatus.NewInstance(nomStatusType);
|
414
|
nameToBeFilled.addStatus(nomStatus);
|
415
|
}
|
416
|
newStatusTypeSet.add(nomStatusType);
|
417
|
fullString = fullString.replace(statusPhrase, "");
|
418
|
} catch (UnknownCdmTypeException e) {
|
419
|
//Do nothing
|
420
|
}
|
421
|
}
|
422
|
//remove not existing nom status
|
423
|
if (makeEmpty){
|
424
|
Set<NomenclaturalStatus> tmpStatus = new HashSet<NomenclaturalStatus>();
|
425
|
tmpStatus.addAll(nameToBeFilled.getStatus());
|
426
|
for (NomenclaturalStatus status : tmpStatus){
|
427
|
if (! newStatusTypeSet.contains(status.getType())){
|
428
|
nameToBeFilled.removeStatus(status);
|
429
|
}
|
430
|
}
|
431
|
}
|
432
|
|
433
|
return fullString;
|
434
|
}
|
435
|
|
436
|
|
437
|
private void parseReference(INonViralName nameToBeFilled, String strReference, boolean isInReference){
|
438
|
|
439
|
INomenclaturalReference ref;
|
440
|
String originalStrReference = strReference;
|
441
|
|
442
|
//End (just delete end (e.g. '.', may be ambigous for yearPhrase, but no real information gets lost
|
443
|
Matcher endMatcher = getMatcher(referenceEnd + end, strReference);
|
444
|
if (endMatcher.find()){
|
445
|
String endPart = endMatcher.group(0);
|
446
|
strReference = strReference.substring(0, strReference.length() - endPart.length());
|
447
|
}
|
448
|
|
449
|
// String pDetailYear = ".*" + detailSeparator + detail + fWs + yearSeperator + fWs + yearPhrase + fWs + end;
|
450
|
// Matcher detailYearMatcher = getMatcher(pDetailYear, strReference);
|
451
|
|
452
|
String strReferenceWithYear = strReference;
|
453
|
//year
|
454
|
String yearPart = null;
|
455
|
String pYearPhrase = yearSeperator + fWs + yearPhrase + fWs + end;
|
456
|
Matcher yearPhraseMatcher = getMatcher(pYearPhrase, strReference);
|
457
|
if (yearPhraseMatcher.find()){
|
458
|
yearPart = yearPhraseMatcher.group(0);
|
459
|
strReference = strReference.substring(0, strReference.length() - yearPart.length());
|
460
|
yearPart = yearPart.replaceFirst(pStart + yearSeperator, "").trim();
|
461
|
}else{
|
462
|
if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
|
463
|
IZoologicalName zooName = CdmBase.deproxy(nameToBeFilled, ZoologicalName.class);
|
464
|
yearPart = String.valueOf(zooName.getPublicationYear());
|
465
|
//continue
|
466
|
}else{
|
467
|
ref = makeDetailYearUnparsable(nameToBeFilled,strReference);
|
468
|
ref.setDatePublished(TimePeriodParser.parseString(yearPart));
|
469
|
return;
|
470
|
}
|
471
|
}
|
472
|
|
473
|
|
474
|
//detail
|
475
|
String pDetailPhrase = detailSeparator + fWs + detail + fWs + end;
|
476
|
Matcher detailPhraseMatcher = getMatcher(pDetailPhrase, strReference);
|
477
|
if (detailPhraseMatcher.find()){
|
478
|
String detailPart = detailPhraseMatcher.group(0);
|
479
|
strReference = strReference.substring(0, strReference.length() - detailPart.length());
|
480
|
detailPart = detailPart.replaceFirst(pStart + detailSeparator, "").trim();
|
481
|
nameToBeFilled.setNomenclaturalMicroReference(detailPart);
|
482
|
}else{
|
483
|
makeDetailYearUnparsable(nameToBeFilled, strReferenceWithYear);
|
484
|
return;
|
485
|
}
|
486
|
//parse title and author
|
487
|
ref = parseReferenceTitle(strReference, yearPart, isInReference);
|
488
|
if (ref.hasProblem()){
|
489
|
//we need to protect both caches otherwise the titleCache is incorrectly build from atomized parts
|
490
|
ref.setTitleCache( (isInReference ? "in ":"") + originalStrReference, true);
|
491
|
ref.setAbbrevTitleCache( (isInReference ? "in ":"") + originalStrReference, true);
|
492
|
}
|
493
|
nameToBeFilled.setNomenclaturalReference(ref);
|
494
|
int end = Math.min(strReference.length(), ref.getProblemEnds());
|
495
|
ref.setProblemEnds(end);
|
496
|
}
|
497
|
|
498
|
/**
|
499
|
* @param nameToBeFilled
|
500
|
* @param strReference
|
501
|
* @return
|
502
|
*/
|
503
|
private Reference makeDetailYearUnparsable(INonViralName nameToBeFilled, String strReference) {
|
504
|
Reference ref;
|
505
|
|
506
|
ref = ReferenceFactory.newGeneric();
|
507
|
ref.setTitleCache(strReference, true);
|
508
|
ref.setAbbrevTitleCache(strReference, true);
|
509
|
ref.setProblemEnds(strReference.length());
|
510
|
ref.addParsingProblem(ParserProblem.CheckDetailOrYear);
|
511
|
nameToBeFilled.addParsingProblem(ParserProblem.CheckDetailOrYear);
|
512
|
nameToBeFilled.setNomenclaturalReference(ref);
|
513
|
return ref;
|
514
|
}
|
515
|
|
516
|
/**
|
517
|
* Parses the referenceTitlePart, including the author volume and edition.
|
518
|
* @param reference
|
519
|
* @param year
|
520
|
* @return
|
521
|
*/
|
522
|
public INomenclaturalReference parseReferenceTitle(String strReference, String year, boolean isInReference){
|
523
|
IBook result = null;
|
524
|
|
525
|
Matcher refSineDetailMatcher = referenceSineDetailPattern.matcher(strReference);
|
526
|
if (! refSineDetailMatcher.matches()){
|
527
|
//TODO ?
|
528
|
}
|
529
|
|
530
|
Matcher articleMatcher = getMatcher(pArticleReference, strReference);
|
531
|
Matcher bookMatcher = getMatcher(pBookReference, strReference);
|
532
|
|
533
|
Matcher softArticleMatcher = getMatcher(pSoftArticleReference, strReference);
|
534
|
Matcher bookSectionMatcher = getMatcher(pBookSectionReference, strReference);
|
535
|
|
536
|
|
537
|
if(isInReference == false){
|
538
|
if (bookMatcher.matches() ){
|
539
|
result = parseBook(strReference);
|
540
|
}else{
|
541
|
logger.warn("Non-InRef must be book but does not match book: "+ strReference);
|
542
|
result = ReferenceFactory.newBook();
|
543
|
makeUnparsableRefTitle(result, strReference);
|
544
|
}
|
545
|
}else{ //inRef
|
546
|
if (articleMatcher.matches()){
|
547
|
//article without separators like ","
|
548
|
result = parseArticle(strReference);
|
549
|
}else if (softArticleMatcher.matches()){
|
550
|
result = parseArticle(strReference);
|
551
|
}else if (bookSectionMatcher.matches()){
|
552
|
result = parseBookSection(strReference);
|
553
|
}else{
|
554
|
result = ReferenceFactory.newGeneric();
|
555
|
makeUnparsableRefTitle(result, "in " + strReference);
|
556
|
}
|
557
|
}
|
558
|
//make year
|
559
|
if (makeYear(result, year) == false){
|
560
|
//TODO
|
561
|
logger.warn("Year could not be parsed");
|
562
|
}
|
563
|
result.setProblemStarts(0);
|
564
|
result.setProblemEnds(strReference.length());
|
565
|
return result;
|
566
|
}
|
567
|
|
568
|
private void makeUnparsableRefTitle(INomenclaturalReference result, String reference){
|
569
|
//need to set both to protected otherwise titleCache is created from atomized parts
|
570
|
result.setTitleCache(reference, true);
|
571
|
result.setAbbrevTitleCache(reference, true);
|
572
|
result.addParsingProblem(ParserProblem.UnparsableReferenceTitle);
|
573
|
}
|
574
|
|
575
|
/**
|
576
|
* Parses a single date string. If the string is not parsable a StringNotParsableException is thrown
|
577
|
* @param singleDateString
|
578
|
* @return
|
579
|
* @throws StringNotParsableException
|
580
|
*/
|
581
|
private static Partial parseSingleDate(String singleDateString)
|
582
|
throws StringNotParsableException{
|
583
|
Partial dt = new Partial();
|
584
|
if (CdmUtils.isNumeric(singleDateString)){
|
585
|
try {
|
586
|
Integer year = Integer.valueOf(singleDateString.trim());
|
587
|
if (year > 1750 && year < 2050){
|
588
|
dt = dt.with(DateTimeFieldType.year(), year);
|
589
|
}else{
|
590
|
dt = null;
|
591
|
}
|
592
|
} catch (NumberFormatException e) {
|
593
|
logger.debug("Not a Integer format in getCalendar()");
|
594
|
throw new StringNotParsableException(singleDateString + "is not parsable as a single Date");
|
595
|
}
|
596
|
}
|
597
|
return dt;
|
598
|
}
|
599
|
|
600
|
|
601
|
/**
|
602
|
* Parses the publication date part.
|
603
|
* @param nomRef
|
604
|
* @param year
|
605
|
* @return If the string is not parsable <code>false</code>
|
606
|
* is returned. <code>True</code> otherwise
|
607
|
*/
|
608
|
private boolean makeYear(INomenclaturalReference nomRef, String year){
|
609
|
boolean result = true;
|
610
|
if (year == null){
|
611
|
return false;
|
612
|
}
|
613
|
if ("".equals(year.trim())){
|
614
|
return true;
|
615
|
}
|
616
|
TimePeriod datePublished = TimePeriodParser.parseString(year);
|
617
|
|
618
|
if (nomRef.getType().equals(ReferenceType.BookSection)){
|
619
|
handleBookSectionYear((IBookSection)nomRef, datePublished);
|
620
|
}else if (nomRef instanceof Reference){
|
621
|
((Reference)nomRef).setDatePublished(datePublished);
|
622
|
}else{
|
623
|
throw new ClassCastException("nom Ref is not of type Reference but " + (nomRef == null? "(null)" : nomRef.getClass()));
|
624
|
}
|
625
|
return result;
|
626
|
}
|
627
|
|
628
|
private String makeVolume(IVolumeReference nomRef, String strReference){
|
629
|
//volume
|
630
|
String volPart = null;
|
631
|
String pVolPhrase = volumeSeparator + volume + end;
|
632
|
Matcher volPhraseMatcher = getMatcher(pVolPhrase, strReference);
|
633
|
if (volPhraseMatcher.find()){
|
634
|
volPart = volPhraseMatcher.group(0);
|
635
|
strReference = strReference.substring(0, strReference.length() - volPart.length());
|
636
|
volPart = volPart.replaceFirst(pStart + volumeSeparator, "").trim();
|
637
|
nomRef.setVolume(volPart);
|
638
|
}
|
639
|
return strReference;
|
640
|
}
|
641
|
|
642
|
private String makeEdition(IBook book, String strReference){
|
643
|
//volume
|
644
|
String editionPart = null;
|
645
|
Matcher editionPhraseMatcher = getMatcher(pEditionPart, strReference);
|
646
|
|
647
|
Matcher editionVolumeMatcher = getMatcher(pEditionVolPart, strReference);
|
648
|
boolean isEditionAndVol = editionVolumeMatcher.find();
|
649
|
|
650
|
if (editionPhraseMatcher.find()){
|
651
|
editionPart = editionPhraseMatcher.group(0);
|
652
|
int pos = strReference.indexOf(editionPart);
|
653
|
int posEnd = pos + editionPart.length();
|
654
|
if (isEditionAndVol){
|
655
|
posEnd++; //delete also comma
|
656
|
}
|
657
|
strReference = strReference.substring(0, pos) + strReference.substring(posEnd);
|
658
|
editionPart = editionPart.replaceFirst(pStart + editionSeparator, "").trim();
|
659
|
book.setEdition(editionPart);
|
660
|
}
|
661
|
return strReference;
|
662
|
}
|
663
|
|
664
|
private IBook parseBook(String reference){
|
665
|
IBook result = ReferenceFactory.newBook();
|
666
|
reference = makeEdition(result, reference);
|
667
|
reference = makeVolume(result, reference);
|
668
|
result.setAbbrevTitle(reference);
|
669
|
return result;
|
670
|
}
|
671
|
|
672
|
|
673
|
private Reference parseArticle(String reference){
|
674
|
//if (articlePatter)
|
675
|
//(type, author, title, volume, editor, series;
|
676
|
Reference result = ReferenceFactory.newArticle();
|
677
|
reference = makeVolume(result, reference);
|
678
|
Reference inJournal = ReferenceFactory.newJournal();
|
679
|
inJournal.setAbbrevTitle(reference);
|
680
|
result.setInReference(inJournal);
|
681
|
return result;
|
682
|
}
|
683
|
|
684
|
private Reference parseBookSection(String reference){
|
685
|
Reference result = ReferenceFactory.newBookSection();
|
686
|
|
687
|
Pattern authorPattern = Pattern.compile("^" + authorTeam + referenceAuthorSeparator);
|
688
|
Matcher authorMatcher = authorPattern.matcher(reference);
|
689
|
boolean find = authorMatcher.find();
|
690
|
if (find){
|
691
|
String authorString = authorMatcher.group(0).trim();
|
692
|
String bookString = reference.substring(authorString.length()).trim();
|
693
|
authorString = authorString.substring(0, authorString.length() -1);
|
694
|
|
695
|
TeamOrPersonBase<?> authorTeam = author(authorString);
|
696
|
IBook inBook = parseBook(bookString);
|
697
|
inBook.setAuthorship(authorTeam);
|
698
|
result.setInBook(inBook);
|
699
|
}else{
|
700
|
logger.warn("Unexpected non matching book section author part");
|
701
|
//TODO do we want to record a 'problem' here?
|
702
|
result.setTitleCache(reference, true);
|
703
|
result.setAbbrevTitleCache(reference, true);
|
704
|
}
|
705
|
|
706
|
return result;
|
707
|
}
|
708
|
|
709
|
/**
|
710
|
* If the publication date of a book section and it's inBook do differ this is usually
|
711
|
* caused by the fact that a book has been published during a period, because originally
|
712
|
* it consisted of several parts that only later where put together to one book.
|
713
|
* If so, the book section's publication date may be a point in time (year or month of year)
|
714
|
* whereas the books publication date may be a period of several years.
|
715
|
* Therefore a valid nomenclatural reference string should use the book sections
|
716
|
* publication date rather then the book's publication date.<BR>
|
717
|
* This method in general adds the publication date to the book section.
|
718
|
* An exception exists if the publication date is a period. Then the parser
|
719
|
* assumes that the nomenclatural reference string does not follow the above rule but
|
720
|
* the books publication date is set.
|
721
|
* @param bookSection
|
722
|
* @param datePublished
|
723
|
*/
|
724
|
private void handleBookSectionYear(IBookSection bookSection, TimePeriod datePublished){
|
725
|
if (datePublished == null || datePublished.getStart() == null || bookSection == null){
|
726
|
return;
|
727
|
}
|
728
|
if (datePublished.isPeriod() && bookSection.getInBook() != null){
|
729
|
bookSection.getInBook().setDatePublished(datePublished);
|
730
|
}else{
|
731
|
bookSection.setDatePublished(datePublished);
|
732
|
}
|
733
|
}
|
734
|
|
735
|
@Override
|
736
|
public INonViralName parseFullName(String fullNameString){
|
737
|
return parseFullName(fullNameString, null, null);
|
738
|
}
|
739
|
|
740
|
@Override
|
741
|
public INonViralName parseFullName(String fullNameString, NomenclaturalCode nomCode, Rank rank) {
|
742
|
|
743
|
if (fullNameString == null){
|
744
|
return null;
|
745
|
}else{
|
746
|
INonViralName result = getNonViralNameInstance(fullNameString, nomCode, rank);
|
747
|
parseFullName(result, fullNameString, rank, false);
|
748
|
return result;
|
749
|
}
|
750
|
}
|
751
|
|
752
|
@Override
|
753
|
public void parseFullName(INonViralName nameToBeFilledOrig, String fullNameStringOrig, Rank rank, boolean makeEmpty) {
|
754
|
INonViralName nameToBeFilled = nameToBeFilledOrig;
|
755
|
|
756
|
//TODO prol. etc.
|
757
|
boolean hasCheckRankProblem = false; //was rank guessed in a previous parsing process?
|
758
|
if (nameToBeFilled == null){
|
759
|
throw new IllegalArgumentException("NameToBeFilled must not be null in name parser");
|
760
|
}else{
|
761
|
hasCheckRankProblem = nameToBeFilled.hasProblem(ParserProblem.CheckRank);
|
762
|
nameToBeFilled.removeParsingProblem(ParserProblem.CheckRank);
|
763
|
}
|
764
|
String authorString = null;
|
765
|
if (fullNameStringOrig == null){
|
766
|
return;
|
767
|
}
|
768
|
if (makeEmpty){
|
769
|
makeEmpty(nameToBeFilled);
|
770
|
}
|
771
|
|
772
|
String fullNameString = fullNameStringOrig.replaceAll(oWs , " ").trim();
|
773
|
|
774
|
fullNameString = removeHybridBlanks(fullNameString);
|
775
|
fullNameString = removeSpNovBlanks(fullNameString);
|
776
|
String[] epi = pattern.split(fullNameString);
|
777
|
try {
|
778
|
//cultivars //TODO 2 implement cultivars
|
779
|
// if ( cultivarMarkerRE.match(fullName) ){ funktioniert noch nicht, da es z.B. auch Namen gibt, wie 't Hart
|
780
|
// result = parseCultivar(fullName);
|
781
|
// }
|
782
|
|
783
|
if (genusOrSupraGenusPattern.matcher(fullNameString).matches()){
|
784
|
//supraGeneric
|
785
|
if (rank != null && ! hasCheckRankProblem && (rank.isSupraGeneric()|| rank.isGenus())){
|
786
|
nameToBeFilled.setRank(rank);
|
787
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
788
|
}
|
789
|
//genus or guess rank
|
790
|
else {
|
791
|
rank = guessUninomialRank(nameToBeFilled, epi[0]);
|
792
|
nameToBeFilled.setRank(rank);
|
793
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
794
|
nameToBeFilled.addParsingProblem(ParserProblem.CheckRank);
|
795
|
nameToBeFilled.setProblemStarts(0);
|
796
|
nameToBeFilled.setProblemEnds(epi[0].length());
|
797
|
}
|
798
|
authorString = fullNameString.substring(epi[0].length());
|
799
|
}
|
800
|
//infra genus
|
801
|
else if (infraGenusPattern.matcher(fullNameString).matches()){
|
802
|
Rank infraGenericRank;
|
803
|
if ("[unranked]".equals(epi[1])){
|
804
|
infraGenericRank = Rank.INFRAGENERICTAXON();
|
805
|
}else{
|
806
|
String infraGenericRankMarker = epi[1];
|
807
|
if (infraGenericRankMarker.startsWith(notho)){ //#3868
|
808
|
nameToBeFilled.setBinomHybrid(true);
|
809
|
infraGenericRankMarker = infraGenericRankMarker.substring(notho.length());
|
810
|
}else if(infraGenericRankMarker.startsWith("n")){
|
811
|
nameToBeFilled.setBinomHybrid(true);
|
812
|
infraGenericRankMarker = infraGenericRankMarker.substring(1);
|
813
|
}
|
814
|
infraGenericRank = Rank.getRankByIdInVoc(infraGenericRankMarker, nameToBeFilledOrig.getNomenclaturalCode());
|
815
|
}
|
816
|
nameToBeFilled.setRank(infraGenericRank);
|
817
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
818
|
nameToBeFilled.setInfraGenericEpithet(epi[2]);
|
819
|
authorString = fullNameString.substring(epi[0].length() + 1 + epi[1].length()+ 1 + epi[2].length());
|
820
|
}
|
821
|
//aggr. or group
|
822
|
else if (aggrOrGroupPattern.matcher(fullNameString).matches()){
|
823
|
nameToBeFilled.setRank(Rank.getRankByIdInVoc(epi[2]));
|
824
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
825
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
826
|
}
|
827
|
//species
|
828
|
else if (speciesPattern.matcher(fullNameString).matches()){
|
829
|
nameToBeFilled.setRank(Rank.SPECIES());
|
830
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
831
|
nameToBeFilled.setSpecificEpithet(normalizeSpNov(epi[1]));
|
832
|
authorString = fullNameString.substring(epi[0].length() + 1 + epi[1].length());
|
833
|
}
|
834
|
//species with infra generic epithet
|
835
|
else if (speciesWithInfraGenPattern.matcher(fullNameString).matches()){
|
836
|
nameToBeFilled.setRank(Rank.SPECIES());
|
837
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
838
|
nameToBeFilled.setInfraGenericEpithet(epi[2]);
|
839
|
nameToBeFilled.setSpecificEpithet(epi[4]);
|
840
|
authorString = fullNameString.substring(epi[0].length() + 2 + epi[2].length() + 2 + epi[4].length());
|
841
|
}
|
842
|
//autonym
|
843
|
else if (autonymPattern.matcher(fullNameString).matches()){
|
844
|
nameToBeFilled.setRank(Rank.getRankByIdInVoc(epi[epi.length - 2]));
|
845
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
846
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
847
|
nameToBeFilled.setInfraSpecificEpithet(epi[epi.length - 1]);
|
848
|
int lenSpecies = 2 + epi[0].length()+epi[1].length();
|
849
|
int lenInfraSpecies = 2 + epi[epi.length - 2].length() + epi[epi.length - 1].length();
|
850
|
authorString = fullNameString.substring(lenSpecies, fullNameString.length() - lenInfraSpecies);
|
851
|
}
|
852
|
//infraSpecies
|
853
|
else if (infraSpeciesPattern.matcher(fullNameString).matches()){
|
854
|
String infraSpecRankMarker = epi[2];
|
855
|
String infraSpecEpi = epi[3];
|
856
|
if ("tax.".equals(infraSpecRankMarker)){
|
857
|
infraSpecRankMarker += " " + epi[3];
|
858
|
infraSpecEpi = epi[4];
|
859
|
}
|
860
|
Rank infraSpecificRank;
|
861
|
if ("[unranked]".equals(infraSpecRankMarker)){
|
862
|
infraSpecificRank = Rank.INFRASPECIFICTAXON();
|
863
|
}else{
|
864
|
String localInfraSpecRankMarker;
|
865
|
if (infraSpecRankMarker.startsWith(notho)){ //#3868
|
866
|
nameToBeFilled.setTrinomHybrid(true);
|
867
|
localInfraSpecRankMarker = infraSpecRankMarker.substring(notho.length());
|
868
|
}else if(infraSpecRankMarker.startsWith("n")){
|
869
|
nameToBeFilled.setTrinomHybrid(true);
|
870
|
localInfraSpecRankMarker = infraSpecRankMarker.substring(1);
|
871
|
}else{
|
872
|
localInfraSpecRankMarker = infraSpecRankMarker;
|
873
|
}
|
874
|
infraSpecificRank = Rank.getRankByIdInVoc(localInfraSpecRankMarker);
|
875
|
}
|
876
|
nameToBeFilled.setRank(infraSpecificRank);
|
877
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
878
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
879
|
nameToBeFilled.setInfraSpecificEpithet(infraSpecEpi);
|
880
|
authorString = fullNameString.substring(epi[0].length()+ 1 + epi[1].length() +1 + infraSpecRankMarker.length() + 1 + infraSpecEpi.length());
|
881
|
|
882
|
}
|
883
|
//infraSpecies without marker
|
884
|
else if (zooInfraSpeciesPattern.matcher(fullNameString).matches()){
|
885
|
String infraSpecEpi = epi[2];
|
886
|
Rank infraSpecificRank = Rank.SUBSPECIES();
|
887
|
nameToBeFilled.setRank(infraSpecificRank);
|
888
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
889
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
890
|
nameToBeFilled.setInfraSpecificEpithet(infraSpecEpi);
|
891
|
authorString = fullNameString.substring(epi[0].length()+ 1 + epi[1].length() +1 + infraSpecEpi.length());
|
892
|
|
893
|
}//old infraSpecies
|
894
|
else if (oldInfraSpeciesPattern.matcher(fullNameString).matches()){
|
895
|
boolean implemented = false;
|
896
|
if (implemented){
|
897
|
nameToBeFilled.setRank(Rank.getRankByNameOrIdInVoc(epi[2]));
|
898
|
nameToBeFilled.setGenusOrUninomial(epi[0]);
|
899
|
nameToBeFilled.setSpecificEpithet(epi[1]);
|
900
|
//TODO result.setUnnamedNamePhrase(epi[2] + " " + epi[3]);
|
901
|
authorString = fullNameString.substring(epi[0].length()+ 1 + epi[1].length() +1 + epi[2].length() + 1 + epi[3].length());
|
902
|
}else{
|
903
|
nameToBeFilled.addParsingProblem(ParserProblem.OldInfraSpeciesNotSupported);
|
904
|
nameToBeFilled.setTitleCache(fullNameString, true);
|
905
|
// FIXME Quick fix, otherwise search would not deilver results for unparsable names
|
906
|
nameToBeFilled.setNameCache(fullNameString,true);
|
907
|
// END
|
908
|
logger.info("Name string " + fullNameString + " could not be parsed because UnnnamedNamePhrase is not yet implemented!");
|
909
|
}
|
910
|
}
|
911
|
//hybrid formula
|
912
|
else if (hybridFormulaPattern.matcher(fullNameString).matches()){
|
913
|
Set<HybridRelationship> existingRelations = new HashSet<>();
|
914
|
Set<HybridRelationship> notToBeDeleted = new HashSet<>();
|
915
|
|
916
|
for ( HybridRelationship rel : nameToBeFilled.getHybridChildRelations()){
|
917
|
existingRelations.add(rel);
|
918
|
}
|
919
|
|
920
|
String firstNameString = "";
|
921
|
String secondNameString = "";
|
922
|
boolean isFirstName = true;
|
923
|
for (String str : epi){
|
924
|
if (str.matches(hybridSign)){
|
925
|
isFirstName = false;
|
926
|
}else if(isFirstName){
|
927
|
firstNameString += " " + str;
|
928
|
}else {
|
929
|
secondNameString += " " + str;
|
930
|
}
|
931
|
}
|
932
|
firstNameString = firstNameString.trim();
|
933
|
secondNameString = secondNameString.trim();
|
934
|
nameToBeFilled.setHybridFormula(true);
|
935
|
NomenclaturalCode code = nameToBeFilled.getNomenclaturalCode();
|
936
|
INonViralName firstName = this.parseFullName(firstNameString, code, rank);
|
937
|
if (secondNameString.matches(abbrevHybridSecondPart)){
|
938
|
secondNameString = extendSecondHybridPart(firstName, secondNameString);
|
939
|
}
|
940
|
INonViralName secondName = this.parseFullName(secondNameString, code, rank);
|
941
|
HybridRelationship firstRel = nameToBeFilled.addHybridParent(firstName, HybridRelationshipType.FIRST_PARENT(), null);
|
942
|
HybridRelationship second = nameToBeFilled.addHybridParent(secondName, HybridRelationshipType.SECOND_PARENT(), null);
|
943
|
checkRelationExist(firstRel, existingRelations, notToBeDeleted);
|
944
|
checkRelationExist(second, existingRelations, notToBeDeleted);
|
945
|
|
946
|
Rank newRank;
|
947
|
Rank firstRank = firstName.getRank();
|
948
|
Rank secondRank = secondName.getRank();
|
949
|
|
950
|
if (firstRank == null || (secondRank != null && firstRank.isHigher(secondRank))){
|
951
|
newRank = secondRank;
|
952
|
}else{
|
953
|
newRank = firstRank;
|
954
|
}
|
955
|
nameToBeFilled.setRank(newRank);
|
956
|
//remove not existing hybrid relation
|
957
|
if (makeEmpty){
|
958
|
Set<HybridRelationship> tmpChildRels = new HashSet<HybridRelationship>();
|
959
|
tmpChildRels.addAll(nameToBeFilled.getHybridChildRelations());
|
960
|
for (HybridRelationship rel : tmpChildRels){
|
961
|
if (! notToBeDeleted.contains(rel)){
|
962
|
nameToBeFilled.removeHybridRelationship(rel);
|
963
|
}
|
964
|
}
|
965
|
}
|
966
|
}
|
967
|
//none
|
968
|
else{
|
969
|
nameToBeFilled.addParsingProblem(ParserProblem.UnparsableNamePart);
|
970
|
nameToBeFilled.setTitleCache(fullNameString, true);
|
971
|
// FIXME Quick fix, otherwise search would not deilver results for unparsable names
|
972
|
nameToBeFilled.setNameCache(fullNameString, true);
|
973
|
// END
|
974
|
logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
|
975
|
}
|
976
|
//hybrid bits
|
977
|
handleHybridBits(nameToBeFilled);
|
978
|
if (!nameToBeFilled.isHybridFormula()){
|
979
|
Set<HybridRelationship> hybridChildRelations = new HashSet<>();
|
980
|
hybridChildRelations.addAll(nameToBeFilled.getHybridChildRelations());
|
981
|
|
982
|
for (HybridRelationship hybridRelationship: hybridChildRelations){
|
983
|
nameToBeFilled.removeHybridRelationship(hybridRelationship);
|
984
|
}
|
985
|
}
|
986
|
|
987
|
//authors
|
988
|
if (StringUtils.isNotBlank(authorString) ){
|
989
|
handleAuthors(nameToBeFilled, fullNameString, authorString);
|
990
|
}
|
991
|
return;
|
992
|
} catch (UnknownCdmTypeException e) {
|
993
|
nameToBeFilled.addParsingProblem(ParserProblem.RankNotSupported);
|
994
|
nameToBeFilled.setTitleCache(fullNameString, true);
|
995
|
// FIXME Quick fix, otherwise search would not deilver results for unparsable names
|
996
|
nameToBeFilled.setNameCache(fullNameString,true);
|
997
|
// END
|
998
|
logger.info("unknown rank (" + (rank == null? "null":rank) + ") or abbreviation in string " + fullNameString);
|
999
|
//return result;
|
1000
|
return;
|
1001
|
}
|
1002
|
}
|
1003
|
|
1004
|
/**
|
1005
|
* @param string
|
1006
|
* @return
|
1007
|
*/
|
1008
|
private String normalizeSpNov(String epi) {
|
1009
|
if (spNovPattern.matcher(epi).matches()){
|
1010
|
epi = epi.replace(".", ". ").replace("\\s+", " ").trim();
|
1011
|
}
|
1012
|
return epi;
|
1013
|
}
|
1014
|
|
1015
|
/**
|
1016
|
* @param firstName
|
1017
|
* @param secondNameString
|
1018
|
* @return
|
1019
|
*/
|
1020
|
private String extendSecondHybridPart(INonViralName firstName, String secondNameString) {
|
1021
|
//first letter of genus given
|
1022
|
if (secondNameString.matches("^" + abbrevHybridGenus + ".*")){
|
1023
|
if (StringUtils.isNotBlank(firstName.getGenusOrUninomial())){
|
1024
|
if (secondNameString.substring(0,1).equals(firstName.getGenusOrUninomial().substring(0, 1))){
|
1025
|
secondNameString = secondNameString.replaceAll("^" + abbrevHybridGenus, firstName.getGenusOrUninomial() + " ");
|
1026
|
}
|
1027
|
}
|
1028
|
}else if (secondNameString.matches(abbrevHybridSecondPartOnlyInfraSpecies)){
|
1029
|
secondNameString = CdmUtils.concat(" " , firstName.getGenusOrUninomial(), firstName.getSpecificEpithet(), secondNameString);
|
1030
|
}else if (true){ //there will be further alternatives in future maybe
|
1031
|
secondNameString = CdmUtils.concat(" " , firstName.getGenusOrUninomial(), secondNameString);
|
1032
|
}
|
1033
|
return secondNameString;
|
1034
|
}
|
1035
|
|
1036
|
/**
|
1037
|
* Checks if a hybrid relation exists in the Set of existing relations
|
1038
|
* and <BR>
|
1039
|
* if it does not adds it to relations not to be deleted <BR>
|
1040
|
* if it does adds the existing relations to the relations not to be deleted
|
1041
|
*
|
1042
|
* @param firstRel
|
1043
|
* @param existingRelations
|
1044
|
* @param notToBeDeleted
|
1045
|
*/
|
1046
|
private void checkRelationExist(
|
1047
|
HybridRelationship newRelation,
|
1048
|
Set<HybridRelationship> existingRelations,
|
1049
|
Set<HybridRelationship> notToBeDeleted) {
|
1050
|
HybridRelationship relToKeep = newRelation;
|
1051
|
for (HybridRelationship existingRelation : existingRelations){
|
1052
|
if (existingRelation.equals(newRelation)){
|
1053
|
relToKeep = existingRelation;
|
1054
|
break;
|
1055
|
}
|
1056
|
}
|
1057
|
notToBeDeleted.add(relToKeep);
|
1058
|
}
|
1059
|
|
1060
|
private void handleHybridBits(INonViralName nameToBeFilled) {
|
1061
|
//uninomial
|
1062
|
String uninomial = CdmUtils.Nz(nameToBeFilled.getGenusOrUninomial());
|
1063
|
boolean isUninomialHybrid = uninomial.startsWith(hybridSign);
|
1064
|
if (isUninomialHybrid){
|
1065
|
nameToBeFilled.setMonomHybrid(true);
|
1066
|
nameToBeFilled.setGenusOrUninomial(uninomial.replace(hybridSign, ""));
|
1067
|
}
|
1068
|
//infrageneric
|
1069
|
String infrageneric = CdmUtils.Nz(nameToBeFilled.getInfraGenericEpithet());
|
1070
|
boolean isInfraGenericHybrid = infrageneric.startsWith(hybridSign);
|
1071
|
if (isInfraGenericHybrid){
|
1072
|
nameToBeFilled.setBinomHybrid(true);
|
1073
|
nameToBeFilled.setInfraGenericEpithet(infrageneric.replace(hybridSign, ""));
|
1074
|
}
|
1075
|
//species Epi
|
1076
|
String speciesEpi = CdmUtils.Nz(nameToBeFilled.getSpecificEpithet());
|
1077
|
boolean isSpeciesHybrid = speciesEpi.startsWith(hybridSign);
|
1078
|
if (isSpeciesHybrid){
|
1079
|
if (StringUtils.isBlank(infrageneric)){
|
1080
|
nameToBeFilled.setBinomHybrid(true);
|
1081
|
}else{
|
1082
|
nameToBeFilled.setTrinomHybrid(true);
|
1083
|
}
|
1084
|
nameToBeFilled.setSpecificEpithet(speciesEpi.replace(hybridSign, ""));
|
1085
|
}
|
1086
|
//infra species
|
1087
|
String infraSpeciesEpi = CdmUtils.Nz(nameToBeFilled.getInfraSpecificEpithet());
|
1088
|
boolean isInfraSpeciesHybrid = infraSpeciesEpi.startsWith(hybridSign);
|
1089
|
if (isInfraSpeciesHybrid){
|
1090
|
nameToBeFilled.setTrinomHybrid(true);
|
1091
|
nameToBeFilled.setInfraSpecificEpithet(infraSpeciesEpi.replace(hybridSign, ""));
|
1092
|
}
|
1093
|
|
1094
|
}
|
1095
|
|
1096
|
private String removeHybridBlanks(String fullNameString) {
|
1097
|
String result = fullNameString
|
1098
|
.replaceAll(oWs + "[xX]" + oWs + "(?=[A-Z])", " " + hybridSign + " ")
|
1099
|
.replaceAll(hybridFull, " " + hybridSign).trim();
|
1100
|
if (result.contains(hybridSign + " ") &&
|
1101
|
result.matches("^" + capitalEpiWord + oWs + hybridSign + oWs + nonCapitalEpiWord + ".*")){
|
1102
|
result = result.replaceFirst(hybridSign + oWs, hybridSign);
|
1103
|
}
|
1104
|
return result;
|
1105
|
}
|
1106
|
|
1107
|
|
1108
|
private String removeSpNovBlanks(String fullNameString) {
|
1109
|
Matcher spNovMatcher = spNovPattern.matcher(fullNameString);
|
1110
|
if (spNovMatcher.find()){
|
1111
|
String spNov = spNovMatcher.group(0);
|
1112
|
String spNovShort = spNov.replaceAll("\\s", "");
|
1113
|
if (spNov.length() != spNovShort.length()){
|
1114
|
fullNameString = fullNameString.replace(spNov, spNovShort);
|
1115
|
}
|
1116
|
}
|
1117
|
return fullNameString;
|
1118
|
}
|
1119
|
|
1120
|
|
1121
|
/**
|
1122
|
* Author parser for external use
|
1123
|
* @param nonViralName
|
1124
|
* @param authorString
|
1125
|
* @throws StringNotParsableException
|
1126
|
*/
|
1127
|
@Override
|
1128
|
public void parseAuthors(INonViralName nonViralNameOrig, String authorString) throws StringNotParsableException{
|
1129
|
INonViralName nonViralName = nonViralNameOrig;
|
1130
|
TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
|
1131
|
Integer[] years = new Integer[4];
|
1132
|
Class<? extends INonViralName> clazz = nonViralName.getClass();
|
1133
|
fullAuthors(authorString, authors, years, clazz);
|
1134
|
nonViralName.setCombinationAuthorship(authors[0]);
|
1135
|
nonViralName.setExCombinationAuthorship(authors[1]);
|
1136
|
nonViralName.setBasionymAuthorship(authors[2]);
|
1137
|
nonViralName.setExBasionymAuthorship(authors[3]);
|
1138
|
if (nonViralName instanceof ZoologicalName){
|
1139
|
IZoologicalName zooName = CdmBase.deproxy(nonViralName, ZoologicalName.class);
|
1140
|
zooName.setPublicationYear(years[0]);
|
1141
|
zooName.setOriginalPublicationYear(years[2]);
|
1142
|
}
|
1143
|
}
|
1144
|
|
1145
|
/**
|
1146
|
* @param nameToBeFilled
|
1147
|
* @param fullNameString
|
1148
|
* @param authorString
|
1149
|
*/
|
1150
|
public void handleAuthors(INonViralName nameToBeFilled, String fullNameString, String authorString) {
|
1151
|
TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
|
1152
|
Integer[] years = new Integer[4];
|
1153
|
try {
|
1154
|
Class<? extends INonViralName> clazz = nameToBeFilled.getClass();
|
1155
|
fullAuthors(authorString, authors, years, clazz);
|
1156
|
} catch (StringNotParsableException e) {
|
1157
|
nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
|
1158
|
nameToBeFilled.setTitleCache(fullNameString, true);
|
1159
|
// FIXME Quick fix, otherwise search would not deliver results for unparsable names
|
1160
|
nameToBeFilled.setNameCache(fullNameString, true);
|
1161
|
// END
|
1162
|
logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");;
|
1163
|
}
|
1164
|
nameToBeFilled.setCombinationAuthorship(authors[0]);
|
1165
|
nameToBeFilled.setExCombinationAuthorship(authors[1]);
|
1166
|
nameToBeFilled.setBasionymAuthorship(authors[2]);
|
1167
|
nameToBeFilled.setExBasionymAuthorship(authors[3]);
|
1168
|
if (nameToBeFilled instanceof ZoologicalName){
|
1169
|
IZoologicalName zooName = (ZoologicalName)nameToBeFilled;
|
1170
|
zooName.setPublicationYear(years[0]);
|
1171
|
zooName.setOriginalPublicationYear(years[2]);
|
1172
|
}
|
1173
|
}
|
1174
|
|
1175
|
/**
|
1176
|
* Guesses the rank of uninomial depending on the typical endings for ranks
|
1177
|
* @param nameToBeFilled
|
1178
|
* @param string
|
1179
|
*/
|
1180
|
private Rank guessUninomialRank(INonViralName nameToBeFilled, String uninomial) {
|
1181
|
Rank result = Rank.GENUS();
|
1182
|
if (nameToBeFilled.isInstanceOf(BotanicalName.class)){
|
1183
|
if (false){
|
1184
|
//
|
1185
|
}else if (uninomial.endsWith("phyta") || uninomial.endsWith("mycota") ){ //plants, fungi
|
1186
|
result = Rank.SECTION_BOTANY();
|
1187
|
}else if (uninomial.endsWith("bionta")){
|
1188
|
result = Rank.SUBKINGDOM(); //TODO
|
1189
|
}else if (uninomial.endsWith("phytina")|| uninomial.endsWith("mycotina") ){ //plants, fungi
|
1190
|
result = Rank.SUBSECTION_BOTANY();
|
1191
|
}else if (uninomial.endsWith("opsida") || uninomial.endsWith("phyceae") || uninomial.endsWith("mycetes")){ //plants, algae, fungi
|
1192
|
result = Rank.CLASS();
|
1193
|
}else if (uninomial.endsWith("idae") || uninomial.endsWith("phycidae") || uninomial.endsWith("mycetidae")){ //plants, algae, fungi
|
1194
|
result = Rank.SUBCLASS();
|
1195
|
}else if (uninomial.endsWith("ales")){
|
1196
|
result = Rank.ORDER();
|
1197
|
}else if (uninomial.endsWith("ineae")){
|
1198
|
result = Rank.SUBORDER();
|
1199
|
}else if (uninomial.endsWith("aceae")){
|
1200
|
result = Rank.FAMILY();
|
1201
|
}else if (uninomial.endsWith("oideae")){
|
1202
|
result = Rank.SUBFAMILY();
|
1203
|
}else if (uninomial.endsWith("eae")){
|
1204
|
result = Rank.TRIBE();
|
1205
|
}else if (uninomial.endsWith("inae")){
|
1206
|
result = Rank.SUBTRIBE();
|
1207
|
}else if (uninomial.endsWith("ota")){
|
1208
|
result = Rank.KINGDOM(); //TODO
|
1209
|
}
|
1210
|
}else if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
|
1211
|
if (false){
|
1212
|
//
|
1213
|
}else if (uninomial.endsWith("oideae")){
|
1214
|
result = Rank.SUPERFAMILY();
|
1215
|
}else if (uninomial.endsWith("idae")){
|
1216
|
result = Rank.FAMILY();
|
1217
|
}else if (uninomial.endsWith("inae")){
|
1218
|
result = Rank.SUBFAMILY();
|
1219
|
}else if (uninomial.endsWith("inae")){
|
1220
|
result = Rank.SUBFAMILY();
|
1221
|
}else if (uninomial.endsWith("ini")){
|
1222
|
result = Rank.TRIBE();
|
1223
|
}else if (uninomial.endsWith("ina")){
|
1224
|
result = Rank.SUBTRIBE();
|
1225
|
}
|
1226
|
}else{
|
1227
|
//
|
1228
|
}
|
1229
|
return result;
|
1230
|
}
|
1231
|
|
1232
|
/**
|
1233
|
* Parses the fullAuthorString
|
1234
|
* @param fullAuthorString
|
1235
|
* @return array of Teams containing the Team[0],
|
1236
|
* ExTeam[1], BasionymTeam[2], ExBasionymTeam[3]
|
1237
|
*/
|
1238
|
protected void fullAuthors (String fullAuthorStringOrig, TeamOrPersonBase<?>[] authors,
|
1239
|
Integer[] years, Class<? extends INonViralName> clazz)
|
1240
|
throws StringNotParsableException{
|
1241
|
if (fullAuthorStringOrig == null || clazz == null){
|
1242
|
return;
|
1243
|
}
|
1244
|
String fullAuthorString = fullAuthorStringOrig.trim();
|
1245
|
|
1246
|
//Botanic
|
1247
|
if ( BotanicalName.class.isAssignableFrom(clazz) ){
|
1248
|
if (! fullBotanicAuthorStringPattern.matcher(fullAuthorString).matches() ){
|
1249
|
throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
|
1250
|
}
|
1251
|
}
|
1252
|
//Zoo
|
1253
|
else if ( ZoologicalName.class.isAssignableFrom(clazz) ){
|
1254
|
if (! fullZooAuthorStringPattern.matcher(fullAuthorString).matches() ){
|
1255
|
throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
|
1256
|
}
|
1257
|
}else {
|
1258
|
//TODO
|
1259
|
logger.warn ("Full author String parsable only for defined BotanicalNames or ZoologicalNames but this is " + clazz.getSimpleName());
|
1260
|
throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
|
1261
|
}
|
1262
|
fullAuthorsChecked(fullAuthorString, authors, years);
|
1263
|
}
|
1264
|
|
1265
|
/*
|
1266
|
* like fullTeams but without trim and match check
|
1267
|
*/
|
1268
|
protected void fullAuthorsChecked (String fullAuthorString, TeamOrPersonBase<?>[] authors, Integer[] years){
|
1269
|
int authorShipStart = 0;
|
1270
|
Matcher basionymMatcher = basionymPattern.matcher(fullAuthorString);
|
1271
|
|
1272
|
if (basionymMatcher.find(0)){
|
1273
|
|
1274
|
String basString = basionymMatcher.group();
|
1275
|
basString = basString.replaceFirst(basStart, "");
|
1276
|
basString = basString.replaceAll(basEnd, "").trim();
|
1277
|
authorShipStart = basionymMatcher.end(1);
|
1278
|
|
1279
|
TeamOrPersonBase<?>[] basAuthors = new TeamOrPersonBase[2];
|
1280
|
Integer[] basYears = new Integer[2];
|
1281
|
authorsAndEx(basString, basAuthors, basYears);
|
1282
|
authors[2]= basAuthors[0];
|
1283
|
years[2] = basYears[0];
|
1284
|
authors[3]= basAuthors[1];
|
1285
|
years[3] = basYears[1];
|
1286
|
}
|
1287
|
if (fullAuthorString.length() >= authorShipStart){
|
1288
|
TeamOrPersonBase<?>[] combinationAuthors = new TeamOrPersonBase[2];
|
1289
|
Integer[] combinationYears = new Integer[2];
|
1290
|
authorsAndEx(fullAuthorString.substring(authorShipStart), combinationAuthors, combinationYears);
|
1291
|
authors[0]= combinationAuthors[0] ;
|
1292
|
years[0] = combinationYears[0];
|
1293
|
authors[1]= combinationAuthors[1];
|
1294
|
years[1] = combinationYears[1];
|
1295
|
}
|
1296
|
}
|
1297
|
|
1298
|
|
1299
|
/**
|
1300
|
* Parses the author and ex-author String
|
1301
|
* @param authorShipStringOrig String representing the author and the ex-author team
|
1302
|
* @return array of Teams containing the Team[0] and the ExTeam[1]
|
1303
|
*/
|
1304
|
protected void authorsAndEx (String authorShipStringOrig, TeamOrPersonBase<?>[] authors, Integer[] years){
|
1305
|
//TODO noch allgemeiner am Anfang durch Replace etc.
|
1306
|
String authorShipString = authorShipStringOrig.trim();
|
1307
|
authorShipString = authorShipString.replaceFirst(oWs + "ex" + oWs, " ex. " );
|
1308
|
|
1309
|
//int authorEnd = authorTeamString.length();
|
1310
|
int authorBegin = 0;
|
1311
|
|
1312
|
Matcher exAuthorMatcher = exAuthorPattern.matcher(authorShipString);
|
1313
|
if (exAuthorMatcher.find(0)){
|
1314
|
authorBegin = exAuthorMatcher.end(0);
|
1315
|
int exAuthorEnd = exAuthorMatcher.start(0);
|
1316
|
String exString = authorShipString.substring(0, exAuthorEnd).trim();
|
1317
|
authors [1] = author(exString);
|
1318
|
}
|
1319
|
zooOrBotanicAuthor(authorShipString.substring(authorBegin), authors, years );
|
1320
|
}
|
1321
|
|
1322
|
/**
|
1323
|
* Parses the authorString and if it matches an botanical or zoological authorTeam it fills
|
1324
|
* the computes the AuthorTeam and fills it into the first field of the team array. Same applies
|
1325
|
* to the year in case of an zoological name.
|
1326
|
* @param authorString
|
1327
|
* @param team
|
1328
|
* @param year
|
1329
|
*/
|
1330
|
protected void zooOrBotanicAuthor(String authorString, TeamOrPersonBase<?>[] team, Integer[] year){
|
1331
|
if (authorString == null){
|
1332
|
return;
|
1333
|
}else if ((authorString = authorString.trim()).length() == 0){
|
1334
|
return;
|
1335
|
}
|
1336
|
Matcher zooAuthorAddidtionMatcher = zooAuthorAddidtionPattern.matcher(authorString);
|
1337
|
if (zooAuthorAddidtionMatcher.find()){
|
1338
|
int index = zooAuthorAddidtionMatcher.start(0);
|
1339
|
String strYear = authorString.substring(index);
|
1340
|
strYear = strYear.replaceAll(zooAuthorYearSeperator, "").trim();
|
1341
|
year[0] = Integer.valueOf(strYear);
|
1342
|
authorString = authorString.substring(0, index).trim();
|
1343
|
}
|
1344
|
team[0] = author(authorString);
|
1345
|
}
|
1346
|
|
1347
|
|
1348
|
/**
|
1349
|
* Parses an authorTeam String and returns the team.
|
1350
|
* !!! TODO (atomization not yet implemented)
|
1351
|
* @param authorString String representing the author
|
1352
|
* @return an Team
|
1353
|
*/
|
1354
|
public TeamOrPersonBase<?> author (String authorString){
|
1355
|
if (authorString == null){
|
1356
|
return null;
|
1357
|
}else if ((authorString = authorString.trim()).length() == 0){
|
1358
|
return null;
|
1359
|
}else if (! finalTeamSplitterPattern.matcher(authorString).find() && ! authorIsAlwaysTeam){
|
1360
|
//1 Person
|
1361
|
Person result = Person.NewInstance();
|
1362
|
result.setNomenclaturalTitle(authorString);
|
1363
|
return result;
|
1364
|
}else{
|
1365
|
return parsedTeam(authorString);
|
1366
|
}
|
1367
|
|
1368
|
}
|
1369
|
|
1370
|
/**
|
1371
|
* Parses an authorString (reprsenting a team into the single authors and add
|
1372
|
* them to the return Team.
|
1373
|
* @param authorString
|
1374
|
* @return Team
|
1375
|
*/
|
1376
|
protected Team parsedTeam(String authorString){
|
1377
|
Team result = Team.NewInstance();
|
1378
|
String[] authors = authorString.split(notFinalTeamSplitter);
|
1379
|
for (int i = 0; i < authors.length; i++){
|
1380
|
String author = authors[i];
|
1381
|
if ("al.".equals(author.trim()) && i == authors.length - 1){ //final al. is handled as hasMoreMembers
|
1382
|
result.setHasMoreMembers(true);
|
1383
|
}else{
|
1384
|
Person person = Person.NewInstance();
|
1385
|
person.setNomenclaturalTitle(author);
|
1386
|
result.addTeamMember(person);
|
1387
|
}
|
1388
|
}
|
1389
|
return result;
|
1390
|
}
|
1391
|
|
1392
|
|
1393
|
// // Parsing of the given full name that has been identified as a cultivar already somwhere else.
|
1394
|
// // The ... cv. ... syntax is not covered here as it is not according the rules for naming cultivars.
|
1395
|
public BotanicalName parseCultivar(String fullName) throws StringNotParsableException{
|
1396
|
CultivarPlantName result = null;
|
1397
|
String[] words = oWsPattern.split(fullName);
|
1398
|
|
1399
|
/* ---------------------------------------------------------------------------------
|
1400
|
* cultivar
|
1401
|
* ---------------------------------------------------------------------------------*/
|
1402
|
if (fullName.indexOf(" '") != 0){
|
1403
|
//TODO location of 'xx' is probably not arbitrary
|
1404
|
Matcher cultivarMatcher = cultivarPattern.matcher(fullName);
|
1405
|
if (cultivarMatcher.find()){
|
1406
|
String namePart = fullName.replaceFirst(cultivar, "");
|
1407
|
|
1408
|
String cultivarPart = cultivarMatcher.group(0).replace("'","").trim();
|
1409
|
//OLD: String cultivarPart = cultivarRE.getParen(0).replace("'","").trim();
|
1410
|
|
1411
|
result = (CultivarPlantName)parseFullName(namePart);
|
1412
|
result.setCultivarName(cultivarPart);
|
1413
|
}
|
1414
|
}else if (fullName.indexOf(" cv.") != 0){
|
1415
|
// cv. is old form (not official)
|
1416
|
throw new StringNotParsableException("Cultivars with only cv. not yet implemented in name parser!");
|
1417
|
}
|
1418
|
|
1419
|
/* ---------------------------------------------------------------------------------
|
1420
|
* cultivar group
|
1421
|
* ---------------------------------------------------------------------------------
|
1422
|
*/
|
1423
|
// TODO in work
|
1424
|
//Ann. this is not the official way of noting cultivar groups
|
1425
|
String group = oWs + "Group" + oWs + capitalEpiWord + end;
|
1426
|
Pattern groupRE = Pattern.compile(group);
|
1427
|
Matcher groupMatcher = groupRE.matcher(fullName);
|
1428
|
if (groupMatcher.find()){
|
1429
|
if (! words[words.length - 2].equals("group")){
|
1430
|
throw new StringNotParsableException ("fct ParseHybrid --> term before cultivar group name in " + fullName + " should be 'group'");
|
1431
|
}else{
|
1432
|
|
1433
|
String namePart = fullName.substring(0, groupMatcher.start(0) - 0);
|
1434
|
//OLD: String namePart = fullName.substring(0, groupRE.getParenStart(0) - 0);
|
1435
|
|
1436
|
String cultivarPart = words[words.length -1];
|
1437
|
result = (CultivarPlantName)parseFullName(namePart);
|
1438
|
if (result != null){
|
1439
|
result.setCultivarName(cultivarPart);
|
1440
|
|
1441
|
//OLD: result.setCultivarGroupName(cultivarPart);
|
1442
|
}
|
1443
|
}
|
1444
|
|
1445
|
}
|
1446
|
// // ---------------------------------------------------------------------------------
|
1447
|
// if ( result = "" ){
|
1448
|
// return "I: fct ParseCultivar: --> could not parse cultivar " + fullName;
|
1449
|
// }else{
|
1450
|
// return result;
|
1451
|
// }
|
1452
|
return result; //TODO
|
1453
|
}
|
1454
|
|
1455
|
|
1456
|
private void makeEmpty(INonViralName nameToBeFilled){
|
1457
|
nameToBeFilled.setRank(null);
|
1458
|
nameToBeFilled.setTitleCache(null, false);
|
1459
|
nameToBeFilled.setFullTitleCache(null, false);
|
1460
|
nameToBeFilled.setNameCache(null, false);
|
1461
|
|
1462
|
nameToBeFilled.setAppendedPhrase(null);
|
1463
|
nameToBeFilled.setBasionymAuthorship(null);
|
1464
|
nameToBeFilled.setCombinationAuthorship(null);
|
1465
|
nameToBeFilled.setExBasionymAuthorship(null);
|
1466
|
nameToBeFilled.setExCombinationAuthorship(null);
|
1467
|
nameToBeFilled.setAuthorshipCache(null, false);
|
1468
|
|
1469
|
|
1470
|
//delete problems except check rank
|
1471
|
makeProblemEmpty(nameToBeFilled);
|
1472
|
|
1473
|
// TODO ?
|
1474
|
//nameToBeFilled.setHomotypicalGroup(newHomotypicalGroup);
|
1475
|
|
1476
|
|
1477
|
nameToBeFilled.setGenusOrUninomial(null);
|
1478
|
nameToBeFilled.setInfraGenericEpithet(null);
|
1479
|
nameToBeFilled.setSpecificEpithet(null);
|
1480
|
nameToBeFilled.setInfraSpecificEpithet(null);
|
1481
|
|
1482
|
nameToBeFilled.setNomenclaturalMicroReference(null);
|
1483
|
nameToBeFilled.setNomenclaturalReference(null);
|
1484
|
|
1485
|
nameToBeFilled.setHybridFormula(false);
|
1486
|
nameToBeFilled.setMonomHybrid(false);
|
1487
|
nameToBeFilled.setBinomHybrid(false);
|
1488
|
nameToBeFilled.setTrinomHybrid(false);
|
1489
|
|
1490
|
if (nameToBeFilled.isInstanceOf(BotanicalName.class)){
|
1491
|
BotanicalName botanicalName = (BotanicalName)nameToBeFilled;
|
1492
|
botanicalName.setAnamorphic(false);
|
1493
|
}
|
1494
|
|
1495
|
if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
|
1496
|
IZoologicalName zoologicalName = (ZoologicalName)nameToBeFilled;
|
1497
|
zoologicalName.setBreed(null);
|
1498
|
zoologicalName.setOriginalPublicationYear(null);
|
1499
|
}
|
1500
|
|
1501
|
//nom status handled in nom status parser, otherwise we loose additional information like reference etc.
|
1502
|
//hybrid relationships handled in hybrid formula and at end of fullNameParser
|
1503
|
}
|
1504
|
|
1505
|
|
1506
|
|
1507
|
}
|