2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.tcsrdf
;
12 import java
.io
.IOException
;
13 import java
.io
.InputStream
;
14 import java
.util
.List
;
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
;
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
;
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
;
59 public class TcsRdfTaxonNameImport
extends TcsRdfImportBase
implements ICdmIO
<TcsRdfImportState
> {
60 private static final Logger logger
= Logger
.getLogger(TcsRdfTaxonNameImport
.class);
62 private static int modCount
= 5000;
64 public TcsRdfTaxonNameImport(){
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);
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")
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")
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
)
108 protected void doInvoke(TcsRdfImportState state
){
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
);
114 String tcsElementName
;
115 Namespace tcsNamespace
;
118 logger
.info("start makeTaxonNames ...");
119 TcsRdfImportConfigurator config
= state
.getConfig();
120 Model root
= config
.getSourceRoot();
122 String rdfNamespace
= config
.getRdfNamespaceURIString();
123 String taxonNameNamespace
= config
.getTnNamespaceURIString();
125 String idNamespace
= "TaxonName";
127 Resource elTaxonName
= root
.getResource(taxonNameNamespace
);
132 Property property
= root
.getProperty(taxonNameNamespace
+"authorship");
134 ResIterator iterator
= root
.listSubjectsWithProperty(property
, (RDFNode
) null);
136 while (iterator
.hasNext()){
138 Resource resource
= iterator
.next();
140 name
= handleNameResource(resource
, config
);
141 id
= resource
.getNameSpace();
142 taxonNameMap
.put(id
, name
);
145 logger
.info(i
+ " names handled");
146 getNameService().save(taxonNameMap
.objects());
147 // makeNameSpecificData(nameMap);
148 logger
.info("end makeTaxonNames ...");
153 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
156 protected boolean isIgnore(TcsRdfImportState state
){
157 return ! state
.getConfig().isDoTaxonNames();
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
);
168 private TaxonNameBase
handleNameResource(Resource nameAbout
, TcsRdfImportConfigurator config
){
169 String idNamespace
= "TaxonName";
171 StmtIterator stmts
= nameAbout
.listProperties();
172 while(stmts
.hasNext()){
173 System
.out
.println(stmts
.next().getPredicate().toString());
176 Property prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"nomenclaturalCode");
177 Statement stateNomenclaturalCode
= nameAbout
.getProperty(prop
);
178 String strNomenclaturalCode
= stateNomenclaturalCode
.getObject().toString();
180 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"rankString");
181 String strRank
= nameAbout
.getProperty(prop
).getString();
187 Rank rank
= TcsRdfTransformer
.rankString2Rank(strRank
);
188 NomenclaturalCode nomCode
;
189 if (strNomenclaturalCode
!= null){
190 nomCode
= TcsRdfTransformer
.nomCodeString2NomCode(strNomenclaturalCode
);
192 nomCode
= NomenclaturalCode
.ICNAFP
;
195 TaxonNameBase
<?
,?
> nameBase
= nomCode
.getNewTaxonNameInstance(rank
);
197 Set
<String
> omitAttributes
= null;
198 //makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
200 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"nameComplete");
201 String strNameComplete
= nameAbout
.getProperty(prop
).getString();
202 nameBase
.setTitleCache(strNameComplete
, true);
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
);
211 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"year");
212 String strYear
= nameAbout
.getProperty(prop
).getString();
214 if (strYear
!= null){
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");
223 }catch(NullPointerException e
){
225 if (config
.isPublishReferences()){
226 ((Reference
<?
>)nomRef
).addMarker(Marker
.NewInstance(MarkerType
.PUBLISH(), false));
230 if (nameBase
instanceof NonViralName
){
231 NonViralName
<?
> nonViralName
= (NonViralName
<?
>)nameBase
;
232 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"genusPart");
235 strGenusPart
= nameAbout
.getProperty(prop
).getString();
236 }catch(NullPointerException e
){
237 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"uninomial");
238 strGenusPart
= nameAbout
.getProperty(prop
).getString();
241 nonViralName
.setGenusOrUninomial(strGenusPart
);
243 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"infragenericEpithet");
245 String strInfragenericEpithet
= nameAbout
.getProperty(prop
).getString();
246 nonViralName
.setInfraGenericEpithet(strInfragenericEpithet
);
247 }catch(NullPointerException e
){
251 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"specificEpithet");
252 String strSpecificEpithet
= nameAbout
.getProperty(prop
).getString();
253 nonViralName
.setSpecificEpithet(strSpecificEpithet
);
254 }catch(NullPointerException e
){
258 prop
= nameAbout
.getModel().getProperty(config
.getTnNamespaceURIString()+"infraspecificEpithet");
259 String strInfraspecificEpithet
= nameAbout
.getProperty(prop
).getString();
260 nonViralName
.setInfraSpecificEpithet(strInfraspecificEpithet
);
261 }catch(NullPointerException e
){
269 <tm:name>(Raf.) Fernald</tm:name>
270 <tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:2691-1"
272 tm:role="Combination Author"/>
273 <tm:hasMember rdf:resource="urn:lsid:ipni.org:authors:8096-1"
275 tm:role="Basionym Author"/>
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");
291 stateAutorTeamTeam
= stateAuthorTeam
.getProperty(prop
);
296 prop
= stateAuthorTeam
.getModel().getProperty(config
.getTeamNamespaceURIString()+"name");
297 stateAutorTeamName
= stateAuthorTeam
.getProperty(prop
);
302 prop
= nameAbout
.getModel().getProperty(config
.getTeamNamespaceURIString()+"hasMember");
303 stateTeamMember
= ((Resource
)stateAuthorTeam
.getObject()).listProperties(prop
);
304 String memberString
= null;
306 for (Statement statement
:stateTeamMember
.toList()){
307 memberString
=statement
.getObject().toString();
308 if (memberString
!= null){
309 person
= Person
.NewTitledInstance(memberString
);
310 authorTeam
.addTeamMember(person
);
314 System
.err
.println(e
.getMessage());
320 nonViralName
.setCombinationAuthorTeam(authorTeam
);
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>
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);
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);
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
358 nonViralName.setAuthorshipCache(authorValue);
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);
370 //ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
372 //checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
382 String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
383 nameBase.setTitleCache(strNameComplete, true);
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);
396 tcsElementName = "year";
397 tcsNamespace = taxonNameNamespace;
399 value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
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");
409 if (config.isPublishReferences()){
410 ((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
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)){
425 NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
426 //NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
427 if (statusType != null){
428 nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
430 } catch (UnknownCdmTypeException e) {
431 if (! statusValue.equals("valid")){
432 logger.warn("Unknown NomenclaturalStatusType: " + statusValue);
439 if (nameBase instanceof NonViralName){
440 NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
441 String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
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);
447 nonViralName.setGenusOrUninomial(strGenusPart);
449 String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
450 nonViralName.setGenusOrUninomial(strInfragenericEpithet);
454 String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
455 nonViralName.setSpecificEpithet(strSpecificEpithet);
457 String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
458 nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
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);
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);
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
486 nonViralName.setAuthorshipCache(authorValue);
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);
498 ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
500 checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
504 //ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
505 //taxonNameMap.put(nameAbout, nameBase);
507 }catch(UnknownCdmTypeException e){
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
);
517 //create TaxonName element
520 String nameAbout
= elTaxonName
.getAttributeValue("about", rdfNamespace
);
521 if (nameAbout
== null){
522 nameAbout
= XmlHelp
.getChildAttributeValue(elTaxonName
, "TaxonName", taxonNameNamespace
, "about", rdfNamespace
);
526 String strRank
= XmlHelp
.getChildAttributeValue(elTaxonName
, "rankString", taxonNameNamespace
, "rankString", rdfNamespace
);
527 if (strRank
== null){
528 strRank
= XmlHelp
.getChildContent(elTaxonName
, "TaxonName", taxonNameNamespace
, "rankString", rdfNamespace
);
532 if (strRank
== null){
533 strRank
= XmlHelp
.getChildAttributeValue(elTaxonName
, "rank", taxonNameNamespace
, "resource", rdfNamespace
);
537 String strNomenclaturalCode
= XmlHelp
.getChildContentAttributeValue(elTaxonName
, "TaxonName", taxonNameNamespace
, "nomenclaturalCode", rdfNamespace
);
538 if (strNomenclaturalCode
== null){
539 strNomenclaturalCode
= XmlHelp
.getChildAttributeValue(elTaxonName
, "nomenclaturalCode", taxonNameNamespace
, "resource", rdfNamespace
);
544 Rank rank
= TcsRdfTransformer
.rankString2Rank(strRank
);
545 NomenclaturalCode nomCode
;
546 if (strNomenclaturalCode
!= null){
547 nomCode
= TcsRdfTransformer
.nomCodeString2NomCode(strNomenclaturalCode
);
549 nomCode
= NomenclaturalCode
.ICNAFP
;
552 TaxonNameBase
<?
,?
> nameBase
= nomCode
.getNewTaxonNameInstance(rank
);
554 Set
<String
> omitAttributes
= null;
555 //makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers);
558 String strNameComplete
= XmlHelp
.getChildContent(elTaxonName
, "TaxonName", taxonNameNamespace
, "nameComplete", rdfNamespace
);
559 nameBase
.setTitleCache(strNameComplete
, true);
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);
572 tcsElementName = "year";
573 tcsNamespace = taxonNameNamespace;
575 value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
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");
585 if (config.isPublishReferences()){
586 ((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
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)){
601 NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
602 //NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
603 if (statusType != null){
604 nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
606 } catch (UnknownCdmTypeException e) {
607 if (! statusValue.equals("valid")){
608 logger.warn("Unknown NomenclaturalStatusType: " + statusValue);
615 if (nameBase instanceof NonViralName){
616 NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
617 String strGenusPart = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
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);
623 nonViralName.setGenusOrUninomial(strGenusPart);
625 String strInfragenericEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
626 nonViralName.setGenusOrUninomial(strInfragenericEpithet);
630 String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
631 nonViralName.setSpecificEpithet(strSpecificEpithet);
633 String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
634 nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
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);
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);
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
662 nonViralName.setAuthorshipCache(authorValue);
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);
674 ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
676 checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
680 //ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
681 //taxonNameMap.put(nameAbout, nameBase);
683 */}catch(UnknownCdmTypeException e
){
689 public TaxonNameBase
handleRdfElementFromStream(InputStream is
, TcsRdfImportConfigurator config
, MapWrapper
<TaxonNameBase
> taxonNameMap
, String uri
){
690 Model model
= ModelFactory
.createDefaultModel();
692 model
.read(is
, null);
694 config
.makeNamespaces(model
);
696 String rdfNamespace
= config
.getRdfNamespaceURIString();
697 String taxonNameNamespace
= config
.getTnNamespaceURIString();
698 return handleNameModel(model
, config
, taxonNameMap
, uri
);
702 logger
.debug("The file was no valid rdf file");