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