Project

General

Profile

Download (16.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.tcsxml;
11

    
12
import org.apache.log4j.Logger;
13

    
14
import eu.etaxonomy.cdm.common.ResultWrapper;
15
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
16
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
18
import eu.etaxonomy.cdm.model.name.Rank;
19
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
20
/*import eu.etaxonomy.cdm.model.reference.Article;
21
import eu.etaxonomy.cdm.model.reference.Book;
22
import eu.etaxonomy.cdm.model.reference.BookSection;
23
import eu.etaxonomy.cdm.model.reference.Journal;
24
import eu.etaxonomy.cdm.model.reference.PersonalCommunication;
25
import eu.etaxonomy.cdm.model.reference.PrintSeries;*/
26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
28
//import eu.etaxonomy.cdm.model.reference.WebPage;
29
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
30
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
31
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
32

    
33
public final class TcsXmlTransformer {
34
	@SuppressWarnings("unused")
35
	private static final Logger logger = Logger.getLogger(TcsXmlTransformer.class);
36
 
37

    
38
	//TypeDesignation
39
	public static SpecimenTypeDesignationStatus typeStatusId2TypeStatus (int typeStatusId)  throws UnknownCdmTypeException{
40
		switch (typeStatusId){
41
			case 1: return SpecimenTypeDesignationStatus.HOLOTYPE();
42
			case 2: return SpecimenTypeDesignationStatus.LECTOTYPE();
43
			case 3: return SpecimenTypeDesignationStatus.NEOTYPE();
44
			case 4: return SpecimenTypeDesignationStatus.EPITYPE();
45
			case 5: return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
46
			case 6: return SpecimenTypeDesignationStatus.ISONEOTYPE();
47
			case 7: return SpecimenTypeDesignationStatus.ISOTYPE();
48
			case 8: return SpecimenTypeDesignationStatus.PARANEOTYPE();
49
			case 9: return SpecimenTypeDesignationStatus.PARATYPE();
50
			case 10: return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
51
			case 11: return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
52
			case 12: return SpecimenTypeDesignationStatus.SYNTYPE();
53
			case 21: return SpecimenTypeDesignationStatus.ICONOTYPE();
54
			case 22: return SpecimenTypeDesignationStatus.PHOTOTYPE();
55
			default: {
56
				throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(typeStatusId).toString() + ")");
57
			}
58
		}
59
	}
60
	
61
	
62
	
63
	
64
	/** Creates an cdm-Rank by the tcs rank
65
	 */
66
	public static Rank rankCode2Rank (String strRank) throws UnknownCdmTypeException{
67
		if (strRank == null){return null;
68
		//genus group
69
		}else if (strRank.equals("infragen")){return Rank.INFRAGENUS();
70
		}else if (strRank.equals("subgen")){return Rank.SUBGENUS();
71
		}else if (strRank.equals("gen")){return Rank.GENUS();
72
		//genus subdivision
73
		//TODO 
74
		}else if (strRank.equals("aggr")){return Rank.SPECIESAGGREGATE();
75
		}else if (strRank.equals("taxinfragen")){return Rank.INFRAGENERICTAXON();
76
		}else if (strRank.equals("subser")){return Rank.SUBSERIES();
77
		}else if (strRank.equals("ser")){return Rank.SERIES();
78
		}else if (strRank.equals("subsect")){return Rank.SUBSECTION_BOTANY();
79
		}else if (strRank.equals("sect")){return Rank.SECTION_BOTANY();
80
		//species group
81
		}else if (strRank.equals("subsp_aggr")){return Rank.SUBSPECIFICAGGREGATE();
82
		}else if (strRank.equals("ssp")){return Rank.SUBSPECIES();
83
		}else if (strRank.equals("sp")){return Rank.SPECIES();
84
		//below subspecies
85
		}else if (strRank.equals("cand")){return Rank.CANDIDATE();
86
		}else if (strRank.equals("taxinfrasp")){return Rank.INFRASPECIFICTAXON();
87
		}else if (strRank.equals("fsp")){return Rank.SPECIALFORM();
88
		}else if (strRank.equals("subsubfm")){return Rank.SUBSUBFORM();
89
		}else if (strRank.equals("subfm")){return Rank.SUBFORM();
90
		}else if (strRank.equals("fm")){return Rank.FORM();
91
		}else if (strRank.equals("subsubvar")){return Rank.SUBSUBVARIETY();
92
		}else if (strRank.equals("subvar")){return Rank.SUBVARIETY();
93
		}else if (strRank.equals("var")){return Rank.VARIETY();
94
		//TODO -> see documentation, Bacteria status
95
//		}else if (strRank.equals("pv")){return Rank;
96
//		}else if (strRank.equals("bv")){return Rank.;
97
		}else if (strRank.equals("infrasp")){return Rank.INFRASPECIES();
98
		//above superfamily
99
		}else if (strRank.equals("infraord")){return Rank.INFRAORDER();
100
		}else if (strRank.equals("ord")){return Rank.ORDER();
101
		}else if (strRank.equals("superord")){return Rank.SUPERORDER();
102
		}else if (strRank.equals("infracl")){return Rank.INFRACLASS();
103
		}else if (strRank.equals("subcl")){return Rank.SUBCLASS();
104
		}else if (strRank.equals("cl")){return Rank.CLASS();
105
		}else if (strRank.equals("supercl")){return Rank.SUPERCLASS();
106
		}else if (strRank.equals("infraphyl_div")){return Rank.INFRAPHYLUM();
107
		}else if (strRank.equals("subphyl_div")){return Rank.SUBPHYLUM();
108
		}else if (strRank.equals("phyl_div")){return Rank.PHYLUM();
109
		}else if (strRank.equals("superphyl_div")){return Rank.SUPERPHYLUM();
110
		}else if (strRank.equals("infrareg")){return Rank.INFRAKINGDOM();
111
		}else if (strRank.equals("subreg")){return Rank.SUBKINGDOM();
112
		}else if (strRank.equals("reg")){return Rank.KINGDOM();
113
		}else if (strRank.equals("superreg")){return Rank.SUPERKINGDOM();
114
		}else if (strRank.equals("dom")){return Rank.DOMAIN();
115
		}else if (strRank.equals("taxsupragen")){return Rank.SUPRAGENERICTAXON();
116
		//family group
117
		}else if (strRank.equals("infrafam")){return Rank.FAMILY();
118
		}else if (strRank.equals("subfam")){return Rank.FAMILY();
119
		}else if (strRank.equals("fam")){return Rank.FAMILY();
120
		}else if (strRank.equals("superfam")){return Rank.FAMILY();
121
		//family subdivision
122
		}else if (strRank.equals("intratrib")){return Rank.FAMILY();
123
		}else if (strRank.equals("subtrib")){return Rank.FAMILY();
124
		}else if (strRank.equals("trib")){return Rank.FAMILY();
125
		}else if (strRank.equals("supertrib")){return Rank.FAMILY();
126
		}	
127
		else {
128
			throw new UnknownCdmTypeException("Unknown Rank " + strRank);
129
		}
130
	}
131
	
132
	/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
133
	 */
134
	public static NomenclaturalCode nomCodeString2NomCode (String nomCode) throws UnknownCdmTypeException{
135
		if (nomCode != null){
136
			nomCode = nomCode.trim();
137
		}
138
		if (nomCode == null){ return null;
139
		}else if (nomCode.equals("Botanical")){return NomenclaturalCode.ICNAFP;
140
		}else if (nomCode.equals("Zoological")){return NomenclaturalCode.ICZN;
141
		}else if (nomCode.equals("Viral")){return NomenclaturalCode.ICVCN;
142
		}else if (nomCode.equals("Bacteriological")){return NomenclaturalCode.ICNB;
143
		}else if (nomCode.equals("CultivatedPlant")){return NomenclaturalCode.ICNCP;
144
		//TODO code Indeterminate
145
//		}else if (nomCode.equals("Indeterminate")){return NomenclaturalCode.XXX();
146
		}	
147
		else {
148
			throw new UnknownCdmTypeException("Unknown Nomenclatural Code " + nomCode);
149
		}
150
	}
151
	
152
	public static boolean isReverseRelationshipCategory (String tcsRelationshipCategory){
153
		String str = tcsRelationshipCategory.replace("http://rs.tdwg.org/ontology/voc/TaxonConcept#", "");
154
		if ("HasSynonym".equalsIgnoreCase(str) 
155
				|| "IsParentTaxonOf".equalsIgnoreCase(str) 
156
				|| "IsIncludedIn".equalsIgnoreCase(str) 
157
				|| "DoesNotInclude".equalsIgnoreCase(str) 
158
									){
159
			
160
			return true;
161
		}
162
		return false;
163
	}
164
	
165
	/** Creates an cdm-Rank by the tcs rank
166
	 */
167
	public static Reference<?> pubTypeStr2PubType (String strPubType) throws UnknownCdmTypeException{
168
		String tcsRoot = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
169
		String tcsBook = tcsRoot + "Book";
170
		String tcsJournal = tcsRoot + "Journal";
171
		String tcsWebPage = tcsRoot + "WebPage";
172
		String tcsCommunication = tcsRoot + "Communication";
173
		String tcsBookSeries = tcsRoot + "BookSeries";
174
		String tcsArticle = tcsRoot + "JournalArticle";
175
		String tcsBookSection = tcsRoot + "BookSection";
176
		
177
		
178
//		Artwork	An Artwork type publication.
179
//		AudiovisualMaterial	A Audiovisual Material type publication.
180
//		BookSeries	A Book Series type publication.
181
//		Commentary	A Commentary type publication.
182
//		Communication	A Communication type publication.
183
//		ComputerProgram	A Computer Program type publication.
184
//		ConferenceProceedings	A Conference Proceedings type publication.
185
//		Determination	A Determination type publication.
186
//		EditedBook	A Edited Book type publication.
187
//		Generic	A generic publication.
188
//		Journal	A Journal type publication.
189
//		MagazineArticle	A Magazine Article type publication.
190
//		Map	A Map type publication.
191
//		NewspaperArticle	A Newspaper Article type publication.
192
//		Patent	A Patent type publication.
193
//		Report	A Report type publication.
194
//		SubReference	A Sub-Reference type publication.
195
//		Thesis	A Thesis type publication.
196

    
197
		if (strPubType == null){return null;
198
		}else if (tcsBookSection.equals(strPubType)){return ReferenceFactory.newBookSection();
199
		}else if (tcsBook.equals(strPubType)){return ReferenceFactory.newBook();
200
		}else if (tcsArticle.equals(strPubType)){return ReferenceFactory.newArticle();
201
		}else if (tcsJournal.equals(strPubType)){return ReferenceFactory.newJournal();
202
		}else if (tcsWebPage.equals(strPubType)){return ReferenceFactory.newWebPage();
203
		}else if (tcsCommunication.equals(strPubType)){return ReferenceFactory.newPersonalCommunication();
204
		}else if (tcsBookSeries.equals(strPubType)){return ReferenceFactory.newPrintSeries();
205
		}	
206
		else {
207
			throw new UnknownCdmTypeException("Unknown publication type " + strPubType);
208
		}
209
	}
210
	
211
	/** Creates an cdm-RelationshipTermBase by the tcsRelationshipCategory
212
	 */
213
	public static RelationshipTermBase<?> tcsRelationshipType2Relationship (String tcsRelationshipType, ResultWrapper<Boolean> inverse) throws UnknownCdmTypeException{
214
		if (tcsRelationshipType == null){ return null;
215
		
216
		//Synonym relationships
217
//		}else if (tcsRelationshipType.equals("is synonym for")){return SynonymRelationshipType.SYNONYM_OF(); 
218
		}else if (tcsRelationshipType.equals("has synonym")){inverse.setValue(true); return SynonymRelationshipType.SYNONYM_OF(); 
219
		
220
		//Taxon relationships
221
		}else if (tcsRelationshipType.equals("is child taxon of")){return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(); 
222
		}else if (tcsRelationshipType.equals("is parent taxon of")){inverse.setValue(true);  return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(); 
223
		
224
		//concept relationships
225
		}else if (tcsRelationshipType.equals("does not overlap")){return TaxonRelationshipType.DOES_NOT_OVERLAP(); 
226
		}else if (tcsRelationshipType.equals("excludes")){return TaxonRelationshipType.EXCLUDES(); 
227
		}else if (tcsRelationshipType.equals("includes")){return TaxonRelationshipType.INCLUDES(); 
228
		}else if (tcsRelationshipType.equals("is congruent to")){return TaxonRelationshipType.CONGRUENT_TO(); 
229
		}else if (tcsRelationshipType.equals("is not congruent to")){return TaxonRelationshipType.NOT_CONGRUENT_TO(); 
230
		}else if (tcsRelationshipType.equals("is not included in")){return TaxonRelationshipType.NOT_INCLUDED_IN(); 
231
		}else if (tcsRelationshipType.equals("overlaps")){return TaxonRelationshipType.OVERLAPS(); 
232
		//reverse concept relationships
233
		}else if (tcsRelationshipType.equals("is included in")){inverse.setValue(true); return TaxonRelationshipType.INCLUDES();
234
		}else if (tcsRelationshipType.equals("does not include")){inverse.setValue(true); return TaxonRelationshipType.NOT_INCLUDED_IN(); 
235
		
236
	//TODO
237
		
238
//		}else if (tcsRelationshipType.equals("has vernacular")){return TaxonRelationshipType.X; 
239
//		}else if (tcsRelationshipType.equals("is vernacular for")){return TaxonRelationshipType.X; 
240
//		}else if (tcsRelationshipType.equals("is ambiregnal of")){return TaxonRelationshipType.X; 
241
//		}else if (tcsRelationshipType.equals("is hybrid child of")){return TaxonRelationshipType.X; 
242
//		}else if (tcsRelationshipType.equals("is hybrid parent of")){return TaxonRelationshipType.X; 
243
//		}else if (tcsRelationshipType.equals("is male parent of")){return TaxonRelationshipType.X; 
244
//		}else if (tcsRelationshipType.equals("is first parent of")){return TaxonRelationshipType.X; 
245
//		}else if (tcsRelationshipType.equals("is female parent of")){return TaxonRelationshipType.X; 
246
//		}else if (tcsRelationshipType.equals("is second parent of")){return TaxonRelationshipType.X; 
247
//		}else if (tcsRelationshipType.equals("is teleomorph of")){return TaxonRelationshipType.X; 
248
//		}else if (tcsRelationshipType.equals("is anamorph of")){return TaxonRelationshipType.X; 
249
		
250
		}else {
251
			throw new UnknownCdmTypeException("Unknown RelationshipCategory " + tcsRelationshipType);
252
		}
253
	}
254
	
255
	
256
	/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
257
	 */
258
	public static NomenclaturalStatusType nomStatusString2NomStatus (String nomStatus) throws UnknownCdmTypeException{
259
	
260
		if (nomStatus == null){ return null;
261
		}else if ("Valid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.VALID();
262
		
263
		}else if ("Alternative".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
264
		}else if ("nom. altern.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
265
		
266
		}else if ("Ambiguous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.AMBIGUOUS();
267
		
268
		}else if ("Doubtful".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.DOUBTFUL();
269
		
270
		}else if ("Confusum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONFUSUM();
271
		
272
		}else if ("Illegitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
273
		}else if ("nom. illeg.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
274
		
275
		}else if ("Superfluous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
276
		}else if ("nom. superfl.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
277
		
278
		}else if ("Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
279
		}else if ("nom. rej.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
280
		
281
		}else if ("Utique Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED();
282
		
283
		}else if ("Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED_PROP();
284
		
285
		}else if ("Orthography Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP();
286
		
287
		}else if ("Legitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.LEGITIMATE();
288
		
289
		}else if ("Novum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
290
		}else if ("nom. nov.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
291
		
292
		}else if ("Utique Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED_PROP();
293
		
294
		}else if ("Orthography Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED();
295
		
296
		}else if ("Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED_PROP();
297
		
298
		}else if ("Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
299
		}else if ("nom. cons.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
300
		
301
		}else if ("Sanctioned".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SANCTIONED();
302
		
303
		}else if ("Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
304
		}else if ("nom. inval.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
305
		
306
		}else if ("Nudum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
307
		}else if ("nom. nud.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
308
		
309
		}else if ("Combination Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.COMBINATION_INVALID();
310
		
311
		}else if ("Provisional".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
312
		}else if ("nom. provis.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
313
		}
314
		else {
315
			throw new UnknownCdmTypeException("Unknown Nomenclatural status type " + nomStatus);
316
		}
317
	}
318
	
319
	
320
}
(3-3/3)