Project

General

Profile

Download (26.9 KB) Statistics
| Branch: | Tag: | Revision:
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.INonViralName;
40
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
41
import eu.etaxonomy.cdm.model.name.NonViralName;
42
import eu.etaxonomy.cdm.model.name.Rank;
43
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
44
import eu.etaxonomy.cdm.model.reference.IGeneric;
45
import eu.etaxonomy.cdm.model.reference.Reference;
46
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
47
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
48

    
49
/**
50
 * @author a.mueller
51
 * @created 29.05.2008
52
 * @version 1.0
53
 */
54
@Component
55
public class TcsRdfTaxonNameImport  extends TcsRdfImportBase implements ICdmIO<TcsRdfImportState> {
56
	private static final Logger logger = Logger.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
		//result &= checkArticlesWithoutJournal(tcsConfig);
70
		//result &= checkPartOfJournal(tcsConfig);
71

    
72
		return result;
73
	}
74

    
75
	protected static CdmSingleAttributeRDFMapperBase[] standardMappers = new CdmSingleAttributeRDFMapperBase[]{
76
		new CdmTextElementMapper("genusPart", "genusOrUninomial")
77
		, new CdmTextElementMapper("uninomial", "genusOrUninomial")  //TODO make it a more specific Mapper for both attributes
78
		, new CdmTextElementMapper("specificEpithet", "specificEpithet")
79
		, new CdmTextElementMapper("infraspecificEpithet", "infraSpecificEpithet")
80
		, new CdmTextElementMapper("infragenericEpithet", "infraGenericEpithet")
81
		, new CdmTextElementMapper("microReference", nsTcom, "nomenclaturalMicroReference")
82

    
83
	};
84

    
85
	protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
86
		new CdmUnclearMapper("basionymAuthorship")
87
		, new CdmUnclearMapper("combinationAuthorship")
88
		, new CdmUnclearMapper("hasAnnotation")
89
		, new CdmUnclearMapper("rank")
90
		, new CdmUnclearMapper("nomenclaturalCode")
91
		, new CdmUnclearMapper("publishedIn", nsTcom)
92
		, new CdmUnclearMapper("year")
93
	};
94

    
95
	protected static CdmSingleAttributeRDFMapperBase[] unclearMappers = new CdmSingleAttributeRDFMapperBase[]{
96
		new CdmUnclearMapper("authorship")
97
		, new CdmUnclearMapper("rankString")
98
		, new CdmUnclearMapper("nameComplete")
99
		, new CdmUnclearMapper("hasBasionym")
100
		, new CdmUnclearMapper("dateOfEntry", nsTpalm)
101
	};
102

    
103
	@Override
104
	protected void doInvoke(TcsRdfImportState state){
105

    
106
		MapWrapper<TaxonNameBase> taxonNameMap = (MapWrapper<TaxonNameBase>)state.getStore(ICdmIO.TAXONNAME_STORE);
107
		MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
108
		MapWrapper<TeamOrPersonBase> authorMap = (MapWrapper<TeamOrPersonBase>)state.getStore(ICdmIO.TEAM_STORE);
109

    
110
		String tcsElementName;
111
		Namespace tcsNamespace;
112
		String value;
113

    
114
		logger.info("start makeTaxonNames ...");
115
		TcsRdfImportConfigurator config = state.getConfig();
116
		Model root = config.getSourceRoot();
117

    
118
		String rdfNamespace = config.getRdfNamespaceURIString();
119
		String taxonNameNamespace = config.getTnNamespaceURIString();
120

    
121
		String idNamespace = "TaxonName";
122

    
123
		Resource elTaxonName = root.getResource(taxonNameNamespace);
124

    
125
		int i = 0;
126

    
127
		TaxonNameBase name;
128
		Property property = root.getProperty(taxonNameNamespace+"authorship");
129

    
130
		ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null);
131
		String id ;
132
		while (iterator.hasNext()){
133

    
134
			Resource resource = iterator.next();
135

    
136
			name = handleNameResource(resource, config);
137
			id = resource.getNameSpace();
138
			taxonNameMap.put(id, name);
139
		}
140

    
141
		logger.info(i + " names handled");
142
		getNameService().save(taxonNameMap.objects());
