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.tcsrdf;
|
11
|
|
12
|
import java.io.InputStream;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
import org.jdom.Attribute;
|
17
|
import org.jdom.Element;
|
18
|
import org.jdom.Namespace;
|
19
|
import org.springframework.stereotype.Component;
|
20
|
|
21
|
import com.hp.hpl.jena.rdf.model.Model;
|
22
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
23
|
import com.hp.hpl.jena.rdf.model.Property;
|
24
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
25
|
import com.hp.hpl.jena.rdf.model.ResIterator;
|
26
|
import com.hp.hpl.jena.rdf.model.Resource;
|
27
|
import com.hp.hpl.jena.rdf.model.Statement;
|
28
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
29
|
|
30
|
import eu.etaxonomy.cdm.common.XmlHelp;
|
31
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
32
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
33
|
import eu.etaxonomy.cdm.model.agent.Person;
|
34
|
import eu.etaxonomy.cdm.model.agent.Team;
|
35
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
36
|
import eu.etaxonomy.cdm.model.common.Marker;
|
37
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
38
|
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
|
39
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
40
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
41
|
import eu.etaxonomy.cdm.model.name.Rank;
|
42
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
43
|
import eu.etaxonomy.cdm.model.reference.IGeneric;
|
44
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
45
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
46
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
47
|
|
48
|
/**
|
49
|
* @author a.mueller
|
50
|
* @since 29.05.2008
|
51
|
*/
|
52
|
@Component
|
53
|
public class TcsRdfTaxonNameImport extends TcsRdfImportBase implements ICdmIO<TcsRdfImportState> {
|
54
|
private static final long serialVersionUID = -2547422867292051979L;
|
55
|
|
56
|
private static final Logger logger = LogManager.getLogger(TcsRdfTaxonNameImport.class);
|
57
|
|
58
|
private static int modCount = 5000;
|
59
|
|
60
|
public TcsRdfTaxonNameImport(){
|
61
|
super();
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
public boolean doCheck(TcsRdfImportState config){
|
66
|
boolean result = true;
|
67
|
// logger.warn("BasionymRelations not yet implemented");
|
68
|
// logger.warn("Checking for TaxonNames not yet implemented");
|
69
|
|
70
|
return result;
|
71
|
}
|
72
|
|
73
|
protected static CdmSingleAttributeRDFMapperBase[] standardMappers = new CdmSingleAttributeRDFMapperBase[]{
|
74
|
new CdmTextElementMapper("genusPart", "genusOrUninomial")
|
75
|
, new CdmTextElementMapper("uninomial", "genusOrUninomial") //TODO make it a more specific Mapper for both attributes
|
76
|
, new CdmTextElementMapper("specificEpithet", "specificEpithet")
|
77
|
, new CdmTextElementMapper("infraspecificEpithet", "infraSpecificEpithet")
|
78
|
, new CdmTextElementMapper("infragenericEpithet", "infraGenericEpithet")
|
79
|
, new CdmTextElementMapper("microReference", nsTcom, "nomenclaturalMicroReference")
|
80
|
|
81
|
};
|
82
|
|
83
|
protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
|
84
|
new CdmUnclearMapper("basionymAuthorship")
|
85
|
, new CdmUnclearMapper("combinationAuthorship")
|
86
|
, new CdmUnclearMapper("hasAnnotation")
|
87
|
, new CdmUnclearMapper("rank")
|
88
|
, new CdmUnclearMapper("nomenclaturalCode")
|
89
|
, new CdmUnclearMapper("publishedIn", nsTcom)
|
90
|
, new CdmUnclearMapper("year")
|
91
|
};
|
92
|
|
93
|
protected static CdmSingleAttributeRDFMapperBase[] unclearMappers = new CdmSingleAttributeRDFMapperBase[]{
|
94
|
new CdmUnclearMapper("authorship")
|
95
|
, new CdmUnclearMapper("rankString")
|
96
|
, new CdmUnclearMapper("nameComplete")
|
97
|
, new CdmUnclearMapper("hasBasionym")
|
98
|
, new CdmUnclearMapper("dateOfEntry", nsTpalm)
|
99
|
};
|
100
|
|
101
|
@Override
|
102
|
protected void doInvoke(TcsRdfImportState state){
|
103
|
|
104
|
MapWrapper<TaxonName> taxonNameMap = (MapWrapper<TaxonName>)state.getStore(ICdmIO.TAXONNAME_STORE);
|
105
|
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
|
106
|
MapWrapper<TeamOrPersonBase> authorMap = (MapWrapper<TeamOrPersonBase>)state.getStore(ICdmIO.TEAM_STORE);
|
107
|
|
108
|
String tcsElementName;
|
109
|
Namespace tcsNamespace;
|
110
|
String value;
|
111
|
|
112
|
logger.info("start makeTaxonNames ...");
|
113
|
TcsRdfImportConfigurator config = state.getConfig();
|
114
|
Model root = config.getSourceRoot();
|
115
|
|
116
|
String rdfNamespace = config.getRdfNamespaceURIString();
|
117
|
String taxonNameNamespace = config.getTnNamespaceURIString();
|
118
|
|
119
|
String idNamespace = "TaxonName";
|
120
|
|
121
|
Resource elTaxonName = root.getResource(taxonNameNamespace);
|
122
|
|
123
|
int i = 0;
|
124
|
|
125
|
TaxonName name;
|
126
|
Property property = root.getProperty(taxonNameNamespace+"authorship");
|
127
|
|
128
|
ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null);
|
129
|
String id ;
|
130
|
while (iterator.hasNext()){
|
131
|
|
132
|
Resource resource = iterator.next();
|
133
|
|
134
|
name = handleNameResource(resource, config);
|
135
|
id = resource.getNameSpace();
|
136
|
taxonNameMap.put(id, name);
|
137
|
}
|
138
|
|
139
|
logger.info(i + " names handled");
|
140
|
getNameService().save(taxonNameMap.objects());
|
141
|
// makeNameSpecificData(nameMap);
|
142
|
logger.info("end makeTaxonNames ...");
|
143
|
return;
|
144
|
|
145
|
}
|
146
|
|
147
|
@Override
|
148
|
protected boolean isIgnore(TcsRdfImportState state){
|
149
|
return ! state.getConfig().isDoTaxonNames();
|
150
|
}
|
151
|
|
152
|
protected TaxonName handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonName> taxonNameMap, String uri){
|
153
|
Resource nameAbout = model.getResource(uri);
|
154
|
TaxonName result = handleNameResource(nameAbout, config);
|
155
|
taxonNameMap.put(uri, result);
|
156
|
return result;
|
157
|
|
158
|
}
|
159
|
|
160
|
private TaxonName handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){
|
161
|
String idNamespace = "TaxonName";
|
162
|
|
163
|
// StmtIterator stmts = nameAbout.listProperties();
|
164
|
// while(stmts.hasNext()){
|
165
|
// System.out.println(stmts.next().getPredicate().toString());
|
166
|
// }
|
167
|
|
168
|
Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode");
|
169
|
Statement stateNomenclaturalCode = nameAbout.getProperty(prop);
|
170
|
String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString();
|
171
|
//Rank
|
172
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString");
|
173
|
String strRank = nameAbout.getProperty(prop).getString();
|
174
|
|
175
|
|
176
|
|
177
|
try {
|
178
|
|
179
|
Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
|
180
|
NomenclaturalCode nomCode;
|
181
|
if (strNomenclaturalCode != null){
|
182
|
nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
|
183
|
}else{
|
184
|
nomCode = NomenclaturalCode.ICNAFP;
|
185
|
}
|
186
|
|
187
|
TaxonName nameBase = nomCode.getNewTaxonNameInstance(rank);
|
188
|
|
189
|
//Set<String> omitAttributes = null;
|
190
|
//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
|
191
|
|
192
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete");
|
193
|
String strNameComplete = nameAbout.getProperty(prop).getString();
|
194
|
nameBase.setTitleCache(strNameComplete, true);
|
195
|
|
196
|
prop = nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn");
|
197
|
String strPublishedIn = nameAbout.getProperty(prop).getString();
|
198
|
if (strPublishedIn != null && strPublishedIn != ""){
|
199
|
IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
|
200
|
nomRef.setTitleCache(strPublishedIn, true);
|
201
|
nameBase.setNomenclaturalReference(nomRef);
|
202
|
try{
|
203
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"year");
|
204
|
String strYear = nameAbout.getProperty(prop).getString();
|
205
|
Integer year = null;
|
206
|
if (strYear != null){
|
207
|
try {
|
208
|
year = Integer.valueOf(strYear);
|
209
|
VerbatimTimePeriod timeP = VerbatimTimePeriod.NewVerbatimInstance(year);
|
210
|
nomRef.setDatePublished(timeP);
|
211
|
} catch (RuntimeException e) {
|
212
|
logger.warn("year could not be parsed");
|
213
|
}
|
214
|
}
|
215
|
}catch(NullPointerException e){
|
216
|
}
|
217
|
if (config.isPublishReferences()){
|
218
|
((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
|
219
|
}
|
220
|
}
|
221
|
|
222
|
if (nameBase.isNonViral()){
|
223
|
INonViralName nonViralName = nameBase;
|
224
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart");
|
225
|
String strGenusPart;
|
226
|
try{
|
227
|
strGenusPart = nameAbout.getProperty(prop).getString();
|
228
|
}catch(NullPointerException e){
|
229
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial");
|
230
|
strGenusPart = nameAbout.getProperty(prop).getString();
|
231
|
}
|
232
|
|
233
|
nonViralName.setGenusOrUninomial(strGenusPart);
|
234
|
|
235
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet");
|
236
|
try{
|
237
|
String strInfragenericEpithet = nameAbout.getProperty(prop).getString();
|
238
|
nonViralName.setInfraGenericEpithet(strInfragenericEpithet);
|
239
|
}catch(NullPointerException e){
|
240
|
|
241
|
}
|
242
|
try {
|
243
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet");
|
244
|
String strSpecificEpithet = nameAbout.getProperty(prop).getString();
|
245
|
nonViralName.setSpecificEpithet(strSpecificEpithet);
|
246
|
}catch(NullPointerException e){
|
247
|
|
248
|
}
|
249
|
try{
|
250
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet");
|
251
|
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
|
252
|
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
|
253
|
}catch(NullPointerException e){
|
254
|
|
255
|
}
|
256
|
//Authorships
|
257
|
//TODO
|
258
|
/*
|
259
|
* <tn:authorteam>
|
260
|
<tm:Team>
|
261
|
<tm:name>(Raf.) Fernald</tm:name>
|
262
|
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1"
|
263
|
tm:index="1"
|
264
|
tm:role="Combination Author"/>
|
265
|
<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
|
266
|
tm:index="1"
|
267
|
tm:role="Basionym Author"/>
|
268
|
</tm:Team>
|
269
|
</tn:authorteam>
|
270
|
*/
|
271
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"authorship");
|
272
|
Statement stateAuthorship = nameAbout.getProperty(prop);
|
273
|
prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"authorteam");
|
274
|
Statement stateAuthorTeam = nameAbout.getProperty(prop);
|
275
|
Team authorTeam = new Team();
|
276
|
authorTeam.setTitleCache(stateAuthorship.getObject().toString(), true);
|
277
|
Statement stateAutorTeamTeam = null;
|
278
|
Statement stateAutorTeamName = null;
|
279
|
StmtIterator stateTeamMember = null;
|
280
|
if (stateAuthorTeam != null){
|
281
|
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"Team");
|
282
|
try{
|
283
|
stateAutorTeamTeam = stateAuthorTeam.getProperty(prop);
|
284
|
}catch(Exception e){
|
285
|
|
286
|
}
|
287
|
try{
|
288
|
prop = stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"name");
|
289
|
stateAutorTeamName = stateAuthorTeam.getProperty(prop);
|
290
|
}catch(Exception e){
|
291
|
|
292
|
}
|
293
|
try{
|
294
|
prop = nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember");
|
295
|
stateTeamMember = ((Resource)stateAuthorTeam.getObject()).listProperties(prop);
|
296
|
String memberString = null;
|
297
|
Person person;
|
298
|
for (Statement statement :stateTeamMember.toList()){
|
299
|
memberString =statement.getObject().toString();
|
300
|
if (memberString != null){
|
301
|
person = Person.NewTitledInstance(memberString);
|
302
|
authorTeam.addTeamMember(person);
|
303
|
}
|
304
|
}
|
305
|
}catch(Exception e){
|
306
|
System.err.println(e.getMessage());
|
307
|
}
|
308
|
}
|
309
|
|
310
|
|
311
|
|
312
|
nonViralName.setCombinationAuthorship(authorTeam);
|
313
|
|
314
|
//Annotations:
|
315
|
/*
|
316
|
* <tn:hasAnnotation>
|
317
|
<tn:NomenclaturalNote>
|
318
|
<tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/>
|
319
|
<tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/>
|
320
|
</tn:NomenclaturalNote>
|
321
|
</tn:hasAnnotation>
|
322
|
*/
|
323
|
/*
|
324
|
String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
|
325
|
tcsElementName = "basionymAuthorship";
|
326
|
String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
327
|
if (basionymAuthorValue != null){
|
328
|
TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
|
329
|
basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
|
330
|
nonViralName.setBasionymAuthorship(basionymAuthor);
|
331
|
}
|
332
|
|
333
|
//TODO
|
334
|
tcsElementName = "combinationAuthorship";
|
335
|
String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
336
|
if (combinationAuthorValue != null){
|
337
|
TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
|
338
|
combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
|
339
|
nonViralName.setCombinationAuthorship(combinationAuthor);
|
340
|
}
|
341
|
|
342
|
//set the authorshipCache
|
343
|
tcsElementName = "authorship";
|
344
|
String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
345
|
String cache = nonViralName.getAuthorshipCache();
|
346
|
if ( authorValue != null){
|
347
|
//compare existing authorship cache with new one and check if it is necessary to
|
348
|
//make cache protected //TODO refinement
|
349
|
if (cache == null){
|
350
|
nonViralName.setAuthorshipCache(authorValue);
|
351
|
}else{
|
352
|
cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
|
353
|
cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
|
354
|
cache = cache.replace("\\(|\\)", "");
|
355
|
cache = cache.trim();
|
356
|
if (! cache.equals("")){
|
357
|
nonViralName.setAuthorshipCache(authorValue);
|
358
|
}
|
359
|
}
|
360
|
}*/
|
361
|
}
|
362
|
//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
|
363
|
|
364
|
//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
|
365
|
|
366
|
return nameBase;
|
367
|
|
368
|
}catch(Exception e){
|
369
|
e.printStackTrace();
|
370
|
return null;
|
371
|
}
|
372
|
/*
|
373
|
//name
|
374
|
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
|
375
|
nameBase.setTitleCache(strNameComplete, true);
|
376
|
|
377
|
//Reference
|
378
|
//TODO
|
379
|
String tcsElementName = "publishedIn";
|
380
|
Namespace tcsNamespace = config.getCommonNamespaceURIString();
|
381
|
String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
|
382
|
if (value != null && value != ""){
|
383
|
IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
|
384
|
nomRef.setTitleCache(value, true);
|
385
|
nameBase.setNomenclaturalReference(nomRef);
|
386
|
|
387
|
//TODO
|
388
|
tcsElementName = "year";
|
389
|
tcsNamespace = taxonNameNamespace;
|
390
|
Integer year = null;
|
391
|
value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
|
392
|
if (value != null){
|
393
|
try {
|
394
|
year = Integer.valueOf(value);
|
395
|
TimePeriod timeP = TimePeriod.NewInstance(year);
|
396
|
nomRef.setDatePublished(timeP);
|
397
|
} catch (RuntimeException e) {
|
398
|
logger.warn("year could not be parsed");
|
399
|
}
|
400
|
}
|
401
|
if (config.isPublishReferences()){
|
402
|
((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
|
403
|
}
|
404
|
}
|
405
|
|
406
|
//Status
|
407
|
tcsNamespace = taxonNameNamespace;
|
408
|
Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
|
409
|
if (elAnnotation != null){
|
410
|
Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
|
411
|
if (elNomenclaturalNote != null){
|
412
|
String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
|
413
|
String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
|
414
|
String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
|
415
|
if (tdwgType.equalsIgnoreCase(type)){
|
416
|
try {
|
417
|
NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
|
418
|
//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
|
419
|
if (statusType != null){
|
420
|
nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
|
421
|
}
|
422
|
} catch (UnknownCdmTypeException e) {
|
423
|
if (! statusValue.equals("valid")){
|
424
|
logger.warn("Unknown NomenclaturalStatusType: " + statusValue);
|
425
|
}
|
426
|
}
|
427
|
}
|
428
|
}
|
429
|
}
|
430
|
|
431
|
if (nameBase instanceof NonViralName){
|
432
|
INonViralName nonViralName = nameBase;
|
433
|
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
|
434
|
|
435
|
//for names of rank genus the uninomial property should be used
|
436
|
if (strGenusPart == null){
|
437
|
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
|
438
|
}
|
439
|
nonViralName.setGenusOrUninomial(strGenusPart);
|
440
|
|
441
|
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
|
442
|
nonViralName.setGenusOrUninomial(strInfragenericEpithet);
|
443
|
|
444
|
|
445
|
|
446
|
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
|
447
|
nonViralName.setSpecificEpithet(strSpecificEpithet);
|
448
|
|
449
|
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
|
450
|
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
|
451
|
//AuthorTeams
|
452
|
//TODO
|
453
|
tcsElementName = "basionymAuthorship";
|
454
|
String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
455
|
if (basionymAuthorValue != null){
|
456
|
TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
|
457
|
basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
|
458
|
nonViralName.setBasionymAuthorship(basionymAuthor);
|
459
|
}
|
460
|
|
461
|
//TODO
|
462
|
tcsElementName = "combinationAuthorship";
|
463
|
String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
464
|
if (combinationAuthorValue != null){
|
465
|
TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
|
466
|
combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
|
467
|
nonViralName.setCombinationAuthorship(combinationAuthor);
|
468
|
}
|
469
|
|
470
|
//set the authorshipCache
|
471
|
tcsElementName = "authorship";
|
472
|
String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
473
|
String cache = nonViralName.getAuthorshipCache();
|
474
|
if ( authorValue != null){
|
475
|
//compare existing authorship cache with new one and check if it is necessary to
|
476
|
//make cache protected //TODO refinement
|
477
|
if (cache == null){
|
478
|
nonViralName.setAuthorshipCache(authorValue);
|
479
|
}else{
|
480
|
cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
|
481
|
cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
|
482
|
cache = cache.replace("\\(|\\)", "");
|
483
|
cache = cache.trim();
|
484
|
if (! cache.equals("")){
|
485
|
nonViralName.setAuthorshipCache(authorValue);
|
486
|
}
|
487
|
}
|
488
|
}
|
489
|
}
|
490
|
ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
|
491
|
|
492
|
checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
|
493
|
|
494
|
//nameId
|
495
|
//TODO
|
496
|
//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
|
497
|
//taxonNameMap.put(nameAbout, nameBase);
|
498
|
return nameBase;
|
499
|
}catch(UnknownCdmTypeException e){
|
500
|
e.printStackTrace();
|
501
|
}
|
502
|
return null;*/
|
503
|
}
|
504
|
|
505
|
protected TaxonName handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonName> taxonNameMap){
|
506
|
String idNamespace = "TaxonName";
|
507
|
Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
|
508
|
|
509
|
//create TaxonName element
|
510
|
|
511
|
|
512
|
String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace);
|
513
|
if (nameAbout == null){
|
514
|
nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace);
|
515
|
}
|
516
|
|
517
|
|
518
|
String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rankString", taxonNameNamespace, "rankString", rdfNamespace);
|
519
|
if (strRank == null){
|
520
|
strRank = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "rankString", rdfNamespace);
|
521
|
|
522
|
}
|
523
|
|
524
|
if (strRank == null){
|
525
|
strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace);
|
526
|
|
527
|
}
|
528
|
|
529
|
String strNomenclaturalCode = XmlHelp.getChildContentAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "nomenclaturalCode", rdfNamespace);
|
530
|
if (strNomenclaturalCode == null){
|
531
|
strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace);
|
532
|
|
533
|
}
|
534
|
try {
|
535
|
|
536
|
Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
|
537
|
NomenclaturalCode nomCode;
|
538
|
if (strNomenclaturalCode != null){
|
539
|
nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
|
540
|
}else{
|
541
|
nomCode = NomenclaturalCode.ICNAFP;
|
542
|
}
|
543
|
|
544
|
TaxonName nameBase = nomCode.getNewTaxonNameInstance(rank);
|
545
|
|
546
|
Set<String> omitAttributes = null;
|
547
|
//makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers);
|
548
|
|
549
|
//name
|
550
|
String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
|
551
|
nameBase.setTitleCache(strNameComplete, true);
|
552
|
|
553
|
//Reference
|
554
|
//TODO
|
555
|
String tcsElementName = "publishedIn";
|
556
|
String tcsNamespace = config.getCommonNamespaceURIString();
|
557
|
/*String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
|
558
|
if (value != null && value != ""){
|
559
|
IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
|
560
|
nomRef.setTitleCache(value, true);
|
561
|
nameBase.setNomenclaturalReference(nomRef);
|
562
|
|
563
|
//TODO
|
564
|
tcsElementName = "year";
|
565
|
tcsNamespace = taxonNameNamespace;
|
566
|
Integer year = null;
|
567
|
value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
|
568
|
if (value != null){
|
569
|
try {
|
570
|
year = Integer.valueOf(value);
|
571
|
TimePeriod timeP = TimePeriod.NewInstance(year);
|
572
|
nomRef.setDatePublished(timeP);
|
573
|
} catch (RuntimeException e) {
|
574
|
logger.warn("year could not be parsed");
|
575
|
}
|
576
|
}
|
577
|
if (config.isPublishReferences()){
|
578
|
((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
|
579
|
}
|
580
|
}
|
581
|
|
582
|
//Status
|
583
|
tcsNamespace = taxonNameNamespace;
|
584
|
Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
|
585
|
if (elAnnotation != null){
|
586
|
Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
|
587
|
if (elNomenclaturalNote != null){
|
588
|
String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
|
589
|
String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
|
590
|
String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
|
591
|
if (tdwgType.equalsIgnoreCase(type)){
|
592
|
try {
|
593
|
NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
|
594
|
//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
|
595
|
if (statusType != null){
|
596
|
nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
|
597
|
}
|
598
|
} catch (UnknownCdmTypeException e) {
|
599
|
if (! statusValue.equals("valid")){
|
600
|
logger.warn("Unknown NomenclaturalStatusType: " + statusValue);
|
601
|
}
|
602
|
}
|
603
|
}
|
604
|
}
|
605
|
}
|
606
|
|
607
|
if (nameBase instanceof NonViralName){
|
608
|
INonViralName nonViralName = nameBase;
|
609
|
String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
|
610
|
|
611
|
//for names of rank genus the uninomial property should be used
|
612
|
if (strGenusPart == null){
|
613
|
strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
|
614
|
}
|
615
|
nonViralName.setGenusOrUninomial(strGenusPart);
|
616
|
|
617
|
String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
|
618
|
nonViralName.setGenusOrUninomial(strInfragenericEpithet);
|
619
|
|
620
|
|
621
|
|
622
|
String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
|
623
|
nonViralName.setSpecificEpithet(strSpecificEpithet);
|
624
|
|
625
|
String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
|
626
|
nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
|
627
|
//AuthorTeams
|
628
|
//TODO
|
629
|
tcsElementName = "basionymAuthorship";
|
630
|
String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
631
|
if (basionymAuthorValue != null){
|
632
|
TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
|
633
|
basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
|
634
|
nonViralName.setBasionymAuthorship(basionymAuthor);
|
635
|
}
|
636
|
|
637
|
//TODO
|
638
|
tcsElementName = "combinationAuthorship";
|
639
|
String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
640
|
if (combinationAuthorValue != null){
|
641
|
TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
|
642
|
combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
|
643
|
nonViralName.setCombinationAuthorship(combinationAuthor);
|
644
|
}
|
645
|
|
646
|
//set the authorshipCache
|
647
|
tcsElementName = "authorship";
|
648
|
String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
|
649
|
String cache = nonViralName.getAuthorshipCache();
|
650
|
if ( authorValue != null){
|
651
|
//compare existing authorship cache with new one and check if it is necessary to
|
652
|
//make cache protected //TODO refinement
|
653
|
if (cache == null){
|
654
|
nonViralName.setAuthorshipCache(authorValue);
|
655
|
}else{
|
656
|
cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
|
657
|
cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
|
658
|
cache = cache.replace("\\(|\\)", "");
|
659
|
cache = cache.trim();
|
660
|
if (! cache.equals("")){
|
661
|
nonViralName.setAuthorshipCache(authorValue);
|
662
|
}
|
663
|
}
|
664
|
}
|
665
|
}
|
666
|
ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
|
667
|
|
668
|
checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
|
669
|
|
670
|
//nameId
|
671
|
//TODO
|
672
|
//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
|
673
|
//taxonNameMap.put(nameAbout, nameBase);
|
674
|
return nameBase;
|
675
|
*/}catch(UnknownCdmTypeException e){
|
676
|
e.printStackTrace();
|
677
|
}
|
678
|
return null;
|
679
|
}
|
680
|
|
681
|
public TaxonName handleRdfElementFromStream(InputStream is, TcsRdfImportConfigurator config, MapWrapper<TaxonName> taxonNameMap, String uri){
|
682
|
Model model = ModelFactory.createDefaultModel();
|
683
|
try{
|
684
|
model.read(is, null);
|
685
|
|
686
|
config.makeNamespaces(model);
|
687
|
|
688
|
String rdfNamespace = config.getRdfNamespaceURIString();
|
689
|
String taxonNameNamespace = config.getTnNamespaceURIString();
|
690
|
return handleNameModel(model, config, taxonNameMap, uri);
|
691
|
|
692
|
|
693
|
}catch(Exception e){
|
694
|
logger.debug("The file was no valid rdf file");
|
695
|
}
|
696
|
|
697
|
return null;
|
698
|
}
|
699
|
|
700
|
}
|