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
|
|
10
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.Collections;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Objects;
|
21
|
import java.util.Set;
|
22
|
import java.util.UUID;
|
23
|
|
24
|
import org.apache.log4j.Logger;
|
25
|
import org.springframework.stereotype.Component;
|
26
|
|
27
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
28
|
import eu.etaxonomy.cdm.database.update.DatabaseTypeNotSupportedException;
|
29
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
30
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelTaxonNameImportValidator;
|
31
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
32
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
33
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
34
|
import eu.etaxonomy.cdm.io.common.Source;
|
35
|
import eu.etaxonomy.cdm.model.agent.Team;
|
36
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
37
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
38
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
39
|
import eu.etaxonomy.cdm.model.common.Extension;
|
40
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
41
|
import eu.etaxonomy.cdm.model.common.Language;
|
42
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
43
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
44
|
import eu.etaxonomy.cdm.model.name.ICultivarPlantName;
|
45
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
46
|
import eu.etaxonomy.cdm.model.name.Rank;
|
47
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
48
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
49
|
import eu.etaxonomy.cdm.model.reference.IJournal;
|
50
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
51
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
52
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
53
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
54
|
import eu.etaxonomy.cdm.model.term.Representation;
|
55
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
56
|
import eu.etaxonomy.cdm.strategy.match.FieldMatcher;
|
57
|
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
|
58
|
import eu.etaxonomy.cdm.strategy.match.IMatchStrategyEqual;
|
59
|
import eu.etaxonomy.cdm.strategy.match.MatchException;
|
60
|
import eu.etaxonomy.cdm.strategy.match.MatchMode;
|
61
|
import eu.etaxonomy.cdm.strategy.match.MatchResult;
|
62
|
import eu.etaxonomy.cdm.strategy.match.MatchStrategyFactory;
|
63
|
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
|
64
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
65
|
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
|
66
|
|
67
|
/**
|
68
|
* @author a.mueller
|
69
|
* @since 20.03.2008
|
70
|
*/
|
71
|
@Component
|
72
|
public class BerlinModelTaxonNameImport extends BerlinModelImportBase {
|
73
|
private static final long serialVersionUID = -8860800694286602016L;
|
74
|
|
75
|
private static final boolean BLANK_TO_NULL = true;
|
76
|
|
77
|
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameImport.class);
|
78
|
|
79
|
public static final String NAMESPACE = "TaxonName";
|
80
|
|
81
|
public static final String NAMESPACE_PRELIM = "RefDetail_Preliminary";
|
82
|
|
83
|
private static int modCount = 5000;
|
84
|
private static final String pluralString = "TaxonNames";
|
85
|
private static final String dbTableName = "Name";
|
86
|
|
87
|
|
88
|
public BerlinModelTaxonNameImport(){
|
89
|
super(dbTableName, pluralString);
|
90
|
}
|
91
|
|
92
|
|
93
|
@Override
|
94
|
protected String getIdQuery(BerlinModelImportState state) {
|
95
|
if (state.getConfig().getNameIdTable() == null ){
|
96
|
return super.getIdQuery(state);
|
97
|
}else{
|
98
|
return "SELECT nameId FROM " + state.getConfig().getNameIdTable()
|
99
|
// + " WHERE nameId = 146109 "
|
100
|
;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
@Override
|
105
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
106
|
Source source = config.getSource();
|
107
|
|
108
|
String facultativCols = "";
|
109
|
String strFacTable = "RefDetail";
|
110
|
String strFacColumn = "IdInSource";
|
111
|
String strColAlias = null;
|
112
|
if (checkSqlServerColumnExists(source, strFacTable, strFacColumn)){
|
113
|
facultativCols += ", " + strFacTable + "." + strFacColumn ;
|
114
|
if (! CdmUtils.Nz(strColAlias).equals("") ){
|
115
|
facultativCols += " AS " + strColAlias;
|
116
|
}
|
117
|
}
|
118
|
|
119
|
String strRecordQuery =
|
120
|
"SELECT Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +
|
121
|
" RefDetail.FullRefCache, RefDetail.FullNomRefCache, RefDetail.PreliminaryFlag AS RefDetailPrelim, RefDetail.Details, " +
|
122
|
" RefDetail.SecondarySources, RefDetail.Notes as detailNotes, Rank.RankAbbrev, Rank.Rank " +
|
123
|
facultativCols +
|
124
|
" FROM Name LEFT OUTER JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId " +
|
125
|
" AND Name.NomRefFk = RefDetail.RefFk " +
|
126
|
" LEFT OUTER JOIN Rank ON Name.RankFk = Rank.rankID " +
|
127
|
" WHERE name.nameId IN ("+ID_LIST_TOKEN+") ";
|
128
|
// strRecordQuery += " AND RefDetail.PreliminaryFlag = 1 ";
|
129
|
//strQuery += " AND Name.Created_When > '03.03.2004' ";
|
130
|
return strRecordQuery + "";
|
131
|
}
|
132
|
|
133
|
|
134
|
private class ReferenceMapping{
|
135
|
public Map<String, ReferenceWrapper> titleMapping = new HashMap<>();
|
136
|
public Map<String, ReferenceWrapper> abbrevMapping = new HashMap<>();
|
137
|
|
138
|
private class ReferenceWrapper {
|
139
|
Set<ReferenceCandidate> candidates = new HashSet<>();
|
140
|
|
141
|
public Set<ReferenceCandidate> getCandidates() {
|
142
|
return candidates;
|
143
|
}
|
144
|
public void add(Reference ref, String detail) {
|
145
|
candidates.add(new ReferenceCandidate(ref, detail));
|
146
|
}
|
147
|
}
|
148
|
private void unload(){
|
149
|
titleMapping.clear();
|
150
|
abbrevMapping.clear();
|
151
|
}
|
152
|
|
153
|
public void addCandidate(Reference ref, String detail) {
|
154
|
String hash = refHash(ref);
|
155
|
ReferenceWrapper wrap = abbrevMapping.get(hash);
|
156
|
if (wrap == null){
|
157
|
wrap = new ReferenceWrapper();
|
158
|
abbrevMapping.put(hash, wrap);
|
159
|
}
|
160
|
wrap.add(ref, detail);
|
161
|
}
|
162
|
|
163
|
public Set<ReferenceCandidate> getCandidates(Reference exemplar) {
|
164
|
String hash = refHash(exemplar);
|
165
|
ReferenceMapping.ReferenceWrapper wrap = abbrevMapping.get(hash);
|
166
|
if (wrap == null){
|
167
|
return new HashSet<>();
|
168
|
}else{
|
169
|
return wrap.getCandidates();
|
170
|
}
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
public String toString(){
|
175
|
return "ReferenceMapping";
|
176
|
}
|
177
|
}
|
178
|
|
179
|
private ReferenceMapping refMapping = new ReferenceMapping();
|
180
|
|
181
|
private void loadReferenceMap(BerlinModelImportState state){
|
182
|
List<Reference> list = getReferenceService().list(null, null, null, null, null);
|
183
|
for (Reference ref : list){
|
184
|
refMapping.addCandidate(ref, null);
|
185
|
}
|
186
|
|
187
|
// try {
|
188
|
//
|
189
|
// String query = "SELECT * FROM Reference ";
|
190
|
//
|
191
|
// ResultSet rs = state.getConfig().getDestination().executeQuery(query);
|
192
|
// while (rs.next()){
|
193
|
// String title = rs.getString("title");
|
194
|
// String abbrevTitle = rs.getString("abbrevTitle");
|
195
|
// int id = rs.getInt("id");
|
196
|
// UUID uuid = UUID.fromString(rs.getString("uuid"));
|
197
|
// String titleCache = rs.getString("titleCache");
|
198
|
// String abbrevTitleCache = rs.getString("abbrevTitleCache");
|
199
|
// String typeStr = rs.getString("refType");
|
200
|
// ReferenceType type = ReferenceType.valueOf(typeStr);
|
201
|
//
|
202
|
// ReferenceMapping.ReferenceWrapper wrapping = refMapping.new ReferenceWrapper(title, id, uuid, titleCache, type) ;
|
203
|
// refMapping.titleMapping.put(title, wrapping);
|
204
|
// wrapping = refMapping.new ReferenceWrapper(abbrevTitle, id, uuid, abbrevTitleCache, type) ;
|
205
|
//
|
206
|
// }
|
207
|
// } catch (SQLException e) {
|
208
|
// e.printStackTrace();
|
209
|
// }
|
210
|
}
|
211
|
|
212
|
private void unloadReferenceMap(){
|
213
|
refMapping.unload();
|
214
|
refMapping = null;
|
215
|
}
|
216
|
|
217
|
|
218
|
@Override
|
219
|
protected void doInvoke(BerlinModelImportState state) {
|
220
|
loadReferenceMap(state);
|
221
|
|
222
|
//update rank labels if necessary
|
223
|
String strAbbrev = state.getConfig().getInfrGenericRankAbbrev();
|
224
|
Rank rank = Rank.INFRAGENERICTAXON();
|
225
|
testRankAbbrev(strAbbrev, rank);
|
226
|
|
227
|
strAbbrev = state.getConfig().getInfrSpecificRankAbbrev();
|
228
|
rank = Rank.INFRASPECIFICTAXON();
|
229
|
testRankAbbrev(strAbbrev, rank);
|
230
|
|
231
|
super.doInvoke(state);
|
232
|
unloadReferenceMap();
|
233
|
printMatchResults();
|
234
|
}
|
235
|
|
236
|
private void testRankAbbrev(String strAbbrev, Rank rank) {
|
237
|
if (strAbbrev != null){
|
238
|
Representation rep = rank.getRepresentation(Language.ENGLISH());
|
239
|
rep.setAbbreviatedLabel(strAbbrev);
|
240
|
getTermService().saveOrUpdate(rank);
|
241
|
}
|
242
|
}
|
243
|
|
244
|
@Override
|
245
|
public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
246
|
String dbAttrName;
|
247
|
String cdmAttrName;
|
248
|
boolean success = true ;
|
249
|
BerlinModelImportConfigurator config = state.getConfig();
|
250
|
Set<TaxonName> namesToSave = new HashSet<>();
|
251
|
@SuppressWarnings("unchecked")
|
252
|
Map<String, Team> teamMap = partitioner.getObjectMap(BerlinModelAuthorTeamImport.NAMESPACE);
|
253
|
//to dedup preliminary refDetail references
|
254
|
state.getDeduplicationHelper().restartSession(this, null);
|
255
|
|
256
|
|
257
|
ResultSet rs = partitioner.getResultSet();
|
258
|
|
259
|
try {
|
260
|
int i = 0;
|
261
|
//for each reference
|
262
|
while (rs.next()){
|
263
|
|
264
|
if ((i++ % modCount) == 0 && i != 1 ){ logger.info("Names handled: " + (i-1));}
|
265
|
|
266
|
//create TaxonName element
|
267
|
int nameId = rs.getInt("nameId");
|
268
|
Integer authorFk = nullSafeInt(rs, "AuthorTeamFk");
|
269
|
Integer exAuthorFk = nullSafeInt(rs, "ExAuthorTeamFk");
|
270
|
Integer basAuthorFk = nullSafeInt(rs, "BasAuthorTeamFk");
|
271
|
Integer exBasAuthorFk = nullSafeInt(rs, "ExBasAuthorTeamFk");
|
272
|
String strCultivarGroupName = rs.getString("CultivarGroupName");
|
273
|
String strCultivarName = rs.getString("CultivarName");
|
274
|
String nameCache = rs.getString("NameCache");
|
275
|
String fullNameCache = rs.getString("FullNameCache");
|
276
|
String uuid = null;
|
277
|
if (resultSetHasColumn(rs,"UUID")){
|
278
|
uuid = rs.getString("UUID");
|
279
|
}
|
280
|
|
281
|
try {
|
282
|
|
283
|
//define rank
|
284
|
boolean useUnknownRank = true;
|
285
|
Rank rank = BerlinModelTransformer.rankId2Rank(rs, useUnknownRank, config.isSwitchSpeciesGroup());
|
286
|
|
287
|
boolean allowInfraSpecTaxonRank = state.getConfig().isAllowInfraSpecTaxonRank() ;
|
288
|
if (rank == null || rank.equals(Rank.UNKNOWN_RANK()) || (rank.equals(Rank.INFRASPECIFICTAXON()) && ! allowInfraSpecTaxonRank)){
|
289
|
rank = handleProlesAndRaceSublusus(state, rs, rank);
|
290
|
}
|
291
|
|
292
|
if (rank.getId() == 0){
|
293
|
getTermService().save(rank);
|
294
|
logger.warn("Rank did not yet exist: " + rank.getTitleCache());
|
295
|
}
|
296
|
|
297
|
//create TaxonName
|
298
|
TaxonName taxonName;
|
299
|
if (config.getNomenclaturalCode() != null){
|
300
|
taxonName = config.getNomenclaturalCode().getNewTaxonNameInstance(rank);
|
301
|
//check cultivar
|
302
|
if (taxonName.isBotanical()){
|
303
|
if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
|
304
|
taxonName = TaxonNameFactory.NewCultivarInstance(rank);
|
305
|
}
|
306
|
}
|
307
|
}else{
|
308
|
taxonName = TaxonNameFactory.NewNonViralInstance(rank);
|
309
|
}
|
310
|
if (uuid != null){
|
311
|
taxonName.setUuid(UUID.fromString(uuid));
|
312
|
}
|
313
|
|
314
|
if (rank == null){
|
315
|
//TODO rank should never be null or a more sophisticated algorithm has to be implemented for genus/supraGenericName
|
316
|
logger.warn("Rank is null. Genus epithet was imported. May be wrong");
|
317
|
success = false;
|
318
|
}
|
319
|
|
320
|
//epithets
|
321
|
if (rank.isSupraGeneric()){
|
322
|
dbAttrName = "supraGenericName";
|
323
|
}else{
|
324
|
dbAttrName = "genus";
|
325
|
}
|
326
|
cdmAttrName = "genusOrUninomial";
|
327
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
328
|
|
329
|
dbAttrName = "genusSubdivisionEpi";
|
330
|
cdmAttrName = "infraGenericEpithet";
|
331
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
332
|
|
333
|
dbAttrName = "speciesEpi";
|
334
|
cdmAttrName = "specificEpithet";
|
335
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
336
|
|
337
|
|
338
|
dbAttrName = "infraSpeciesEpi";
|
339
|
cdmAttrName = "infraSpecificEpithet";
|
340
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
341
|
|
342
|
dbAttrName = "unnamedNamePhrase";
|
343
|
cdmAttrName = "appendedPhrase";
|
344
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
345
|
|
346
|
//Details
|
347
|
dbAttrName = "details";
|
348
|
cdmAttrName = "nomenclaturalMicroReference";
|
349
|
success &= ImportHelper.addStringValue(rs, taxonName, dbAttrName, cdmAttrName, BLANK_TO_NULL);
|
350
|
|
351
|
//authorTeams
|
352
|
if (teamMap != null ){
|
353
|
taxonName.setCombinationAuthorship(getAuthorTeam(teamMap, authorFk, nameId, config));
|
354
|
taxonName.setExCombinationAuthorship(getAuthorTeam(teamMap, exAuthorFk, nameId, config));
|
355
|
taxonName.setBasionymAuthorship(getAuthorTeam(teamMap, basAuthorFk, nameId, config));
|
356
|
taxonName.setExBasionymAuthorship(getAuthorTeam(teamMap, exBasAuthorFk, nameId, config));
|
357
|
}else{
|
358
|
logger.warn("TeamMap is null");
|
359
|
success = false;
|
360
|
}
|
361
|
|
362
|
//nomRef
|
363
|
success &= makeNomenclaturalReference(state, taxonName, nameId, rs, partitioner);
|
364
|
|
365
|
//Source_Acc
|
366
|
boolean colExists = true;
|
367
|
try {
|
368
|
colExists = state.getConfig().getSource().checkColumnExists("Name", "Source_Acc");
|
369
|
} catch (DatabaseTypeNotSupportedException e) {
|
370
|
logger.debug("Source does not support 'checkColumnExists'");
|
371
|
}
|
372
|
if (colExists){
|
373
|
String sourceAcc = rs.getString("Source_Acc");
|
374
|
if (isNotBlank(sourceAcc)){
|
375
|
ExtensionType sourceAccExtensionType = getExtensionType(state, BerlinModelTransformer.SOURCE_ACC_UUID, "Source_Acc","Source_Acc","Source_Acc");
|
376
|
Extension.NewInstance(taxonName, sourceAcc, sourceAccExtensionType);
|
377
|
}
|
378
|
}
|
379
|
|
380
|
//created, notes
|
381
|
boolean excludeUpdated = true;
|
382
|
boolean excludeNotes = true;
|
383
|
success &= doIdCreatedUpdatedNotes(state, taxonName, rs, nameId, NAMESPACE, excludeUpdated, excludeNotes);
|
384
|
handleNameNotes(state, taxonName, rs, nameId);
|
385
|
|
386
|
//detail notes
|
387
|
String detailNotes = rs.getString("detailNotes");
|
388
|
if (isNotBlank(detailNotes)){
|
389
|
Annotation detailNoteAnnotation = Annotation.NewDefaultLanguageInstance("RefDetail: " + detailNotes);
|
390
|
taxonName.addAnnotation(detailNoteAnnotation);
|
391
|
}
|
392
|
|
393
|
//zoologicalName
|
394
|
if (taxonName.isZoological()){
|
395
|
IZoologicalName zooName = taxonName;
|
396
|
makeZoologialName(rs, zooName, nameId);
|
397
|
}
|
398
|
//botanicalName
|
399
|
else if (taxonName.isBotanical()){
|
400
|
IBotanicalName botName = taxonName;
|
401
|
success &= makeBotanicalNamePart(rs, botName) ;
|
402
|
|
403
|
}
|
404
|
|
405
|
// dbAttrName = "preliminaryFlag";
|
406
|
Boolean preliminaryFlag = rs.getBoolean("PreliminaryFlag");
|
407
|
Boolean hybridFormulaFlag = rs.getBoolean("HybridFormulaFlag"); //hybrid flag does not lead to cache update in Berlin Model
|
408
|
if (preliminaryFlag == true || hybridFormulaFlag == true){
|
409
|
//Computes all caches and sets
|
410
|
taxonName.setTitleCache(fullNameCache, true);
|
411
|
taxonName.setFullTitleCache(taxonName.getFullTitleCache(), true);
|
412
|
taxonName.setNameCache(nameCache, true);
|
413
|
taxonName.setAuthorshipCache(taxonName.getAuthorshipCache(), true);
|
414
|
}
|
415
|
namesToSave.add(taxonName);
|
416
|
|
417
|
}
|
418
|
catch (UnknownCdmTypeException e) {
|
419
|
logger.warn("Name with id " + nameId + " has unknown rankId " + " and could not be saved.");
|
420
|
success = false;
|
421
|
}
|
422
|
|
423
|
} //while rs.hasNext()
|
424
|
} catch (SQLException e) {
|
425
|
logger.error("SQLException:" + e);
|
426
|
return false;
|
427
|
}
|
428
|
|
429
|
|
430
|
// logger.info( i + " names handled");
|
431
|
getNameService().save(namesToSave);
|
432
|
// printMatchResults();
|
433
|
return success;
|
434
|
}
|
435
|
|
436
|
|
437
|
/**
|
438
|
*
|
439
|
*/
|
440
|
private void printMatchResults() {
|
441
|
for (MatchType type : MatchType.values()){
|
442
|
List<String> list = matchResults.get(type);
|
443
|
list = list == null? new ArrayList<>(): list;
|
444
|
Collections.sort(list);
|
445
|
System.out.println("\n" + type.toString() + " " + list.size());
|
446
|
System.out.println("=============================");
|
447
|
for (String result : list){
|
448
|
System.out.println(result);
|
449
|
}
|
450
|
}
|
451
|
|
452
|
}
|
453
|
|
454
|
|
455
|
/**
|
456
|
* @param state
|
457
|
* @param taxonName
|
458
|
* @param rs
|
459
|
* @param nameId
|
460
|
* @throws SQLException
|
461
|
*/
|
462
|
private void handleNameNotes(BerlinModelImportState state, TaxonName taxonName, ResultSet rs, int nameId) throws SQLException {
|
463
|
String notesOrig = rs.getString("notes");
|
464
|
String notes = filterNotes(notesOrig, nameId);
|
465
|
boolean isParentalSpecies = state.getConfig().isEuroMed() && isPostulatedParentalSpeciesNote(notes);
|
466
|
if (isNotBlank(notes) && taxonName != null && !isParentalSpecies ){
|
467
|
String notesString = String.valueOf(notes);
|
468
|
if (notesString.length() > 65530 ){
|
469
|
notesString = notesString.substring(0, 65530) + "...";
|
470
|
logger.warn("Notes string is longer than 65530 and was truncated: " + taxonName);
|
471
|
}
|
472
|
Annotation notesAnnotation = Annotation.NewInstance(notesString, Language.DEFAULT());
|
473
|
//notesAnnotation.setAnnotationType(AnnotationType.EDITORIAL());
|
474
|
//notes.setCommentator(bmiConfig.getCommentator());
|
475
|
taxonName.addAnnotation(notesAnnotation);
|
476
|
}
|
477
|
|
478
|
}
|
479
|
|
480
|
private static final String MCL = "MCL\\s?[0-9]{1,3}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,4}(\\-[0-9]{1,3})?)?)?)?";
|
481
|
/**
|
482
|
* @param notes
|
483
|
*/
|
484
|
protected static String filterNotes(String notes, int nameId) {
|
485
|
String result;
|
486
|
if (isBlank(notes)){
|
487
|
result = null;
|
488
|
}else if (notes.matches("Acc:.*")){
|
489
|
if (notes.matches("Acc: .*\\$$") || (notes.matches("Acc: .*"+MCL))){
|
490
|
result = null;
|
491
|
}else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
|
492
|
notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
|
493
|
result = notes;
|
494
|
}else if (notes.matches("Acc: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
|
495
|
notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
|
496
|
result = notes;
|
497
|
}else{
|
498
|
logger.warn("Name id: " + nameId + ". Namenote: " + notes);
|
499
|
result = notes;
|
500
|
}
|
501
|
}else if (notes.matches("Syn:.*")){
|
502
|
if (notes.matches("Syn: .*\\$$") || (notes.matches("Syn: .*"+MCL))){
|
503
|
result = null;
|
504
|
}else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\{.*\\}")){
|
505
|
notes = notes.substring(notes.indexOf("{")+1, notes.length()-1);
|
506
|
result = notes;
|
507
|
}else if (notes.matches("Syn: .*(\\$|"+MCL+")\\s*\\[.*\\]")){
|
508
|
notes = notes.substring(notes.indexOf("[")+1, notes.length()-1);
|
509
|
result = notes;
|
510
|
}else{
|
511
|
logger.warn("Name id: " + nameId + ". Namenote: " + notes);
|
512
|
result = notes;
|
513
|
}
|
514
|
}else{
|
515
|
result = notes;
|
516
|
}
|
517
|
return result;
|
518
|
}
|
519
|
|
520
|
|
521
|
/**
|
522
|
* @param nameNotes
|
523
|
* @return
|
524
|
*/
|
525
|
protected static boolean isPostulatedParentalSpeciesNote(String nameNotes) {
|
526
|
if (nameNotes == null){
|
527
|
return false;
|
528
|
}else{
|
529
|
return nameNotes.matches(".*<>.*");
|
530
|
}
|
531
|
}
|
532
|
|
533
|
|
534
|
private Rank handleProlesAndRaceSublusus(BerlinModelImportState state, ResultSet rs, Rank rank) throws SQLException {
|
535
|
Rank result;
|
536
|
String rankAbbrev = rs.getString("RankAbbrev");
|
537
|
// String rankStr = rs.getString("Rank");
|
538
|
if (CdmUtils.nullSafeEqual(rankAbbrev, "prol.") ){
|
539
|
result = Rank.PROLES();
|
540
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "race")){
|
541
|
result = Rank.RACE();
|
542
|
}else if(CdmUtils.nullSafeEqual(rankAbbrev, "sublusus")){
|
543
|
result = Rank.SUBLUSUS();
|
544
|
}else{
|
545
|
result = rank;
|
546
|
logger.warn("Unhandled rank: " + rankAbbrev);
|
547
|
}
|
548
|
return result;
|
549
|
}
|
550
|
|
551
|
@Override
|
552
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
553
|
|
554
|
String nameSpace;
|
555
|
Set<String> idSet;
|
556
|
|
557
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
558
|
|
559
|
try{
|
560
|
Set<String> teamIdSet = new HashSet<>();
|
561
|
Set<String> referenceIdSet = new HashSet<>();
|
562
|
Set<String> refDetailIdSet = new HashSet<>();
|
563
|
List<Integer> prelimRefDetailCandidateIdSet = new ArrayList<>();
|
564
|
while (rs.next()){
|
565
|
handleForeignKey(rs, teamIdSet, "AuthorTeamFk");
|
566
|
handleForeignKey(rs, teamIdSet, "ExAuthorTeamFk");
|
567
|
handleForeignKey(rs, teamIdSet, "BasAuthorTeamFk");
|
568
|
handleForeignKey(rs, teamIdSet, "ExBasAuthorTeamFk");
|
569
|
handleForeignKey(rs, referenceIdSet, "nomRefFk");
|
570
|
handleForeignKey(rs, refDetailIdSet, "nomRefDetailFk");
|
571
|
prelimRefDetailCandidateIdSet.addAll(getPreliminaryIdCandidates(state, rs));
|
572
|
}
|
573
|
|
574
|
//team map
|
575
|
nameSpace = BerlinModelAuthorTeamImport.NAMESPACE;
|
576
|
idSet = teamIdSet;
|
577
|
@SuppressWarnings("rawtypes")
|
578
|
Map<String, TeamOrPersonBase> teamMap = getCommonService().getSourcedObjectsByIdInSourceC(TeamOrPersonBase.class, idSet, nameSpace);
|
579
|
result.put(nameSpace, teamMap);
|
580
|
|
581
|
//reference map
|
582
|
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
|
583
|
idSet = referenceIdSet;
|
584
|
Map<String, Reference> referenceMap = getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
|
585
|
result.put(nameSpace, referenceMap);
|
586
|
|
587
|
//refDetail map
|
588
|
nameSpace = BerlinModelRefDetailImport.REFDETAIL_NAMESPACE;
|
589
|
idSet = refDetailIdSet;
|
590
|
Map<String, Reference> refDetailMap= getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
|
591
|
result.put(nameSpace, refDetailMap);
|
592
|
|
593
|
//prelim map
|
594
|
nameSpace = NAMESPACE_PRELIM;
|
595
|
List<Reference> list = getReferenceService().loadByIds(prelimRefDetailCandidateIdSet, null);
|
596
|
Map<String, Reference> prelimMap = new HashMap<>();
|
597
|
for (Reference ref : list){
|
598
|
prelimMap.put(String.valueOf(ref.getId()), ref);
|
599
|
}
|
600
|
result.put(nameSpace, prelimMap);
|
601
|
|
602
|
} catch (SQLException e) {
|
603
|
throw new RuntimeException(e);
|
604
|
}
|
605
|
return result;
|
606
|
}
|
607
|
|
608
|
private boolean makeZoologialName(ResultSet rs, IZoologicalName zooName, int nameId)
|
609
|
throws SQLException{
|
610
|
boolean success = true;
|
611
|
//publicationYear
|
612
|
String authorTeamYear = rs.getString("authorTeamYear");
|
613
|
try {
|
614
|
if (! "".equals(CdmUtils.Nz(authorTeamYear).trim())){
|
615
|
Integer publicationYear = Integer.valueOf(authorTeamYear.trim());
|
616
|
zooName.setPublicationYear(publicationYear);
|
617
|
}
|
618
|
} catch (NumberFormatException e) {
|
619
|
logger.warn("authorTeamYear could not be parsed for taxonName: "+ nameId);
|
620
|
}
|
621
|
//original publication year
|
622
|
String basAuthorTeamYear = rs.getString("basAuthorTeamYear");
|
623
|
try {
|
624
|
if (! "".equals(CdmUtils.Nz(basAuthorTeamYear).trim())){
|
625
|
Integer OriginalPublicationYear = Integer.valueOf(basAuthorTeamYear.trim());
|
626
|
zooName.setOriginalPublicationYear(OriginalPublicationYear);
|
627
|
}
|
628
|
} catch (NumberFormatException e) {
|
629
|
logger.warn("basAuthorTeamYear could not be parsed for taxonName: "+ nameId);
|
630
|
}
|
631
|
return success;
|
632
|
}
|
633
|
|
634
|
private boolean makeBotanicalNamePart(ResultSet rs, IBotanicalName botanicalName)throws SQLException{
|
635
|
boolean success = true;
|
636
|
String dbAttrName;
|
637
|
String cdmAttrName;
|
638
|
|
639
|
dbAttrName = "HybridFormulaFlag";
|
640
|
cdmAttrName = "isHybridFormula";
|
641
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
642
|
|
643
|
dbAttrName = "MonomHybFlag";
|
644
|
cdmAttrName = "isMonomHybrid";
|
645
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
646
|
|
647
|
dbAttrName = "BinomHybFlag";
|
648
|
cdmAttrName = "isBinomHybrid";
|
649
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
650
|
|
651
|
dbAttrName = "TrinomHybFlag";
|
652
|
cdmAttrName = "isTrinomHybrid";
|
653
|
success &= ImportHelper.addBooleanValue(rs, botanicalName, dbAttrName, cdmAttrName);
|
654
|
|
655
|
try {
|
656
|
String strCultivarGroupName = rs.getString("CultivarGroupName");
|
657
|
String strCultivarName = rs.getString("CultivarName");
|
658
|
if (botanicalName.isCultivar()){
|
659
|
ICultivarPlantName cultivarName = (ICultivarPlantName)botanicalName;
|
660
|
String concatCultivarName = CdmUtils.concat("-", strCultivarName, strCultivarGroupName);
|
661
|
if (isNotBlank(strCultivarGroupName) && isNotBlank(strCultivarName)){
|
662
|
logger.warn("CDM does not support cultivarGroupName and CultivarName together: " + concatCultivarName);
|
663
|
}
|
664
|
cultivarName.setCultivarEpithet(strCultivarGroupName);
|
665
|
}
|
666
|
} catch (SQLException e) {
|
667
|
throw e;
|
668
|
}
|
669
|
return success;
|
670
|
}
|
671
|
|
672
|
|
673
|
private boolean makeNomenclaturalReference(BerlinModelImportState state, TaxonName taxonName,
|
674
|
int nameId, ResultSet rs, @SuppressWarnings("rawtypes") ResultSetPartitioner partitioner) throws SQLException{
|
675
|
BerlinModelImportConfigurator config = state.getConfig();
|
676
|
|
677
|
@SuppressWarnings("unchecked")
|
678
|
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
|
679
|
@SuppressWarnings("unchecked")
|
680
|
Map<String, Reference> refDetailMap = partitioner.getObjectMap(BerlinModelRefDetailImport.REFDETAIL_NAMESPACE);
|
681
|
|
682
|
Integer nomRefFkInt = nullSafeInt(rs, "NomRefFk");
|
683
|
Integer nomRefDetailFkInt = nullSafeInt(rs, "NomRefDetailFk");
|
684
|
boolean refDetailPrelim = rs.getBoolean("RefDetailPrelim");
|
685
|
|
686
|
boolean success = true;
|
687
|
//nomenclatural Reference
|
688
|
if (refMap != null){
|
689
|
if (nomRefFkInt != null){
|
690
|
String nomRefFk = String.valueOf(nomRefFkInt);
|
691
|
String nomRefDetailFk = String.valueOf(nomRefDetailFkInt);
|
692
|
//get nomRef
|
693
|
Reference nomReference =
|
694
|
getReferenceFromMaps(refDetailMap, refMap, nomRefDetailFk, nomRefFk);
|
695
|
|
696
|
if(config.isDoPreliminaryRefDetailsWithNames() && refDetailPrelim){
|
697
|
makePrelimRefDetailRef(state, rs, partitioner, taxonName, nameId);
|
698
|
}else{
|
699
|
|
700
|
//setNomRef
|
701
|
if (nomReference == null ){
|
702
|
//TODO
|
703
|
if (! config.isIgnoreNull()){
|
704
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
705
|
" was not found in reference store. Nomenclatural reference not set!!");
|
706
|
}
|
707
|
}else{
|
708
|
if (! INomenclaturalReference.class.isAssignableFrom(nomReference.getClass())){
|
709
|
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFk + ") for TaxonName (nameId = " + nameId + ")"+
|
710
|
" is not assignable from INomenclaturalReference. (Class = " + nomReference.getClass()+ ")");
|
711
|
}
|
712
|
nomReference.setNomenclaturallyRelevant(true);
|
713
|
taxonName.setNomenclaturalReference(nomReference);
|
714
|
}
|
715
|
}
|
716
|
}
|
717
|
}
|
718
|
return success;
|
719
|
}
|
720
|
|
721
|
|
722
|
private INonViralNameParser<?> parser = NonViralNameParserImpl.NewInstance();
|
723
|
|
724
|
|
725
|
private class ReferenceCandidate{
|
726
|
Reference ref;
|
727
|
String detail;
|
728
|
private ReferenceCandidate(Reference ref, String detail) {
|
729
|
this.ref = ref;
|
730
|
this.detail = detail;
|
731
|
}
|
732
|
public Integer getId() {
|
733
|
return ref.getId();
|
734
|
}
|
735
|
@Override
|
736
|
public String toString(){
|
737
|
return ref.toString() + ": " + detail;
|
738
|
}
|
739
|
}
|
740
|
|
741
|
private class FinalCandidate{
|
742
|
private FinalCandidate(ReferenceCandidate candidate, ReferenceCandidate exemplar, MatchResult matchResult) {
|
743
|
this.candidate = candidate;
|
744
|
this.exemplar = exemplar;
|
745
|
this.matchResult = matchResult;
|
746
|
}
|
747
|
ReferenceCandidate candidate;
|
748
|
ReferenceCandidate exemplar;
|
749
|
MatchResult matchResult;
|
750
|
|
751
|
@Override
|
752
|
public String toString(){
|
753
|
return candidate.toString() + " <-> " + exemplar.toString() + "\n " + matchResult.toString()+"\n";
|
754
|
}
|
755
|
}
|
756
|
|
757
|
/**
|
758
|
* @param config
|
759
|
* @param rs
|
760
|
* @param partitioner
|
761
|
* @param taxonName
|
762
|
* @param nameId
|
763
|
* @throws SQLException
|
764
|
*/
|
765
|
private void makePrelimRefDetailRef(BerlinModelImportState state, ResultSet rs, @SuppressWarnings("rawtypes") ResultSetPartitioner partitioner,
|
766
|
TaxonName taxonName, int nameId) throws SQLException {
|
767
|
|
768
|
int refDetailId = rs.getInt("RefDetailId");
|
769
|
@SuppressWarnings("unchecked")
|
770
|
Map<String, Reference> refMap = partitioner.getObjectMap(NAMESPACE_PRELIM);
|
771
|
|
772
|
String nameTitleCache = taxonName.getTitleCache();
|
773
|
|
774
|
String fullNomRefCache = rs.getString("FullNomRefCache");
|
775
|
String detail = rs.getString("Details");
|
776
|
|
777
|
if (fullNomRefCache == null){
|
778
|
logger.warn("fullNomRefCache is null for preliminary refDetail. NameId: " + nameId);
|
779
|
return;
|
780
|
}
|
781
|
|
782
|
fullNomRefCache = fullNomRefCache.trim();
|
783
|
if (fullNomRefCache.startsWith(": ")){
|
784
|
logger.warn("fullNomRefCache starts with ':' for preliminary refDetail. NameId: " + nameId);
|
785
|
return;
|
786
|
}else if (fullNomRefCache.matches("[12][7890][0-9][0-9](-(1774|1832))?") && isBlank(detail)){
|
787
|
handlePrelimYearOnly(state, rs, taxonName, nameId, refMap, fullNomRefCache, detail, refDetailId);
|
788
|
}else{
|
789
|
Reference genericCandidate = ReferenceFactory.newGeneric();
|
790
|
genericCandidate.setAbbrevTitleCache(fullNomRefCache, true);
|
791
|
Set<FinalCandidate> finalCandidates = new HashSet<>();
|
792
|
Set<FinalCandidate> finalInRefCandidates = new HashSet<>();
|
793
|
Set<Reference> parsedReferences = new HashSet<>();
|
794
|
|
795
|
makeFinalCandidates(state, rs, taxonName, refMap,
|
796
|
nameTitleCache, finalCandidates,
|
797
|
finalInRefCandidates, parsedReferences);
|
798
|
|
799
|
evaluateFinalCandidates(state, rs, taxonName, detail, genericCandidate, parsedReferences,
|
800
|
finalCandidates, fullNomRefCache);
|
801
|
}
|
802
|
}
|
803
|
|
804
|
|
805
|
/**
|
806
|
* @param state
|
807
|
* @param rs
|
808
|
* @param taxonName
|
809
|
* @param nameId
|
810
|
* @param refMap
|
811
|
* @param fullNomRefCache
|
812
|
* @param detail
|
813
|
* @throws SQLException
|
814
|
*/
|
815
|
private void handlePrelimYearOnly(BerlinModelImportState state, ResultSet rs, TaxonName taxonName, int nameId,
|
816
|
Map<String, Reference> refMap, String fullNomRefCache, String detail, int refDetailId) throws SQLException {
|
817
|
TeamOrPersonBase<?> combAuthor = taxonName.getCombinationAuthorship();
|
818
|
Set<Integer> candidateIds = getPreliminaryIdCandidates(state, rs);
|
819
|
|
820
|
boolean candidateMatches = false;
|
821
|
for (Integer candidateId : candidateIds){
|
822
|
Reference dedupCandidate = CdmBase.deproxy(refMap.get(String.valueOf(candidateId)));
|
823
|
System.out.println("dedupCandidate: " + dedupCandidate.getAbbrevTitleCache());
|
824
|
TeamOrPersonBase<?> dedupAuthor = dedupCandidate.getAuthorship();
|
825
|
if (dedupAuthor != null && combAuthor != null){
|
826
|
if (Objects.equals(dedupAuthor, combAuthor)){
|
827
|
taxonName.setNomenclaturalReference(dedupCandidate);
|
828
|
candidateMatches = true;
|
829
|
}else if (Objects.equals(dedupAuthor.getNomenclaturalTitleCache(), combAuthor.getNomenclaturalTitleCache())){
|
830
|
logger.warn("Year nomAuthor equal in nomTitle but not same: " + dedupAuthor.getNomenclaturalTitleCache() + "; " + fullNomRefCache + "; nameId " + nameId);
|
831
|
taxonName.setNomenclaturalReference(dedupCandidate);
|
832
|
candidateMatches = true;
|
833
|
}
|
834
|
}else if (dedupCandidate.getAuthorship() == null && combAuthor != null){
|
835
|
logger.warn("Year dedupCand and name have no author: " + fullNomRefCache + "; nameId " + nameId);
|
836
|
taxonName.setNomenclaturalReference(dedupCandidate);
|
837
|
candidateMatches = true;
|
838
|
}
|
839
|
}
|
840
|
if (!candidateMatches){
|
841
|
Reference yearRef = ReferenceFactory.newGeneric();
|
842
|
VerbatimTimePeriod timePeriod = TimePeriodParser.parseStringVerbatim(fullNomRefCache);
|
843
|
yearRef.setDatePublished(timePeriod);
|
844
|
yearRef.setAuthorship(combAuthor);
|
845
|
taxonName.setNomenclaturalReference(yearRef);
|
846
|
yearRef.addImportSource(String.valueOf(refDetailId), NAMESPACE_PRELIM, state.getTransactionalSourceReference(), null);
|
847
|
refMapping.addCandidate(yearRef, detail);
|
848
|
//TODO
|
849
|
// refMap.put(key, yearRef);
|
850
|
}
|
851
|
}
|
852
|
|
853
|
|
854
|
private enum MatchType{
|
855
|
UNPARSED,
|
856
|
NO_MATCH_SINGLE_PARSE_ARTICLE_WITH_COMMA,
|
857
|
NO_MATCH_SINGLE_PARSE_ARTICLE_NO_COMMA,
|
858
|
NO_MATCH_SINGLE_PARSE_BOOKSECTION,
|
859
|
NO_MATCH_SINGLE_PARSE_BOOK,
|
860
|
NO_MATCH_SINGLE_PARSE_GENERIC,
|
861
|
NO_MATCH_SINGLE_PARSE_OTHER,
|
862
|
NO_MATCH_MULTI_PARSE,
|
863
|
NO_MATCH_WITH_CANDIDATE,
|
864
|
SINGLE_FULL_MATCH,
|
865
|
SINGLE_INREF_MATCH,
|
866
|
MULTI_SINGLE_PERSISTENT,
|
867
|
MULTI_MULTI_PERSISTENT_NO_EXACT,
|
868
|
MULTI_MULTI_PERSISTENT_MULTI_EXACT,
|
869
|
MULTI_MULTI_PERSISTENT_SINGLE_EXACT,
|
870
|
MULTI_NO_PERSISTENT_MULTI_EXACT,
|
871
|
MULTI_NO_PERSISTENT_SINGLE_EXACT,
|
872
|
MULTI_NO_PERSISTENT_NO_EXACT,
|
873
|
}
|
874
|
|
875
|
private Map<MatchType, List<String>> matchResults = new HashMap<>();
|
876
|
|
877
|
/**
|
878
|
* @param taxonName
|
879
|
* @param detail
|
880
|
* @param genericCandidate
|
881
|
* @param finalCandidates
|
882
|
* @param fullNomRefCache
|
883
|
* @param exemplars
|
884
|
* @throws SQLException
|
885
|
*/
|
886
|
private void evaluateFinalCandidates(BerlinModelImportState state, ResultSet rs,
|
887
|
TaxonName taxonName, String detail, Reference genericCandidate, Set<Reference> parsedCandidates,
|
888
|
Set<FinalCandidate> finalCandidates, String fullNomRefCache) throws SQLException {
|
889
|
|
890
|
int refDetailId = rs.getInt("RefDetailId");
|
891
|
Set<FinalCandidate> matchingCandidates = getSuccess(finalCandidates);
|
892
|
if (matchingCandidates.isEmpty()){
|
893
|
taxonName.setNomenclaturalReference(genericCandidate);
|
894
|
genericCandidate.addImportSource(String.valueOf(refDetailId), BerlinModelRefDetailImport.REFDETAIL_NAMESPACE,
|
895
|
state.getTransactionalSourceReference(), null);
|
896
|
//TODO should we set this?
|
897
|
taxonName.setNomenclaturalMicroReference(detail);
|
898
|
if (finalCandidates.isEmpty()){
|
899
|
if (taxonName.getCombinationAuthorship()==null){
|
900
|
System.out.println("nom. ref. not parsed because author is null: " + taxonName.getTitleCache());
|
901
|
}else{
|
902
|
System.out.println("Final Candidates empty but author exists - should not happen: " + taxonName.getTitleCache());
|
903
|
}
|
904
|
handleNoMatch(state, refDetailId, taxonName, detail, genericCandidate, finalCandidates, fullNomRefCache, parsedCandidates);
|
905
|
// printResult(MatchType.NO_MATCH, unparsedAndName(fullNomRefCache, taxonName));
|
906
|
}else if (hasOnlyUnparsedExemplars(finalCandidates)){
|
907
|
printResult(MatchType.UNPARSED, unparsedAndName(fullNomRefCache, taxonName));
|
908
|
}else if (hasNoCandidateExemplars(finalCandidates)){
|
909
|
//but we can define the ref type here
|
910
|
handleNoMatch(state, refDetailId, taxonName, detail, genericCandidate, finalCandidates, fullNomRefCache, parsedCandidates);
|
911
|
// printResult(MatchType.NO_MATCH, unparsedAndName(fullNomRefCache, taxonName));
|
912
|
}else{
|
913
|
String message = resultMessage(fullNomRefCache, finalCandidates, taxonName);
|
914
|
printResult(MatchType.NO_MATCH_WITH_CANDIDATE, message);
|
915
|
}
|
916
|
}else if (matchingCandidates.size() == 1){
|
917
|
ReferenceCandidate single = matchingCandidates.iterator().next().candidate;
|
918
|
addAuthorAndDetail(state, refDetailId, taxonName, single);
|
919
|
if (single.ref.isPersited()){
|
920
|
printResult(MatchType.SINGLE_FULL_MATCH, unparsedAndName(fullNomRefCache, taxonName));
|
921
|
}else{
|
922
|
// single.ref.addImportSource(String.valueOf(refDetailId), BerlinModelRefDetailImport.REFDETAIL_NAMESPACE,
|
923
|
// state.getTransactionalSourceReference(), null);
|
924
|
printResult(MatchType.SINGLE_INREF_MATCH, unparsedAndName(fullNomRefCache, taxonName));
|
925
|
}
|
926
|
}else{
|
927
|
FinalCandidate finCand = findBestMatchingFinalCandidate(state, refDetailId, taxonName, matchingCandidates, fullNomRefCache);
|
928
|
// addAuthorAndDetail(taxonName, finCand.candidate);
|
929
|
}
|
930
|
}
|
931
|
|
932
|
|
933
|
/**
|
934
|
* @param state
|
935
|
* @param taxonName
|
936
|
* @param detail
|
937
|
* @param genericCandidate
|
938
|
* @param finalCandidates
|
939
|
* @param fullNomRefCache
|
940
|
* @param parsedCandidates
|
941
|
*/
|
942
|
private void handleNoMatch(BerlinModelImportState state, int refDetailId, TaxonName taxonName, String detail,
|
943
|
Reference genericCandidate, Set<FinalCandidate> finalCandidates, String fullNomRefCache,
|
944
|
Set<Reference> parsedCandidatesAsRef) {
|
945
|
Set<FinalCandidate> parsedCandidates = getParsedExemplars(finalCandidates);
|
946
|
// parsedCandidatesAsRef = removeGenericFromParsedReferencesAsRef();
|
947
|
// if (parsedCandidates.size() != parsedCandidatesAsRef.size()){
|
948
|
// System.out.println("Parsed Candidates differ in size. Should not happen");
|
949
|
// }
|
950
|
if (parsedCandidates.isEmpty()){
|
951
|
System.out.println("Parsed Candidates empty. Should not happen");
|
952
|
}else if (parsedCandidates.size() == 1){
|
953
|
|
954
|
ReferenceCandidate refCand = parsedCandidates.iterator().next().exemplar;
|
955
|
addAuthorAndDetail(state, refDetailId, taxonName, refCand);
|
956
|
if (refCand.ref.getType() == ReferenceType.Article){
|
957
|
if(refCand.ref.getInReference().getAbbrevTitle().contains(",")){
|
958
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_ARTICLE_WITH_COMMA, unparsedAndName(fullNomRefCache, taxonName));
|
959
|
}else{
|
960
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_ARTICLE_NO_COMMA, unparsedAndName(fullNomRefCache, taxonName));
|
961
|
}
|
962
|
}else if (refCand.ref.getType() == ReferenceType.BookSection){
|
963
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_BOOKSECTION, unparsedAndName(fullNomRefCache, taxonName));
|
964
|
}else if (refCand.ref.getType() == ReferenceType.Book){
|
965
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_BOOK, unparsedAndName(fullNomRefCache, taxonName));
|
966
|
}else {
|
967
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_OTHER, unparsedAndName(fullNomRefCache, taxonName));
|
968
|
}
|
969
|
}else{
|
970
|
ReferenceCandidate generCandidate = createGenericReference(parsedCandidates, detail);
|
971
|
addAuthorAndDetail(state, refDetailId, taxonName, generCandidate);
|
972
|
if (generCandidate.ref.getType() == ReferenceType.Article){
|
973
|
if(generCandidate.ref.getInReference().getAbbrevTitle().contains(",")){
|
974
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_ARTICLE_WITH_COMMA, unparsedAndName(fullNomRefCache, taxonName));
|
975
|
}else{
|
976
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_ARTICLE_NO_COMMA, unparsedAndName(fullNomRefCache, taxonName));
|
977
|
}
|
978
|
}else if (generCandidate.ref.getType() == ReferenceType.BookSection){
|
979
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_BOOKSECTION, unparsedAndName(fullNomRefCache, taxonName));
|
980
|
}else if (generCandidate.ref.getType() == ReferenceType.Book){
|
981
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_BOOK, unparsedAndName(fullNomRefCache, taxonName));
|
982
|
}else if (generCandidate.ref.getType() == ReferenceType.Generic){
|
983
|
printResult(MatchType.NO_MATCH_SINGLE_PARSE_GENERIC, unparsedAndName(fullNomRefCache, taxonName));
|
984
|
}else {
|
985
|
printResult(MatchType.NO_MATCH_MULTI_PARSE, unparsedAndName(fullNomRefCache, taxonName));
|
986
|
}
|
987
|
}
|
988
|
|
989
|
// System.out.println(fullNomRefCache);
|
990
|
}
|
991
|
|
992
|
private static final Reference NO_REMAINING_SINGLE = ReferenceFactory.newGeneric();
|
993
|
/**
|
994
|
* @param parsedCandidates
|
995
|
* @return
|
996
|
*/
|
997
|
private ReferenceCandidate createGenericReference(Set<FinalCandidate> parsedCandidates, String detail) {
|
998
|
Reference refGen = ReferenceFactory.newGeneric();
|
999
|
String title = null;
|
1000
|
VerbatimTimePeriod datePublished = null;
|
1001
|
String volume = null;
|
1002
|
String series = null;
|
1003
|
String edition = null;
|
1004
|
TeamOrPersonBase<?> author = null;
|
1005
|
|
1006
|
Reference journalCandidate = null;
|
1007
|
Reference remainingSingle = null;
|
1008
|
for (FinalCandidate parsedCand : parsedCandidates){
|
1009
|
|
1010
|
Reference ref = parsedCand.exemplar.ref;
|
1011
|
if (ref.getType().isArticle()){
|
1012
|
journalCandidate = ref;
|
1013
|
}
|
1014
|
if (!ref.getType().isPublication()){
|
1015
|
if (ref.getInReference().getAbbrevTitle().matches("((ser|ed)\\..*|(Beih|App|Suppl|Praef|Bot|S\u00E9r\\. Bot|Prodr|Alt|Ap|Nachtr)\\.|Apend|Texte|Atlas)")){
|
1016
|
continue;
|
1017
|
}
|
1018
|
}
|
1019
|
if (ref.getType().isArticle()){
|
1020
|
if (ref.getVolume() == null || ref.getInReference().getAbbrevTitle().endsWith(", ed.")){
|
1021
|
continue;
|
1022
|
}
|
1023
|
}
|
1024
|
if (ref.getType().isBook()){
|
1025
|
if (ref.getAbbrevTitle().matches("(Abh|Acad|Act|Akad|Ann|Arch|Ark|"
|
1026
|
+ "Ber|Bergens Mus|Bibliot|Biol\\. Skr|Boll?|Cah\\. Soc|Doc|Dokl|Erd\u00E9sz|"
|
1027
|
+ "Int|Izv|Mem|Mitt|M\u00E9m|Nachr|Novit|Novye Mem|"
|
1028
|
+ "Nuovi Ann|Pract|Proc|Publ|Quad|Razpr|Rec|Repert|Samml|Sitzungsber|"
|
1029
|
+ "Verh)\\.\\s.*") ||
|
1030
|
ref.getAbbrevTitle().matches("(Acta|Actes|Anais|Analele|Anales|"
|
1031
|
+ "Atti|Daffodil|Florist|Indian|Ionios|Monthly|Naturaleza|Orchidophile|"
|
1032
|
+ "Posebna|Recueil|R[ei]vista|Spicy|Trudy)\\s.*")){
|
1033
|
continue;
|
1034
|
}
|
1035
|
}
|
1036
|
|
1037
|
//title
|
1038
|
if (ref.getType().isPublication()){
|
1039
|
title = verify(title, ref.getAbbrevTitle());
|
1040
|
}else{
|
1041
|
title = verify(title, ref.getInReference().getAbbrevTitle());
|
1042
|
}
|
1043
|
//volume
|
1044
|
if (ref.getType().isVolumeReference()){
|
1045
|
volume = verify(volume, ref.getVolume());
|
1046
|
}else{
|
1047
|
volume = verify(volume, ref.getInReference().getVolume());
|
1048
|
}
|
1049
|
//edition
|
1050
|
if (ref.getType().isVolumeReference()){
|
1051
|
edition = verify(edition, ref.getEdition());
|
1052
|
}else{
|
1053
|
edition = verify(edition, ref.getInReference().getEdition());
|
1054
|
}
|
1055
|
//series
|
1056
|
if (ref.getType().isVolumeReference()){
|
1057
|
series = verify(series, ref.getSeriesPart());
|
1058
|
}else{
|
1059
|
series = verify(series, ref.getInReference().getSeriesPart());
|
1060
|
}
|
1061
|
//datePublished
|
1062
|
datePublished = verify(datePublished, ref.getDatePublished());
|
1063
|
//datePublished
|
1064
|
author = verify(author, ref.getAuthorship());
|
1065
|
|
1066
|
remainingSingle = remainingSingle == null? ref : NO_REMAINING_SINGLE;
|
1067
|
}
|
1068
|
|
1069
|
if (remainingSingle == null){
|
1070
|
System.out.println("No remaing ref. This should not happen.");
|
1071
|
}else if (remainingSingle != NO_REMAINING_SINGLE){
|
1072
|
refGen = remainingSingle;
|
1073
|
}else if (IJournal.guessIsJournalName(title) && journalCandidate != null){
|
1074
|
refGen = journalCandidate;
|
1075
|
}else{
|
1076
|
refGen.setAbbrevTitle(title);
|
1077
|
refGen.setVolume(volume);
|
1078
|
refGen.setEdition(edition);
|
1079
|
refGen.setSeriesPart(series);
|
1080
|
refGen.setDatePublished(datePublished);
|
1081
|
refGen.setAuthorship(author);
|
1082
|
}
|
1083
|
|
1084
|
ReferenceCandidate cand = new ReferenceCandidate(refGen, detail);
|
1085
|
return cand;
|
1086
|
}
|
1087
|
|
1088
|
|
1089
|
/**
|
1090
|
* @param existing
|
1091
|
* @param newText
|
1092
|
* @return
|
1093
|
*/
|
1094
|
private <T extends Object> T verify(T existing, T newText) {
|
1095
|
if (existing == null){
|
1096
|
return newText;
|
1097
|
}else if (existing.equals(newText)){
|
1098
|
return existing;
|
1099
|
}else if (newText == null){
|
1100
|
logger.warn("Text not verified, missing, before: " + existing);
|
1101
|
return existing;
|
1102
|
}else{
|
1103
|
logger.warn("Text not verified, differs: " + existing + "<->" +newText);
|
1104
|
return existing;
|
1105
|
}
|
1106
|
}
|
1107
|
|
1108
|
|
1109
|
/**
|
1110
|
* @param finalCandidates
|
1111
|
* @return
|
1112
|
*/
|
1113
|
private boolean hasNoCandidateExemplars(Set<FinalCandidate> finalCandidates) {
|
1114
|
for (FinalCandidate finalCandidate : finalCandidates){
|
1115
|
if (finalCandidate.matchResult != UNPARSED_EXEMPLAR && finalCandidate.matchResult != PARSED_NO_CANDIDATE ){
|
1116
|
return false;
|
1117
|
}
|
1118
|
}
|
1119
|
return true;
|
1120
|
}
|
1121
|
|
1122
|
private Set<FinalCandidate> getParsedExemplars(Set<FinalCandidate> finalCandidates) {
|
1123
|
Set<FinalCandidate> parsedCandidates = new HashSet<>();
|
1124
|
for (FinalCandidate finalCandidate : finalCandidates){
|
1125
|
if (finalCandidate.matchResult != UNPARSED_EXEMPLAR){
|
1126
|
parsedCandidates.add(finalCandidate);
|
1127
|
}
|
1128
|
}
|
1129
|
return parsedCandidates;
|
1130
|
}
|
1131
|
|
1132
|
/**
|
1133
|
* @param finalCandidates
|
1134
|
* @return
|
1135
|
*/
|
1136
|
private boolean hasOnlyUnparsedExemplars(Set<FinalCandidate> finalCandidates) {
|
1137
|
for (FinalCandidate finalCandidate : finalCandidates){
|
1138
|
if (finalCandidate.matchResult != UNPARSED_EXEMPLAR){
|
1139
|
return false;
|
1140
|
}
|
1141
|
}
|
1142
|
return true;
|
1143
|
}
|
1144
|
|
1145
|
|
1146
|
/**
|
1147
|
* @param refDetailId
|
1148
|
* @param state
|
1149
|
* @param taxonName
|
1150
|
* @param single
|
1151
|
*/
|
1152
|
private void addAuthorAndDetail(BerlinModelImportState state, int refDetailId, TaxonName taxonName, ReferenceCandidate refCand) {
|
1153
|
if (!CdmUtils.nullSafeEqual(refCand.ref.getAuthorship(), taxonName.getCombinationAuthorship())){
|
1154
|
TeamOrPersonBase<?> refAuthor = refCand.ref.getAuthorship();
|
1155
|
TeamOrPersonBase<?> nameAuthor = taxonName.getCombinationAuthorship();
|
1156
|
if(refAuthor == null || nameAuthor == null){
|
1157
|
logger.warn("refAut or nameAut was null. RefDetailId = " + refDetailId); //this happened once
|
1158
|
return;
|
1159
|
}
|
1160
|
try {
|
1161
|
MatchResult match = MatchStrategyFactory.NewParsedTeamOrPersonInstance().invoke(refAuthor, nameAuthor, true);
|
1162
|
if (match.isFailed()){
|
1163
|
System.out.println("not same author \n"+ match);
|
1164
|
}else{
|
1165
|
taxonName.setCombinationAuthorship(refAuthor);
|
1166
|
}
|
1167
|
} catch (MatchException e) {
|
1168
|
// TODO Auto-generated catch block
|
1169
|
e.printStackTrace();
|
1170
|
}
|
1171
|
}
|
1172
|
if (refCand.ref.getSources().isEmpty()){
|
1173
|
refCand.ref.addImportSource(String.valueOf(refDetailId), BerlinModelRefDetailImport.REFDETAIL_NAMESPACE, state.getTransactionalSourceReference(), null);
|
1174
|
}
|
1175
|
// if (!refCand.ref.isPersited()){
|
1176
|
// getReferenceService().save(refCand.ref);
|
1177
|
// }
|
1178
|
|
1179
|
Reference nomRef = state.getDeduplicationHelper().getExistingReference(refCand.ref);
|
1180
|
if (nomRef != refCand.ref){
|
1181
|
System.out.println("Ref deduplicated: " + nomRef.getTitleCache() + "(RefDetId: " + refDetailId + ")");
|
1182
|
if (nomRef.isPersited() && !getSession().contains(nomRef)){
|
1183
|
System.out.println("Start load with uuid: " + nomRef.getUuid() + ")");
|
1184
|
nomRef = getReferenceService().find(nomRef.getUuid());
|
1185
|
}
|
1186
|
}
|
1187
|
|
1188
|
taxonName.setNomenclaturalReference(nomRef);
|
1189
|
taxonName.setNomenclaturalMicroReference(refCand.detail);
|
1190
|
}
|
1191
|
|
1192
|
//
|
1193
|
// /**
|
1194
|
// * @param finalCandidates
|
1195
|
// * @return
|
1196
|
// */
|
1197
|
// private int getSuccessCount(Set<FinalCandidate> finalCandidates) {
|
1198
|
// int i = 0;
|
1199
|
// for (FinalCandidate candidate : finalCandidates){
|
1200
|
// if (candidate.matchResult.isSuccessful()){
|
1201
|
// i++;
|
1202
|
// }
|
1203
|
// }
|
1204
|
// return i;
|
1205
|
// }
|
1206
|
|
1207
|
private String unparsedAndName(String fullNomRefCache, TaxonName taxonName) {
|
1208
|
return fullNomRefCache +" | " + taxonName.getFullTitleCache();
|
1209
|
}
|
1210
|
|
1211
|
private void printResult(MatchType type, String text) {
|
1212
|
List<String> list = matchResults.get(type);
|
1213
|
if (list == null){
|
1214
|
list = new ArrayList<>();
|
1215
|
matchResults.put(type, list);
|
1216
|
}
|
1217
|
list.add(text);
|
1218
|
|
1219
|
}
|
1220
|
|
1221
|
|
1222
|
/**
|
1223
|
* @param fullNomRefCache
|
1224
|
* @param finalCandidates
|
1225
|
* @param taxonName
|
1226
|
* @return
|
1227
|
*/
|
1228
|
private String resultMessage(String fullNomRefCache, Set<FinalCandidate> finalCandidates, TaxonName taxonName) {
|
1229
|
String result = unparsedAndName(fullNomRefCache, taxonName)+"\n";
|
1230
|
result += finalCandidates.size() +": " + matchResultMessage(finalCandidates);
|
1231
|
return result;
|
1232
|
}
|
1233
|
|
1234
|
|
1235
|
/**
|
1236
|
* @param finalCandidates
|
1237
|
* @param result
|
1238
|
* @return
|
1239
|
*/
|
1240
|
private String matchResultMessage(Set<FinalCandidate> finalCandidates) {
|
1241
|
String result = "\n ";
|
1242
|
for (FinalCandidate finalCand : finalCandidates){
|
1243
|
result += finalCand.matchResult.toString()+"\n ";
|
1244
|
}
|
1245
|
return result;
|
1246
|
}
|
1247
|
|
1248
|
|
1249
|
private Set<FinalCandidate> getSuccess(Set<FinalCandidate> finalCandidates) {
|
1250
|
Set<FinalCandidate> result = new HashSet<>();
|
1251
|
for (FinalCandidate candidate : finalCandidates){
|
1252
|
if (candidate.matchResult.isSuccessful()){
|
1253
|
result.add(candidate);
|
1254
|
}
|
1255
|
}
|
1256
|
return result;
|
1257
|
}
|
1258
|
|
1259
|
|
1260
|
/**
|
1261
|
* return object not really necessary here
|
1262
|
*/
|
1263
|
private FinalCandidate findBestMatchingFinalCandidate(BerlinModelImportState state, int refDetailId, TaxonName taxonName,
|
1264
|
Set<FinalCandidate> finalCandidates, String fullNomRefCache) {
|
1265
|
try {
|
1266
|
Set<FinalCandidate> persistentMatches = findPersistentMatch(taxonName, finalCandidates);
|
1267
|
if (persistentMatches.size() >= 1){
|
1268
|
if (persistentMatches.size()>1){
|
1269
|
Set<FinalCandidate> exactMatches = findExactMatch(taxonName, finalCandidates);
|
1270
|
Set<FinalCandidate> successCandidatesExacts = getSuccess(exactMatches);
|
1271
|
if (successCandidatesExacts.size() >= 1){
|
1272
|
FinalCandidate result = successCandidatesExacts.iterator().next();
|
1273
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1274
|
// String message = resultMessage(fullNomRefCache, exactMatches, taxonName);
|
1275
|
if (successCandidatesExacts.size()>1){
|
1276
|
printResult(MatchType.MULTI_MULTI_PERSISTENT_MULTI_EXACT, unparsedAndName(fullNomRefCache, taxonName));
|
1277
|
}else{
|
1278
|
printResult(MatchType.MULTI_MULTI_PERSISTENT_SINGLE_EXACT, unparsedAndName(fullNomRefCache, taxonName));
|
1279
|
}
|
1280
|
return result;
|
1281
|
}else{
|
1282
|
String message = resultMessage(fullNomRefCache, successCandidatesExacts, taxonName);
|
1283
|
printResult(MatchType.MULTI_MULTI_PERSISTENT_NO_EXACT, message);
|
1284
|
FinalCandidate result = persistentMatches.iterator().next();
|
1285
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1286
|
return result;
|
1287
|
}
|
1288
|
}else{
|
1289
|
FinalCandidate result = persistentMatches.iterator().next();
|
1290
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1291
|
printResult(MatchType.MULTI_SINGLE_PERSISTENT, taxonName.getFullTitleCache());
|
1292
|
return result;
|
1293
|
}
|
1294
|
}
|
1295
|
Set<FinalCandidate> exactMatches = findExactMatch(taxonName, finalCandidates);
|
1296
|
Set<FinalCandidate> successCandidatesExacts = getSuccess(exactMatches);
|
1297
|
if (successCandidatesExacts.size() >= 1){
|
1298
|
FinalCandidate result = successCandidatesExacts.iterator().next();
|
1299
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1300
|
String message = resultMessage(fullNomRefCache, exactMatches, taxonName);
|
1301
|
if (successCandidatesExacts.size()>1){
|
1302
|
printResult(MatchType.MULTI_NO_PERSISTENT_MULTI_EXACT, message);
|
1303
|
// System.out.println("More then 1 exact match: " + taxonName.getFullTitleCache() + ": " + exactMatches.iterator().next().exemplar.ref.getAbbrevTitleCache());
|
1304
|
}else{
|
1305
|
printResult(MatchType.MULTI_NO_PERSISTENT_SINGLE_EXACT, message);
|
1306
|
}
|
1307
|
return result;
|
1308
|
}else{
|
1309
|
FinalCandidate result = finalCandidates.iterator().next();
|
1310
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1311
|
String message = resultMessage(fullNomRefCache, exactMatches, taxonName);
|
1312
|
printResult(MatchType.MULTI_NO_PERSISTENT_NO_EXACT, message);
|
1313
|
return result;
|
1314
|
}
|
1315
|
} catch (MatchException e) {
|
1316
|
e.printStackTrace();
|
1317
|
FinalCandidate result = finalCandidates.iterator().next();
|
1318
|
addAuthorAndDetail(state, refDetailId, taxonName, result.candidate);
|
1319
|
return result;
|
1320
|
}
|
1321
|
}
|
1322
|
|
1323
|
|
1324
|
|
1325
|
/**
|
1326
|
* @param taxonName
|
1327
|
* @param finalCandidates
|
1328
|
* @return
|
1329
|
*/
|
1330
|
private String getMultiMultiPersistentMessage(TaxonName taxonName, Set<FinalCandidate> finalCandidates) {
|
1331
|
String result = finalCandidates.size() + ":" + taxonName.getFullTitleCache();
|
1332
|
result += matchResultMessage(finalCandidates);
|
1333
|
return result;
|
1334
|
}
|
1335
|
private String getMultiNoPersistentMultiExactMessage(TaxonName taxonName, Set<FinalCandidate> finalCandidates) {
|
1336
|
String result = finalCandidates.size() + ":" + taxonName.getFullTitleCache();
|
1337
|
result += matchResultMessage(finalCandidates);
|
1338
|
return result;
|
1339
|
}
|
1340
|
|
1341
|
/**
|
1342
|
* @param taxonName
|
1343
|
* @param finalCandidates
|
1344
|
* @param exemplars
|
1345
|
* @return
|
1346
|
* @throws MatchException
|
1347
|
*/
|
1348
|
private Set<FinalCandidate> findExactMatch(TaxonName taxonName, Set<FinalCandidate> finalCandidates) throws MatchException {
|
1349
|
IMatchStrategyEqual exactMatcher = getExactMatcher();
|
1350
|
Set<FinalCandidate> result = new HashSet<>();
|
1351
|
for (FinalCandidate cand : finalCandidates){
|
1352
|
Reference exemplarRef = cand.exemplar.ref;
|
1353
|
if (cand.candidate.ref.getType().equals(exemplarRef.getType())){
|
1354
|
MatchResult match = exactMatcher.invoke(cand.candidate.ref, exemplarRef, true);
|
1355
|
result.add(new FinalCandidate(cand.candidate, cand.exemplar, match));
|
1356
|
if (match.isFailed()){
|
1357
|
String oldTitle = exemplarRef.getTitle();
|
1358
|
exemplarRef.setTitle(exemplarRef.getAbbrevTitle());
|
1359
|
match = exactMatcher.invoke(cand.candidate.ref, exemplarRef, true);
|
1360
|
if (match.isSuccessful()){
|
1361
|
result.add(new FinalCandidate(cand.candidate, cand.exemplar, match));
|
1362
|
}
|
1363
|
exemplarRef.setTitle(oldTitle);
|
1364
|
}
|
1365
|
}else{
|
1366
|
MatchResult match = MatchResult.NewNoTypeInstance(cand.candidate.ref.getType(), exemplarRef.getType());
|
1367
|
FinalCandidate finCand = new FinalCandidate(cand.candidate, cand.exemplar, match);
|
1368
|
result.add(finCand);
|
1369
|
}
|
1370
|
}
|
1371
|
return result;
|
1372
|
}
|
1373
|
|
1374
|
/**
|
1375
|
* @return
|
1376
|
*/
|
1377
|
private IMatchStrategyEqual getExactMatcher() {
|
1378
|
IMatchStrategyEqual result = MatchStrategyFactory.NewDefaultInstance(Reference.class);
|
1379
|
FieldMatcher inRefMatcher = result.getMatching().getFieldMatcher("inReference");
|
1380
|
try {
|
1381
|
inRefMatcher.getMatchStrategy().setMatchMode("title", MatchMode.EQUAL);
|
1382
|
return result;
|
1383
|
} catch (MatchException e) {
|
1384
|
throw new RuntimeException("Problems creating exact matcher.", e);
|
1385
|
}//must not be EXACT_REQUIRED
|
1386
|
}
|
1387
|
|
1388
|
|
1389
|
private Set<FinalCandidate> findPersistentMatch(TaxonName taxonName, Set<FinalCandidate> finalCandidates) throws MatchException {
|
1390
|
Set<FinalCandidate> result = new HashSet<>();
|
1391
|
for (FinalCandidate cand : finalCandidates){
|
1392
|
if (cand.candidate.ref.isPersited()){
|
1393
|
result.add(cand);
|
1394
|
}
|
1395
|
}
|
1396
|
|
1397
|
return result;
|
1398
|
}
|
1399
|
|
1400
|
|
1401
|
/**
|
1402
|
* @param state
|
1403
|
* @param rs
|
1404
|
* @param taxonName
|
1405
|
* @param refMap
|
1406
|
* @param nameTitleCache
|
1407
|
* @param fullNomRefCache
|
1408
|
* @param finalCandidates
|
1409
|
* @param genericCandidate
|
1410
|
* @param exemplars2
|
1411
|
* @param finalCandidates
|
1412
|
* @throws SQLException
|
1413
|
*/
|
1414
|
public static final MatchResult UNPARSED_EXEMPLAR = new MatchResult();
|
1415
|
public static final MatchResult PARSED_NO_CANDIDATE = new MatchResult();
|
1416
|
{
|
1417
|
UNPARSED_EXEMPLAR.addNullMatching(null, null);
|
1418
|
PARSED_NO_CANDIDATE.addNullMatching(null, null);
|
1419
|
}
|
1420
|
private void makeFinalCandidates(BerlinModelImportState state, ResultSet rs, TaxonName taxonName,
|
1421
|
Map<String, Reference> refMap, String nameTitleCache,
|
1422
|
Set<FinalCandidate> finalCandidates,
|
1423
|
Set<FinalCandidate> finalInRefCandidates, Set<Reference> parsedReferences
|
1424
|
) throws SQLException {
|
1425
|
|
1426
|
Set<Integer> candidateIds = getPreliminaryIdCandidates(state, rs);
|
1427
|
Set<TaxonName> nameCandidates = parseExemplars(state, rs, taxonName);
|
1428
|
|
1429
|
Set<ReferenceCandidate> exemplars = new HashSet<>();
|
1430
|
for(TaxonName nameCandidate: nameCandidates){
|
1431
|
if(nameCandidate.getNomenclaturalReference()!= null){
|
1432
|
exemplars.add(new ReferenceCandidate(nameCandidate.getNomenclaturalReference(), nameCandidate.getNomenclaturalMicroReference()));
|
1433
|
parsedReferences.add(nameCandidate.getNomenclaturalReference());
|
1434
|
}
|
1435
|
}
|
1436
|
|
1437
|
for(ReferenceCandidate exemplar: exemplars){
|
1438
|
if (exemplar.ref.isProtectedAbbrevTitleCache() || exemplar.ref.isProtectedTitleCache()){
|
1439
|
FinalCandidate parsedNoCandidateExemplarCandidate = new FinalCandidate(null, exemplar, UNPARSED_EXEMPLAR);
|
1440
|
finalCandidates.add(parsedNoCandidateExemplarCandidate);
|
1441
|
}else if (candidateIds.isEmpty()){
|
1442
|
FinalCandidate unparsedExemplarCandidate = new FinalCandidate(null, exemplar, PARSED_NO_CANDIDATE);
|
1443
|
finalCandidates.add(unparsedExemplarCandidate);
|
1444
|
}else{
|
1445
|
for (Integer candidateId : candidateIds){
|
1446
|
if (candidateId == null){
|
1447
|
logger.warn("CandidateId not found: " + candidateId);
|
1448
|
continue;
|
1449
|
}
|
1450
|
Reference dedupCandidate = CdmBase.deproxy(refMap.get(String.valueOf(candidateId)));
|
1451
|
|
1452
|
//ref
|
1453
|
FinalCandidate cand = matchSingle(finalCandidates, dedupCandidate, exemplar, nameTitleCache);
|
1454
|
//inRef
|
1455
|
if (cand.matchResult.isFailed() && exemplar.ref.getInReference() != null ){
|
1456
|
FinalCandidate candInRef = matchSingle(finalInRefCandidates, dedupCandidate, new ReferenceCandidate(exemplar.ref.getInReference(), null), nameTitleCache);
|
1457
|
if(candInRef.matchResult.isSuccessful()){
|
1458
|
Reference clone = exemplar.ref.clone();
|
1459
|
clone.setInReference(dedupCandidate);
|
1460
|
FinalCandidate inRefCand = new FinalCandidate(new ReferenceCandidate(clone, exemplar.detail),
|
1461
|
exemplar, candInRef.matchResult);
|
1462
|
finalCandidates.add(inRefCand);
|
1463
|
}
|
1464
|
}
|
1465
|
}
|
1466
|
}
|
1467
|
}
|
1468
|
|
1469
|
return;
|
1470
|
}
|
1471
|
|
1472
|
|
1473
|
/**
|
1474
|
* @param finalCandidates
|
1475
|
* @param refCandidate
|
1476
|
* @param exemplar
|
1477
|
* @param fullNomRefCache
|
1478
|
* @param nameTitleCache
|
1479
|
*/
|
1480
|
protected FinalCandidate matchSingle(Set<FinalCandidate> finalCandidates, Reference dedupCandidate,
|
1481
|
ReferenceCandidate exemplar, String nameTitleCache) {
|
1482
|
|
1483
|
try {
|
1484
|
MatchResult match = null;
|
1485
|
FinalCandidate finalCand;
|
1486
|
IMatchStrategy matchStrategy = getReferenceMatchStrategy();
|
1487
|
Reference refExemplar = exemplar.ref;
|
1488
|
if(refExemplar.getType().equals(dedupCandidate.getType())){
|
1489
|
TeamOrPersonBase<?> exemplarAuthor = refExemplar.getAuthorship();
|
1490
|
TeamOrPersonBase<?> candidateAuthor = CdmBase.deproxy(dedupCandidate.getAuthorship());
|
1491
|
String cache = refExemplar.getTitleCache();
|
1492
|
String ccache = dedupCandidate.getTitleCache();
|
1493
|
String abbrevCache = refExemplar.getAbbrevTitleCache();
|
1494
|
String cabbrevCache = dedupCandidate.getAbbrevTitleCache();
|
1495
|
if (exemplarAuthor != null && candidateAuthor != null){
|
1496
|
exemplarAuthor.getTitleCache();
|
1497
|
String exemplarAuthorStr = exemplarAuthor.getNomenclaturalTitleCache();
|
1498
|
// System.out.println(exemplarAuthor.getTitleCache());
|
1499
|
String candidateAuthorStr = candidateAuthor.getNomenclaturalTitleCache();
|
1500
|
// System.out.println(candidateAuthor.getTitleCache());
|
1501
|
if (!exemplarAuthorStr.equals(candidateAuthorStr)){
|
1502
|
match = MatchResult.NewInstance(":authorship", MatchMode.EQUAL, exemplarAuthorStr, candidateAuthorStr);
|
1503
|
}
|
1504
|
}
|
1505
|
|
1506
|
if (match == null){
|
1507
|
match = matchStrategy.invoke(dedupCandidate, refExemplar, true);
|
1508
|
}
|
1509
|
|
1510
|
//TODO detail match
|
1511
|
//TODO formatter match
|
1512
|
if (true){
|
1513
|
// return true;
|
1514
|
}else if (refExemplar.getInReference() != null && dedupCandidate.getInReference() != null){
|
1515
|
// boolean matchInRef = matchStrategy.invoke(dedupCandidate.getInReference(), refExemplar.getInReference());
|
1516
|
// if(matchInRef){
|
1517
|
// Reference clone = (Reference)refExemplar.clone();
|
1518
|
// clone.setInReference(dedupCandidate.getInReference());
|
1519
|
// finalCandidates.add(new ReferenceCandidate(clone, exemplar.detail));
|
1520
|
// }
|
1521
|
}
|
1522
|
}else{
|
1523
|
match = MatchResult.NewNoTypeInstance(refExemplar.getType(), dedupCandidate.getType());
|
1524
|
}
|
1525
|
finalCand = new FinalCandidate(new ReferenceCandidate(dedupCandidate, exemplar.detail), exemplar, match);
|
1526
|
finalCandidates.add(finalCand);
|
1527
|
|
1528
|
return finalCand;
|
1529
|
} catch (MatchException e) {
|
1530
|
e.printStackTrace();
|
1531
|
throw new RuntimeException();
|
1532
|
}
|
1533
|
}
|
1534
|
|
1535
|
|
1536
|
private IMatchStrategy referenceMatchStrategy;
|
1537
|
|
1538
|
/**
|
1539
|
* @return
|
1540
|
* @throws MatchException
|
1541
|
*/
|
1542
|
protected IMatchStrategy getReferenceMatchStrategy() throws MatchException {
|
1543
|
|
1544
|
if (referenceMatchStrategy == null){
|
1545
|
referenceMatchStrategy = MatchStrategyFactory.NewParsedReferenceInstance();
|
1546
|
}
|
1547
|
// if (referenceMatchStrategy == null){
|
1548
|
// referenceMatchStrategy = DefaultMatchStrategy.NewInstance(Reference.class);
|
1549
|
//
|
1550
|
// referenceMatchStrategy.setMatchMode("title", MatchMode.EQUAL_OR_SECOND_NULL);
|
1551
|
// referenceMatchStrategy.setMatchMode("placePublished", MatchMode.EQUAL_OR_SECOND_NULL);
|
1552
|
// @SuppressWarnings("rawtypes")
|
1553
|
// SubClassMatchStrategy<TeamOrPersonBase> refAuthorMatchStrategy = SubClassMatchStrategy
|
1554
|
// .NewInstance(TeamOrPersonBase.class, Person.class, Team.class);
|
1555
|
// refAuthorMatchStrategy.setMatchMode(Person.class, "familyName", MatchMode.EQUAL_OR_SECOND_NULL);
|
1556
|
// refAuthorMatchStrategy.setMatchMode(Person.class, "givenName", MatchMode.EQUAL_OR_SECOND_NULL);
|
1557
|
// refAuthorMatchStrategy.setMatchMode(Person.class, "initials", MatchMode.EQUAL_OR_SECOND_NULL);
|
1558
|
// referenceMatchStrategy.setMatchMode("authorship", MatchMode.MATCH, refAuthorMatchStrategy);
|
1559
|
//
|
1560
|
// //for testing only
|
1561
|
//// referenceMatchStrategy = null;
|
1562
|
//// FieldMatcher autMatcher = referenceMatchStrategy.getMatching().getFieldMatcher("authorship");
|
1563
|
// }
|
1564
|
return referenceMatchStrategy;
|
1565
|
}
|
1566
|
|
1567
|
private Set<Integer> getPreliminaryIdCandidates(BerlinModelImportState state, ResultSet rs) throws SQLException{
|
1568
|
|
1569
|
Set<Integer> result = new HashSet<>();
|
1570
|
boolean refDetailPrelim = rs.getBoolean("RefDetailPrelim");
|
1571
|
if(state.getConfig().isDoPreliminaryRefDetailsWithNames() && refDetailPrelim){
|
1572
|
|
1573
|
Set<TaxonName> names = parseExemplars(state, rs, null);
|
1574
|
for (TaxonName name : names){
|
1575
|
Reference exemplar = name.getNomenclaturalReference();
|
1576
|
if (exemplar != null){
|
1577
|
Set<ReferenceCandidate> persistendCandidates = refMapping.getCandidates(exemplar);
|
1578
|
if (exemplar.getInReference()!= null){
|
1579
|
persistendCandidates.addAll(refMapping.getCandidates(exemplar.getInReference()));
|
1580
|
}
|
1581
|
for (ReferenceCandidate persistendCandidate : persistendCandidates){
|
1582
|
result.add(persistendCandidate.getId());
|
1583
|
}
|
1584
|
}
|
1585
|
}
|
1586
|
}
|
1587
|
return result;
|
1588
|
}
|
1589
|
|
1590
|
private Set<TaxonName> parseExemplars(BerlinModelImportState state, ResultSet rs, TaxonName taxonName) throws SQLException{
|
1591
|
BerlinModelImportConfigurator config = state.getConfig();
|
1592
|
|
1593
|
Set<TaxonName> result = new HashSet<>();
|
1594
|
|
1595
|
String fullNomRefCache = rs.getString("FullNomRefCache");
|
1596
|
String detail = rs.getString("Details");
|
1597
|
|
1598
|
|
1599
|
if (fullNomRefCache == null){
|
1600
|
// logger.warn("fullNomRefCache is null for preliminary refDetail. NameId: " + nameId);
|
1601
|
return result;
|
1602
|
}else if (fullNomRefCache.trim().startsWith(": ")){
|
1603
|
// logger.warn("fullNomRefCache starts with for preliminary refDetail. NameId: " + nameId);
|
1604
|
return result;
|
1605
|
}else{
|
1606
|
TaxonName testName = taxonName == null ? getTestName() : (TaxonName)taxonName.clone();
|
1607
|
|
1608
|
Set<String> fullStrCandidates;
|
1609
|
if (fullNomRefCache.trim().startsWith("in ")){
|
1610
|
//RefDetails with "in" references
|
1611
|
fullStrCandidates = makePrelimRefDetailInRef(state, testName, fullNomRefCache, detail);
|
1612
|
}else if (fullNomRefCache.trim().startsWith(", ")){
|
1613
|
//RefDetails with ", " reference
|
1614
|
fullStrCandidates = makePrelimRefDetailBook(state, testName, fullNomRefCache, detail);
|
1615
|
}else{
|
1616
|
//ordinary protected ref details
|
1617
|
fullStrCandidates = makePrelimRefDetailNotInRef(state, testName, fullNomRefCache, detail);
|
1618
|
}
|
1619
|
|
1620
|
for (String parseStr : fullStrCandidates){
|
1621
|
TaxonName newName = (TaxonName)parser.parseReferencedName(parseStr, config.getNomenclaturalCode(), testName.getRank());
|
1622
|
Reference newNomRef = newName.getNomenclaturalReference();
|
1623
|
if (taxonName != null && newNomRef != null && !newNomRef.isProtectedAbbrevTitleCache()&& !newNomRef.isProtectedTitleCache()){
|
1624
|
newNomRef.setAuthorship(taxonName.getCombinationAuthorship());
|
1625
|
}
|
1626
|
result.add(newName);
|
1627
|
// Reference exemplar = newName.getNomenclaturalReference();
|
1628
|
}
|
1629
|
return result;
|
1630
|
}
|
1631
|
}
|
1632
|
|
1633
|
|
1634
|
/**
|
1635
|
* @return
|
1636
|
*/
|
1637
|
protected TaxonName getTestName() {
|
1638
|
TaxonName testName = TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES(), null);
|
1639
|
testName.setGenusOrUninomial("Abies");
|
1640
|
testName.setSpecificEpithet("alba");
|
1641
|
testName.setAuthorshipCache("Mill.");
|
1642
|
return testName;
|
1643
|
}
|
1644
|
|
1645
|
|
1646
|
|
1647
|
/**
|
1648
|
* @param config
|
1649
|
* @param refMap
|
1650
|
* @param taxonName
|
1651
|
* @param nameId
|
1652
|
* @param fullNomRefCache
|
1653
|
* @return
|
1654
|
*/
|
1655
|
protected Set<String> makePrelimRefDetailNotInRef(BerlinModelImportState state, TaxonName taxonName,
|
1656
|
String fullNomRefCache, String detail) {
|
1657
|
Set<String> result = new HashSet<>();
|
1658
|
String fullStrComma = taxonName.getTitleCache()+ ", " + fullNomRefCache;
|
1659
|
result.add(fullStrComma);
|
1660
|
String fullStrIn = taxonName.getTitleCache()+ " in " + fullNomRefCache;
|
1661
|
result.add(fullStrIn);
|
1662
|
return result;
|
1663
|
|
1664
|
//
|
1665
|
// INonViralName newNameComma = parser.parseReferencedName(fullStrComma, config.getNomenclaturalCode(), taxonName.getRank());
|
1666
|
// INonViralName newNameIn = parser.parseReferencedName(fullStrIn, config.getNomenclaturalCode(), taxonName.getRank());
|
1667
|
//
|
1668
|
// INonViralName newName;
|
1669
|
// boolean commaProtected = newNameComma.isProtectedFullTitleCache() || (newNameComma.getNomenclaturalReference() != null
|
1670
|
// && newNameComma.getNomenclaturalReference().isProtectedTitleCache());
|
1671
|
// boolean inProtected = newNameIn.isProtectedFullTitleCache() || (newNameIn.getNomenclaturalReference() != null
|
1672
|
// && newNameIn.getNomenclaturalReference().isProtectedTitleCache());
|
1673
|
// if (commaProtected && !inProtected){
|
1674
|
// newName = newNameIn;
|
1675
|
// }else if (!commaProtected && inProtected){
|
1676
|
// newName = newNameComma;
|
1677
|
// }else if (commaProtected && inProtected){
|
1678
|
// logger.warn("Can't parse preliminary refDetail: " + fullNomRefCache + " for name " + taxonName.getTitleCache() + "; nameId: " + nameId );
|
1679
|
// newName = newNameComma;
|
1680
|
// }else{
|
1681
|
// logger.warn("Can't decide ref type for preliminary refDetail: " + fullNomRefCache + " for name " + taxonName.getTitleCache() + "; nameId: " + nameId );
|
1682
|
// newName = newNameComma;
|
1683
|
// }
|
1684
|
//
|
1685
|
//
|
1686
|
// if (newName.isProtectedFullTitleCache()){
|
1687
|
// Reference nomRef = ReferenceFactory.newGeneric();
|
1688
|
// nomRef.setAbbrevTitleCache(fullNomRefCache, true);
|
1689
|
// taxonName.setNomenclaturalReference(nomRef);
|
1690
|
// //check detail
|
1691
|
// }else{
|
1692
|
// Reference nomRef = newName.getNomenclaturalReference();
|
1693
|
// taxonName.setNomenclaturalReference(nomRef);
|
1694
|
// String detail = newName.getNomenclaturalMicroReference();
|
1695
|
// String oldDetail = taxonName.getNomenclaturalMicroReference();
|
1696
|
// if (isBlank(detail)){
|
1697
|
// if (isNotBlank(oldDetail)){
|
1698
|
// logger.warn("Detail could not be parsed but seems to exist. NameId: " + nameId);
|
1699
|
// }
|
1700
|
// }else{
|
1701
|
// if (isNotBlank(oldDetail) && !detail.equals(oldDetail)){
|
1702
|
// logger.warn("Details differ: " + detail + " <-> " + oldDetail + ". NameId: " + nameId);
|
1703
|
// }
|
1704
|
// taxonName.setNomenclaturalMicroReference(detail);
|
1705
|
// }
|
1706
|
// }
|
1707
|
}
|
1708
|
|
1709
|
|
1710
|
/**
|
1711
|
* @param config
|
1712
|
* @param refMap
|
1713
|
* @param taxonName
|
1714
|
* @param nameId
|
1715
|
* @param fullNomRefCache
|
1716
|
* @param detail
|
1717
|
* @return
|
1718
|
*/
|
1719
|
protected Set<String> makePrelimRefDetailInRef(BerlinModelImportState state,
|
1720
|
TaxonName taxonName,
|
1721
|
String fullNomRefCache, String detail) {
|
1722
|
|
1723
|
Set<String> result = new HashSet<>();
|
1724
|
String parseStr = taxonName.getTitleCache()+ " " + fullNomRefCache;
|
1725
|
result.add(parseStr);
|
1726
|
return result;
|
1727
|
|
1728
|
|
1729
|
// String detail = newName.getNomenclaturalMicroReference();
|
1730
|
// String oldDetail = taxonName.getNomenclaturalMicroReference();
|
1731
|
// if (isBlank(detail)){
|
1732
|
// if (isNotBlank(oldDetail)){
|
1733
|
// logger.warn("Detail could not be parsed but seems to exist. NameId: " + nameId);
|
1734
|
// }
|
1735
|
// }else{
|
1736
|
// if (isNotBlank(oldDetail) && !detail.equals(oldDetail)){
|
1737
|
// logger.warn("Details differ: " + detail + " <-> " + oldDetail + ". NameId: " + nameId);
|
1738
|
// }
|
1739
|
// taxonName.setNomenclaturalMicroReference(detail);
|
1740
|
// }
|
1741
|
}
|
1742
|
|
1743
|
protected Set<String> makePrelimRefDetailBook(BerlinModelImportState state,
|
1744
|
TaxonName taxonName,
|
1745
|
String fullNomRefCache, String detail) {
|
1746
|
|
1747
|
Set<String> result = new HashSet<>();
|
1748
|
String parseStr = taxonName.getTitleCache()+ fullNomRefCache;
|
1749
|
result.add(parseStr);
|
1750
|
return result;
|
1751
|
}
|
1752
|
|
1753
|
|
1754
|
/**
|
1755
|
* Creates the hash string for finding preliminary RefDetail duplicates
|
1756
|
* @param nomRef
|
1757
|
*/
|
1758
|
private String refHash(Reference nomRef) {
|
1759
|
// TeamOrPersonBase<?> author = nomRef.getAuthorship();
|
1760
|
// String authorStr = author == null? "" : author.getNomenclaturalTitle();
|
1761
|
|
1762
|
String title = nomRef.getAbbrevTitle();
|
1763
|
if (title == null){
|
1764
|
title = nomRef.getTitle();
|
1765
|
if (title == null && nomRef.getInReference() != null){
|
1766
|
title = nomRef.getInReference().getAbbrevTitle();
|
1767
|
if (title == null){
|
1768
|
title = nomRef.getInReference().getTitle();
|
1769
|
}
|
1770
|
}
|
1771
|
if (title == null){
|
1772
|
title = nomRef.getAbbrevTitleCache();
|
1773
|
}
|
1774
|
if (title == null){
|
1775
|
title = nomRef.getTitleCache();
|
1776
|
}
|
1777
|
}
|
1778
|
String vol = nomRef.getVolume();
|
1779
|
if (vol == null && nomRef.getInReference() != null){
|
1780
|
vol = nomRef.getInReference().getVolume();
|
1781
|
}
|
1782
|
String date = nomRef.getDatePublishedString();
|
1783
|
if (date == null && nomRef.getInReference() != null){
|
1784
|
date = nomRef.getInReference().getDatePublishedString();
|
1785
|
}
|
1786
|
ReferenceType type = nomRef.getType();
|
1787
|
|
1788
|
String result = CdmUtils.concat("@", title, vol, date, type.getKey());
|
1789
|
return result;
|
1790
|
}
|
1791
|
|
1792
|
|
1793
|
private static TeamOrPersonBase<?> getAuthorTeam(Map<String, Team> teamMap, Integer teamIdInt, int nameId, BerlinModelImportConfigurator config){
|
1794
|
if (teamIdInt == null){
|
1795
|
return null;
|
1796
|
}else {
|
1797
|
String teamIdStr = String.valueOf(teamIdInt);
|
1798
|
TeamOrPersonBase<?> author = teamMap.get(teamIdStr);
|
1799
|
if (author == null){
|
1800
|
//TODO
|
1801
|
if (!config.isIgnoreNull() && ! (teamIdStr.equals(0) && config.isIgnore0AuthorTeam()) ){
|
1802
|
logger.warn("AuthorTeam (teamId = " + teamIdStr + ") for TaxonName (nameId = " + nameId + ")"+
|
1803
|
" was not found in authorTeam store. Relation was not set!");
|
1804
|
}
|
1805
|
return null;
|
1806
|
}else{
|
1807
|
return author;
|
1808
|
}
|
1809
|
}
|
1810
|
}
|
1811
|
|
1812
|
@Override
|
1813
|
protected boolean doCheck(BerlinModelImportState state){
|
1814
|
IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonNameImportValidator();
|
1815
|
return validator.validate(state);
|
1816
|
}
|
1817
|
|
1818
|
@Override
|
1819
|
protected boolean isIgnore(BerlinModelImportState state){
|
1820
|
return ! state.getConfig().isDoTaxonNames();
|
1821
|
}
|
1822
|
|
1823
|
|
1824
|
|
1825
|
|
1826
|
|
1827
|
|
1828
|
//FOR FUTURE USE , DONT DELETE
|
1829
|
// new CdmStringMapper("nameId", "nameId"),
|
1830
|
// new CdmStringMapper("rankFk", "rankFk"),
|
1831
|
// new CdmStringMapper("nameCache", "nameCache"),
|
1832
|
// new CdmStringMapper("unnamedNamePhrase", "unnamedNamePhrase"),
|
1833
|
// new CdmStringMapper("fullNameCache", "fullNameCache"),
|
1834
|
// new CdmStringMapper("preliminaryFlag", "preliminaryFlag"),
|
1835
|
// new CdmStringMapper("supragenericName", "supragenericName"),
|
1836
|
// new CdmStringMapper("genus", "genus"),
|
1837
|
// new CdmStringMapper("genusSubdivisionEpi", "genusSubdivisionEpi"),
|
1838
|
// new CdmStringMapper("speciesEpi", "speciesEpi"),
|
1839
|
// new CdmStringMapper("infraSpeciesEpi", "infraSpeciesEpi"),
|
1840
|
// new CdmStringMapper("authorTeamFk", "authorTeamFk"),
|
1841
|
// new CdmStringMapper("exAuthorTeamFk", "exAuthorTeamFk"),
|
1842
|
// new CdmStringMapper("basAuthorTeamFk", "basAuthorTeamFk"),
|
1843
|
// new CdmStringMapper("exBasAuthorTeamFk", "exBasAuthorTeamFk"),
|
1844
|
// new CdmStringMapper("hybridFormulaFlag", "hybridFormulaFlag"),
|
1845
|
// new CdmStringMapper("monomHybFlag", "monomHybFlag"),
|
1846
|
// new CdmStringMapper("binomHybFlag", "binomHybFlag"),
|
1847
|
// new CdmStringMapper("trinomHybFlag", "trinomHybFlag"),
|
1848
|
// new CdmStringMapper("cultivarGroupName", "cultivarGroupName"),
|
1849
|
// new CdmStringMapper("cultivarName", "cultivarName"),
|
1850
|
// new CdmStringMapper("nomRefFk", "nomRefFk"),
|
1851
|
// new CdmStringMapper("nomRefDetailFk", "nomRefDetailFk"),
|
1852
|
// new CdmStringMapper("nameSourceRefFk", "nameSourceRefFk"),
|
1853
|
// new CdmStringMapper("source_Acc", "source_Acc"),
|
1854
|
// new CdmStringMapper("created_When", "created_When"),
|
1855
|
// new CdmStringMapper("created_Who", "created_Who"),
|
1856
|
// new CdmStringMapper("notes", "notes"),
|
1857
|
// new CdmStringMapper("parsingComments", "parsingComments"),
|
1858
|
// new CdmStringMapper("oldNomRefFk", "oldNomRefFk"),
|
1859
|
// new CdmStringMapper("oldNomRefDetailFk", "oldNomRefDetailFk"),
|
1860
|
// new CdmStringMapper("updated_Who", "updated_Who"),
|
1861
|
// new CdmStringMapper("orthoProjection", "orthoProjection"),
|
1862
|
|
1863
|
|
1864
|
}
|