143
//		makeNameSpecificData(nameMap);
144
		logger.info("end makeTaxonNames ...");
145
		return;
146

    
147
	}
148
	/* (non-Javadoc)
149
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
150
	 */
151
	@Override
152
    protected boolean isIgnore(TcsRdfImportState state){
153
		return ! state.getConfig().isDoTaxonNames();
154
	}
155

    
156
	protected TaxonNameBase handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){
157
		Resource nameAbout = model.getResource(uri);
158
		TaxonNameBase result = handleNameResource(nameAbout, config);
159
		taxonNameMap.put(uri, result);
160
		return result;
161

    
162
	}
163

    
164
	private TaxonNameBase handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){
165
		String idNamespace = "TaxonName";
166

    
167
		StmtIterator stmts = nameAbout.listProperties();
168
		while(stmts.hasNext()){
169
			System.out.println(stmts.next().getPredicate().toString());
170
		}
171

    
172
		Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode");
173
		Statement stateNomenclaturalCode = nameAbout.getProperty(prop);
174
		String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString();
175
		//Rank
176
		prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString");
177
		String strRank = nameAbout.getProperty(prop).getString();
178

    
179

    
180

    
181
		try {
182

    
183
			Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
184
			NomenclaturalCode nomCode;
185
			if (strNomenclaturalCode != null){
186
				nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
187
			}else{
188
				nomCode = NomenclaturalCode.ICNAFP;
189
			}
190

    
191
			TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
192

    
193
			Set<String> omitAttributes = null;
194
			//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
195

    
196
			prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete");
197
			String strNameComplete = nameAbout.getProperty(prop).getString();
198
			nameBase.setTitleCache(strNameComplete, true);
199

    
200
			prop =  nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn");
201
			String strPublishedIn = nameAbout.getProperty(prop).getString();
202
			if (strPublishedIn != null && strPublishedIn != ""){
203
				IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
204
				nomRef.setTitleCache(strPublishedIn, true);
205
				nameBase.setNomenclaturalReference(nomRef);
206
				try{
207
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"year");
208
				String strYear = nameAbout.getProperty(prop).getString();
209
				Integer year = null;
210
				if (strYear != null){
211
					try {
212
						year = Integer.valueOf(strYear);
213
						TimePeriod timeP = TimePeriod.NewInstance(year);
214
						nomRef.setDatePublished(timeP);
215
					} catch (RuntimeException e) {
216
						logger.warn("year could not be parsed");
217
					}
218
				}
219
				}catch(NullPointerException e){
220
				}
221
				if (config.isPublishReferences()){
222
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
223
				}
224
			}
225

    
226
			if (nameBase instanceof NonViralName){
227
				INonViralName nonViralName = nameBase;
228
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart");
229
				String strGenusPart;
230
				try{
231
					strGenusPart = nameAbout.getProperty(prop).getString();
232
				}catch(NullPointerException e){
233
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial");
234
					strGenusPart = nameAbout.getProperty(prop).getString();
235
				}
236

    
237
				nonViralName.setGenusOrUninomial(strGenusPart);
238

    
239
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet");
240
				try{
241
					String strInfragenericEpithet = nameAbout.getProperty(prop).getString();
242
					nonViralName.setInfraGenericEpithet(strInfragenericEpithet);
243
				}catch(NullPointerException e){
244

    
245
				}
246
				try {
247
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet");
248
					String strSpecificEpithet = nameAbout.getProperty(prop).getString();
249
					nonViralName.setSpecificEpithet(strSpecificEpithet);
250
				}catch(NullPointerException e){
251

    
252
				}
253
				try{
254
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet");
255
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
256
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
257
				}catch(NullPointerException e){
258

    
259
				}
260
				//Authorships
261
				//TODO
262
				/*
263
				 * <tn:authorteam>
264
						<tm:Team>
265
							<tm:name>(Raf.) Fernald</tm:name>
266
							<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1"
267
								tm:index="1"
268
								tm:role="Combination Author"/>
269
							<tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
270
								tm:index="1"
271
								tm:role="Basionym Author"/>
272
						</tm:Team>
273
					</tn:authorteam>
274
				 */
275
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"authorship");
276
				Statement stateAuthorship = nameAbout.getProperty(prop);
277
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"authorteam");
278
				Statement stateAuthorTeam = nameAbout.getProperty(prop);
