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