279
				Team authorTeam = new Team();
280
				authorTeam.setTitleCache(stateAuthorship.getObject().toString(), true);
281
				Statement stateAutorTeamTeam = null;
282
				Statement stateAutorTeamName = null;
283
				StmtIterator stateTeamMember = null;
284
				if (stateAuthorTeam != null){
285
					prop =  stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"Team");
286
					try{
287
						stateAutorTeamTeam = stateAuthorTeam.getProperty(prop);
288
					}catch(Exception e){
289

    
290
					}
291
					try{
292
						prop =  stateAuthorTeam.getModel().getProperty(config.getTeamNamespaceURIString()+"name");
293
						stateAutorTeamName = stateAuthorTeam.getProperty(prop);
294
					}catch(Exception e){
295

    
296
					}
297
					try{
298
						prop =  nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember");
299
						stateTeamMember = ((Resource)stateAuthorTeam.getObject()).listProperties(prop);
300
						String memberString = null;
301
						Person person;
302
						for (Statement statement :stateTeamMember.toList()){
303
							memberString =statement.getObject().toString();
304
							if (memberString != null){
305
								person = Person.NewTitledInstance(memberString);
306
								authorTeam.addTeamMember(person);
307
							}
308
						}
309
					}catch(Exception e){
310
						System.err.println(e.getMessage());
311
					}
312
				}
313

    
314

    
315

    
316
				nonViralName.setCombinationAuthorship(authorTeam);
317

    
318
				//Annotations:
319
				/*
320
				 * <tn:hasAnnotation>
321
            <tn:NomenclaturalNote>
322
                <tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/>
323
                <tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/>
324
            </tn:NomenclaturalNote>
325
        </tn:hasAnnotation>
326
				 */
327
				/*
328
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
329
				tcsElementName = "basionymAuthorship";
330
				String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
331
				if (basionymAuthorValue != null){
332
					TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
333
					basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
334
					nonViralName.setBasionymAuthorship(basionymAuthor);
335
				}
336

    
337
				//TODO
338
				tcsElementName = "combinationAuthorship";
339
				String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
340
				if (combinationAuthorValue != null){
341
					TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
342
					combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
343
					nonViralName.setCombinationAuthorship(combinationAuthor);
344
				}
345

    
346
				//set the authorshipCache
347
				tcsElementName = "authorship";
348
				String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
349
				String cache = nonViralName.getAuthorshipCache();
350
				if ( authorValue != null){
351
					//compare existing authorship cache with new one and check if it is necessary to
352
					//make cache protected  //TODO refinement
353
					if (cache == null){
354
						nonViralName.setAuthorshipCache(authorValue);
355
					}else{
356
						cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
357
						cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
358
						cache = cache.replace("\\(|\\)", "");
359
						cache = cache.trim();
360
						if (! cache.equals("")){
361
							nonViralName.setAuthorshipCache(authorValue);
362
						}
363
					}
364
				}*/
365
			}
366
			//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
367

    
368
			//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
369

    
370
			return nameBase;
371

    
372
			}catch(Exception e){
373
			e.printStackTrace();
374
			return null;
375
		}
376
			/*
377
			//name
378
			String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
379
			nameBase.setTitleCache(strNameComplete, true);
380

    
381
			//Reference
382
			//TODO
383
			String tcsElementName = "publishedIn";
384
			Namespace tcsNamespace = config.getCommonNamespaceURIString();
385
			String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
386
			if (value != null && value != ""){
387
				IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
388
				nomRef.setTitleCache(value, true);
389
				nameBase.setNomenclaturalReference(nomRef);
390

    
391
				//TODO
392
				tcsElementName = "year";
393
				tcsNamespace = taxonNameNamespace;
394
				Integer year = null;
395
				value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
396
				if (value != null){
397
					try {
398
						year = Integer.valueOf(value);
399
						TimePeriod timeP = TimePeriod.NewInstance(year);
400
						nomRef.setDatePublished(timeP);
401
					} catch (RuntimeException e) {
402
						logger.warn("year could not be parsed");
403
					}
404
				}
405
				if (config.isPublishReferences()){
406
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
407
				}
408
			}
409

    
410
			//Status
411
			tcsNamespace = taxonNameNamespace;
412
			Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
413
			if (elAnnotation != null){
414
				Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
415
				if (elNomenclaturalNote != null){
416
					String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
417
					String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
418
					String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
419
					if (tdwgType.equalsIgnoreCase(type)){
420
						try {
421
							NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
422
							//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
423
							if (statusType != null){
424
								nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
425
							}
426
						} catch (UnknownCdmTypeException e) {
427
							if (! statusValue.equals("valid")){
428
								logger.warn("Unknown NomenclaturalStatusType: " +  statusValue);
429
							}
430
						}
431
					}
432
				}
433
			}
434

    
435
			if (nameBase instanceof NonViralName){
436
				INonViralName nonViralName = nameBase;
437
				String strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
438

    
439
				//for names of rank genus the uninomial property should be used
440
				if (strGenusPart == null){
441
					strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
442
				}
443
				nonViralName.setGenusOrUninomial(strGenusPart);
444

    
445
				String strInfragenericEpithet =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
446
				nonViralName.setGenusOrUninomial(strInfragenericEpithet);
447

    
448

    
449

    
450
				String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
451
				nonViralName.setSpecificEpithet(strSpecificEpithet);
452

    
453
				String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
454
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
455
				//AuthorTeams
456
				//TODO
457
				tcsElementName = "basionymAuthorship";
458
				String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
459
				if (basionymAuthorValue != null){
460
					TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
461
					basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
462
					nonViralName.setBasionymAuthorship(basionymAuthor);
463
				}
464

    
465
				//TODO
466
				tcsElementName = "combinationAuthorship";
467
				String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
468
				if (combinationAuthorValue != null){
469
					TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
470
					combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
471
					nonViralName.setCombinationAuthorship(combinationAuthor);
472
				}
473

    
474
				//set the authorshipCache
475
				tcsElementName = "authorship";
476
				String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
477
				String cache = nonViralName.getAuthorshipCache();
478
				if ( authorValue != null){
479
					//compare existing authorship cache with new one and check if it is necessary to
480
					//make cache protected  //TODO refinement
481
					if (cache == null){
482
						nonViralName.setAuthorshipCache(authorValue);
483
					}else{
484
						cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
485
						cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
486
						cache = cache.replace("\\(|\\)", "");
487
						cache = cache.trim();
488
						if (! cache.equals("")){
489
							nonViralName.setAuthorshipCache(authorValue);
490
						}
491
					}
492
				}
493
			}
494
			ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
495

    
496
			checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
497

    
498
			//nameId
499
			//TODO
500
			//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
501
			//taxonNameMap.put(nameAbout, nameBase);
502
			return nameBase;
503
		}catch(UnknownCdmTypeException e){
504
			e.printStackTrace();
505
		}
506
		return null;*/
507
	}
508

    
509
	protected TaxonNameBase handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap){
510
		String idNamespace = "TaxonName";
511
		Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
512

    
513
		//create TaxonName element
514

    
515

    
516
		String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace);
517
		if (nameAbout == null){
518
			nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace);
519
		}
520

    
521

    
522
		String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rankString", taxonNameNamespace, "rankString", rdfNamespace);
523
		if (strRank == null){
524
			strRank = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "rankString", rdfNamespace);
525

    
526
		}
527

    
528
		if (strRank == null){
529
			strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace);
530

    
531
		}
532

    
533
		String strNomenclaturalCode = XmlHelp.getChildContentAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "nomenclaturalCode", rdfNamespace);
534
		if (strNomenclaturalCode == null){
535
			strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace);
536

    
537
		}
538
		try {
539

    
540
			Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
541
			NomenclaturalCode nomCode;
542
			if (strNomenclaturalCode != null){
543
				nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
544
			}else{
545
				nomCode = NomenclaturalCode.ICNAFP;
546
			}
547

    
548
			TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
549

    
550
			Set<String> omitAttributes = null;
551
			//makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers);
552

    
553
			//name
554
			String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
555
			nameBase.setTitleCache(strNameComplete, true);
556

    
557
			//Reference
558
			//TODO
559
			String tcsElementName = "publishedIn";
560
			String tcsNamespace = config.getCommonNamespaceURIString();
561
			/*String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
562
			if (value != null && value != ""){
563
				IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
564
				nomRef.setTitleCache(value, true);
565
				nameBase.setNomenclaturalReference(nomRef);
566

    
567
				//TODO
568
				tcsElementName = "year";
569
				tcsNamespace = taxonNameNamespace;
570
				Integer year = null;
571
				value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
572
				if (value != null){
573
					try {
574
						year = Integer.valueOf(value);
575
						TimePeriod timeP = TimePeriod.NewInstance(year);
576
						nomRef.setDatePublished(timeP);
577
					} catch (RuntimeException e) {
578
						logger.warn("year could not be parsed");
579
					}
580
				}
581
				if (config.isPublishReferences()){
582
					((Reference)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
583
				}
584
			}
585

    
586
			//Status
587
			tcsNamespace = taxonNameNamespace;
588
			Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
589
			if (elAnnotation != null){
590
				Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
591
				if (elNomenclaturalNote != null){
592
					String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
593
					String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
594
					String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
595
					if (tdwgType.equalsIgnoreCase(type)){
596
						try {
597
							NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
598
							//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
599
							if (statusType != null){
600
								nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
601
							}
602
						} catch (UnknownCdmTypeException e) {
603
							if (! statusValue.equals("valid")){
604
								logger.warn("Unknown NomenclaturalStatusType: " +  statusValue);
605
							}
606
						}
607
					}
608
				}
609
			}
610

    
611
			if (nameBase instanceof NonViralName){
612
				INonViralName nonViralName = nameBase;
613
				String strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
614

    
615
				//for names of rank genus the uninomial property should be used
616
				if (strGenusPart == null){
617
					strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
618
				}
619
				nonViralName.setGenusOrUninomial(strGenusPart);
620

    
621
				String strInfragenericEpithet =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
622
				nonViralName.setGenusOrUninomial(strInfragenericEpithet);
623

    
624

    
625

    
626
				String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
627
				nonViralName.setSpecificEpithet(strSpecificEpithet);
628

    
629
				String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
630
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
631
				//AuthorTeams
632
				//TODO
633
				tcsElementName = "basionymAuthorship";
634
				String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
635
				if (basionymAuthorValue != null){
636
					TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
637
					basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
638
					nonViralName.setBasionymAuthorship(basionymAuthor);
639
				}
640

    
641
				//TODO
642
				tcsElementName = "combinationAuthorship";
643
				String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
644
				if (combinationAuthorValue != null){
645
					TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
646
					combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
647
					nonViralName.setCombinationAuthorship(combinationAuthor);
648
				}
649

    
650
				//set the authorshipCache
651
				tcsElementName = "authorship";
652
				String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
653
				String cache = nonViralName.getAuthorshipCache();
654
				if ( authorValue != null){
655
					//compare existing authorship cache with new one and check if it is necessary to
656
					//make cache protected  //TODO refinement
657
					if (cache == null){
658
						nonViralName.setAuthorshipCache(authorValue);
659
					}else{
660
						cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
661
						cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
662
						cache = cache.replace("\\(|\\)", "");
663
						cache = cache.trim();
664
						if (! cache.equals("")){
665
							nonViralName.setAuthorshipCache(authorValue);
666
						}
667
					}
668
				}
669
			}
670
			ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
671

    
672
			checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
673

    
674
			//nameId
675
			//TODO
676
			//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
677
			//taxonNameMap.put(nameAbout, nameBase);
678
			return nameBase;
679
		*/}catch(UnknownCdmTypeException e){
680
			e.printStackTrace();
681
		}
682
		return null;
683
	}
684

    
685
	public TaxonNameBase handleRdfElementFromStream(InputStream is, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){
686
	Model model = ModelFactory.createDefaultModel();
687
		try{
688
			model.read(is, null);
689

    
690
			config.makeNamespaces(model);
691

    
692
			String rdfNamespace = config.getRdfNamespaceURIString();
693
			String taxonNameNamespace = config.getTnNamespaceURIString();
694
			return handleNameModel(model, config, taxonNameMap, uri);
695

    
696

    
697
		}catch(Exception e){
698
			logger.debug("The file was no valid rdf file");
699
		}
700

    
701

    
702

    
703
		return null;
704
	}
705

    
706
}
(10-10/13)