1
|
package eu.etaxonomy.cdm.io.tcsxml;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
|
5
|
import eu.etaxonomy.cdm.common.ResultWrapper;
|
6
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
7
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
8
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
9
|
import eu.etaxonomy.cdm.model.name.Rank;
|
10
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
11
|
import eu.etaxonomy.cdm.model.reference.Article;
|
12
|
import eu.etaxonomy.cdm.model.reference.Book;
|
13
|
import eu.etaxonomy.cdm.model.reference.BookSection;
|
14
|
import eu.etaxonomy.cdm.model.reference.Journal;
|
15
|
import eu.etaxonomy.cdm.model.reference.PersonalCommunication;
|
16
|
import eu.etaxonomy.cdm.model.reference.PrintSeries;
|
17
|
import eu.etaxonomy.cdm.model.reference.StrictReferenceBase;
|
18
|
import eu.etaxonomy.cdm.model.reference.WebPage;
|
19
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
21
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
22
|
|
23
|
public final class TcsXmlTransformer {
|
24
|
@SuppressWarnings("unused")
|
25
|
private static final Logger logger = Logger.getLogger(TcsXmlTransformer.class);
|
26
|
|
27
|
|
28
|
//TypeDesignation
|
29
|
public static SpecimenTypeDesignationStatus typeStatusId2TypeStatus (int typeStatusId) throws UnknownCdmTypeException{
|
30
|
switch (typeStatusId){
|
31
|
case 1: return SpecimenTypeDesignationStatus.HOLOTYPE();
|
32
|
case 2: return SpecimenTypeDesignationStatus.LECTOTYPE();
|
33
|
case 3: return SpecimenTypeDesignationStatus.NEOTYPE();
|
34
|
case 4: return SpecimenTypeDesignationStatus.EPITYPE();
|
35
|
case 5: return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
|
36
|
case 6: return SpecimenTypeDesignationStatus.ISONEOTYPE();
|
37
|
case 7: return SpecimenTypeDesignationStatus.ISOTYPE();
|
38
|
case 8: return SpecimenTypeDesignationStatus.PARANEOTYPE();
|
39
|
case 9: return SpecimenTypeDesignationStatus.PARATYPE();
|
40
|
case 10: return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
|
41
|
case 11: return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
|
42
|
case 12: return SpecimenTypeDesignationStatus.SYNTYPE();
|
43
|
case 21: return SpecimenTypeDesignationStatus.ICONOTYPE();
|
44
|
case 22: return SpecimenTypeDesignationStatus.PHOTOTYPE();
|
45
|
default: {
|
46
|
throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(typeStatusId).toString() + ")");
|
47
|
}
|
48
|
}
|
49
|
}
|
50
|
|
51
|
|
52
|
|
53
|
|
54
|
/** Creates an cdm-Rank by the tcs rank
|
55
|
*/
|
56
|
public static Rank rankCode2Rank (String strRank) throws UnknownCdmTypeException{
|
57
|
if (strRank == null){return null;
|
58
|
//genus group
|
59
|
}else if (strRank.equals("infragen")){return Rank.INFRAGENUS();
|
60
|
}else if (strRank.equals("subgen")){return Rank.SUBGENUS();
|
61
|
}else if (strRank.equals("gen")){return Rank.GENUS();
|
62
|
//genus subdivision
|
63
|
//TODO
|
64
|
}else if (strRank.equals("aggr")){return Rank.SPECIESAGGREGATE();
|
65
|
}else if (strRank.equals("taxinfragen")){return Rank.INFRAGENERICTAXON();
|
66
|
}else if (strRank.equals("subser")){return Rank.SUBSERIES();
|
67
|
}else if (strRank.equals("ser")){return Rank.SERIES();
|
68
|
}else if (strRank.equals("subsect")){return Rank.SUBSECTION();
|
69
|
}else if (strRank.equals("sect")){return Rank.SECTION();
|
70
|
//species group
|
71
|
}else if (strRank.equals("subsp_aggr")){return Rank.SUBSPECIFICAGGREGATE();
|
72
|
}else if (strRank.equals("ssp")){return Rank.SUBSPECIES();
|
73
|
}else if (strRank.equals("sp")){return Rank.SPECIES();
|
74
|
//below subspecies
|
75
|
}else if (strRank.equals("cand")){return Rank.CANDIDATE();
|
76
|
}else if (strRank.equals("taxinfrasp")){return Rank.INFRASPECIFICTAXON();
|
77
|
}else if (strRank.equals("fsp")){return Rank.SPECIALFORM();
|
78
|
}else if (strRank.equals("subsubfm")){return Rank.SUBSUBFORM();
|
79
|
}else if (strRank.equals("subfm")){return Rank.SUBFORM();
|
80
|
}else if (strRank.equals("fm")){return Rank.FORM();
|
81
|
}else if (strRank.equals("subsubvar")){return Rank.SUBSUBVARIETY();
|
82
|
}else if (strRank.equals("subvar")){return Rank.SUBVARIETY();
|
83
|
}else if (strRank.equals("var")){return Rank.VARIETY();
|
84
|
//TODO -> see documentation, Bacteria status
|
85
|
// }else if (strRank.equals("pv")){return Rank;
|
86
|
// }else if (strRank.equals("bv")){return Rank.;
|
87
|
}else if (strRank.equals("infrasp")){return Rank.INFRASPECIES();
|
88
|
//above superfamily
|
89
|
}else if (strRank.equals("infraord")){return Rank.INFRAORDER();
|
90
|
}else if (strRank.equals("ord")){return Rank.ORDER();
|
91
|
}else if (strRank.equals("superord")){return Rank.SUPERORDER();
|
92
|
}else if (strRank.equals("infracl")){return Rank.INFRACLASS();
|
93
|
}else if (strRank.equals("subcl")){return Rank.SUBCLASS();
|
94
|
}else if (strRank.equals("cl")){return Rank.CLASS();
|
95
|
}else if (strRank.equals("supercl")){return Rank.SUPERCLASS();
|
96
|
}else if (strRank.equals("infraphyl_div")){return Rank.INFRAPHYLUM();
|
97
|
}else if (strRank.equals("subphyl_div")){return Rank.SUBPHYLUM();
|
98
|
}else if (strRank.equals("phyl_div")){return Rank.PHYLUM();
|
99
|
}else if (strRank.equals("superphyl_div")){return Rank.SUPERPHYLUM();
|
100
|
}else if (strRank.equals("infrareg")){return Rank.INFRAKINGDOM();
|
101
|
}else if (strRank.equals("subreg")){return Rank.SUBKINGDOM();
|
102
|
}else if (strRank.equals("reg")){return Rank.KINGDOM();
|
103
|
}else if (strRank.equals("superreg")){return Rank.SUPERKINGDOM();
|
104
|
}else if (strRank.equals("dom")){return Rank.DOMAIN();
|
105
|
}else if (strRank.equals("taxsupragen")){return Rank.SUPRAGENERICTAXON();
|
106
|
//family group
|
107
|
}else if (strRank.equals("infrafam")){return Rank.FAMILY();
|
108
|
}else if (strRank.equals("subfam")){return Rank.FAMILY();
|
109
|
}else if (strRank.equals("fam")){return Rank.FAMILY();
|
110
|
}else if (strRank.equals("superfam")){return Rank.FAMILY();
|
111
|
//family subdivision
|
112
|
}else if (strRank.equals("intratrib")){return Rank.FAMILY();
|
113
|
}else if (strRank.equals("subtrib")){return Rank.FAMILY();
|
114
|
}else if (strRank.equals("trib")){return Rank.FAMILY();
|
115
|
}else if (strRank.equals("supertrib")){return Rank.FAMILY();
|
116
|
}
|
117
|
else {
|
118
|
throw new UnknownCdmTypeException("Unknown Rank " + strRank);
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
|
123
|
*/
|
124
|
public static NomenclaturalCode nomCodeString2NomCode (String nomCode) throws UnknownCdmTypeException{
|
125
|
if (nomCode != null){
|
126
|
nomCode = nomCode.trim();
|
127
|
}
|
128
|
if (nomCode == null){ return null;
|
129
|
}else if (nomCode.equals("Botanical")){return NomenclaturalCode.ICBN;
|
130
|
}else if (nomCode.equals("Zoological")){return NomenclaturalCode.ICZN;
|
131
|
}else if (nomCode.equals("Viral")){return NomenclaturalCode.ICVCN;
|
132
|
}else if (nomCode.equals("Bacteriological")){return NomenclaturalCode.ICNB;
|
133
|
}else if (nomCode.equals("CultivatedPlant")){return NomenclaturalCode.ICNCP;
|
134
|
//TODO code Indeterminate
|
135
|
// }else if (nomCode.equals("Indeterminate")){return NomenclaturalCode.XXX();
|
136
|
}
|
137
|
else {
|
138
|
throw new UnknownCdmTypeException("Unknown Nomenclatural Code " + nomCode);
|
139
|
}
|
140
|
}
|
141
|
|
142
|
public static boolean isReverseRelationshipCategory (String tcsRelationshipCategory){
|
143
|
String str = tcsRelationshipCategory.replace("http://rs.tdwg.org/ontology/voc/TaxonConcept#", "");
|
144
|
if ("HasSynonym".equalsIgnoreCase(str)
|
145
|
|| "IsParentTaxonOf".equalsIgnoreCase(str)
|
146
|
|| "IsIncludedIn".equalsIgnoreCase(str)
|
147
|
|| "DoesNotInclude".equalsIgnoreCase(str)
|
148
|
){
|
149
|
|
150
|
return true;
|
151
|
}
|
152
|
return false;
|
153
|
}
|
154
|
|
155
|
/** Creates an cdm-Rank by the tcs rank
|
156
|
*/
|
157
|
public static StrictReferenceBase pubTypeStr2PubType (String strPubType) throws UnknownCdmTypeException{
|
158
|
String tcsRoot = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
|
159
|
String tcsBook = tcsRoot + "Book";
|
160
|
String tcsJournal = tcsRoot + "Journal";
|
161
|
String tcsWebPage = tcsRoot + "WebPage";
|
162
|
String tcsCommunication = tcsRoot + "Communication";
|
163
|
String tcsBookSeries = tcsRoot + "BookSeries";
|
164
|
String tcsArticle = tcsRoot + "JournalArticle";
|
165
|
String tcsBookSection = tcsRoot + "BookSection";
|
166
|
|
167
|
|
168
|
// Artwork An Artwork type publication.
|
169
|
// AudiovisualMaterial A Audiovisual Material type publication.
|
170
|
// BookSeries A Book Series type publication.
|
171
|
// Commentary A Commentary type publication.
|
172
|
// Communication A Communication type publication.
|
173
|
// ComputerProgram A Computer Program type publication.
|
174
|
// ConferenceProceedings A Conference Proceedings type publication.
|
175
|
// Determination A Determination type publication.
|
176
|
// EditedBook A Edited Book type publication.
|
177
|
// Generic A generic publication.
|
178
|
// Journal A Journal type publication.
|
179
|
// MagazineArticle A Magazine Article type publication.
|
180
|
// Map A Map type publication.
|
181
|
// NewspaperArticle A Newspaper Article type publication.
|
182
|
// Patent A Patent type publication.
|
183
|
// Report A Report type publication.
|
184
|
// SubReference A Sub-Reference type publication.
|
185
|
// Thesis A Thesis type publication.
|
186
|
|
187
|
|
188
|
if (strPubType == null){return null;
|
189
|
}else if (tcsBookSection.equals(strPubType)){return BookSection.NewInstance();
|
190
|
}else if (tcsBook.equals(strPubType)){return Book.NewInstance();
|
191
|
}else if (tcsArticle.equals(strPubType)){return Article.NewInstance();
|
192
|
}else if (tcsJournal.equals(strPubType)){return Journal.NewInstance();
|
193
|
}else if (tcsWebPage.equals(strPubType)){return WebPage.NewInstance();
|
194
|
}else if (tcsCommunication.equals(strPubType)){return PersonalCommunication.NewInstance();
|
195
|
}else if (tcsBookSeries.equals(strPubType)){return PrintSeries.NewInstance();
|
196
|
}
|
197
|
else {
|
198
|
throw new UnknownCdmTypeException("Unknown publication type " + strPubType);
|
199
|
}
|
200
|
}
|
201
|
|
202
|
/** Creates an cdm-RelationshipTermBase by the tcsRelationshipCategory
|
203
|
*/
|
204
|
public static RelationshipTermBase tcsRelationshipType2Relationship (String tcsRelationshipType, ResultWrapper<Boolean> inverse) throws UnknownCdmTypeException{
|
205
|
if (tcsRelationshipType == null){ return null;
|
206
|
|
207
|
//Synonym relationships
|
208
|
// }else if (tcsRelationshipType.equals("is synonym for")){return SynonymRelationshipType.SYNONYM_OF();
|
209
|
}else if (tcsRelationshipType.equals("has synonym")){inverse.setValue(true); return SynonymRelationshipType.SYNONYM_OF();
|
210
|
|
211
|
//Taxon relationships
|
212
|
}else if (tcsRelationshipType.equals("is child taxon of")){return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
|
213
|
}else if (tcsRelationshipType.equals("is parent taxon of")){inverse.setValue(true); return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
|
214
|
|
215
|
//concept relationships
|
216
|
}else if (tcsRelationshipType.equals("does not overlap")){return TaxonRelationshipType.DOES_NOT_OVERLAP();
|
217
|
}else if (tcsRelationshipType.equals("excludes")){return TaxonRelationshipType.EXCLUDES();
|
218
|
}else if (tcsRelationshipType.equals("includes")){return TaxonRelationshipType.INCLUDES();
|
219
|
}else if (tcsRelationshipType.equals("is congruent to")){return TaxonRelationshipType.CONGRUENT_TO();
|
220
|
}else if (tcsRelationshipType.equals("is not congruent to")){return TaxonRelationshipType.NOT_CONGRUENT_TO();
|
221
|
}else if (tcsRelationshipType.equals("is not included in")){return TaxonRelationshipType.NOT_INCLUDED_IN();
|
222
|
}else if (tcsRelationshipType.equals("overlaps")){return TaxonRelationshipType.OVERLAPS();
|
223
|
//reverse concept relationships
|
224
|
}else if (tcsRelationshipType.equals("is included in")){inverse.setValue(true); return TaxonRelationshipType.INCLUDES();
|
225
|
}else if (tcsRelationshipType.equals("does not include")){inverse.setValue(true); return TaxonRelationshipType.NOT_INCLUDED_IN();
|
226
|
|
227
|
//TODO
|
228
|
|
229
|
// }else if (tcsRelationshipType.equals("has vernacular")){return TaxonRelationshipType.X;
|
230
|
// }else if (tcsRelationshipType.equals("is vernacular for")){return TaxonRelationshipType.X;
|
231
|
// }else if (tcsRelationshipType.equals("is ambiregnal of")){return TaxonRelationshipType.X;
|
232
|
// }else if (tcsRelationshipType.equals("is hybrid child of")){return TaxonRelationshipType.X;
|
233
|
// }else if (tcsRelationshipType.equals("is hybrid parent of")){return TaxonRelationshipType.X;
|
234
|
// }else if (tcsRelationshipType.equals("is male parent of")){return TaxonRelationshipType.X;
|
235
|
// }else if (tcsRelationshipType.equals("is first parent of")){return TaxonRelationshipType.X;
|
236
|
// }else if (tcsRelationshipType.equals("is female parent of")){return TaxonRelationshipType.X;
|
237
|
// }else if (tcsRelationshipType.equals("is second parent of")){return TaxonRelationshipType.X;
|
238
|
// }else if (tcsRelationshipType.equals("is teleomorph of")){return TaxonRelationshipType.X;
|
239
|
// }else if (tcsRelationshipType.equals("is anamorph of")){return TaxonRelationshipType.X;
|
240
|
|
241
|
}else {
|
242
|
throw new UnknownCdmTypeException("Unknown RelationshipCategory " + tcsRelationshipType);
|
243
|
}
|
244
|
}
|
245
|
|
246
|
|
247
|
/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
|
248
|
*/
|
249
|
public static NomenclaturalStatusType nomStatusString2NomStatus (String nomStatus) throws UnknownCdmTypeException{
|
250
|
|
251
|
if (nomStatus == null){ return null;
|
252
|
}else if ("Valid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.VALID();
|
253
|
|
254
|
}else if ("Alternative".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
|
255
|
}else if ("nom. altern.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
|
256
|
|
257
|
}else if ("Ambiguous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.AMBIGUOUS();
|
258
|
|
259
|
}else if ("Doubtful".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.DOUBTFUL();
|
260
|
|
261
|
}else if ("Confusum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONFUSUM();
|
262
|
|
263
|
}else if ("Illegitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
|
264
|
}else if ("nom. illeg.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
|
265
|
|
266
|
}else if ("Superfluous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
|
267
|
}else if ("nom. superfl.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
|
268
|
|
269
|
}else if ("Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
|
270
|
}else if ("nom. rej.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
|
271
|
|
272
|
}else if ("Utique Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED();
|
273
|
|
274
|
}else if ("Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED_PROP();
|
275
|
|
276
|
}else if ("Orthography Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP();
|
277
|
|
278
|
}else if ("Legitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.LEGITIMATE();
|
279
|
|
280
|
}else if ("Novum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
|
281
|
}else if ("nom. nov.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
|
282
|
|
283
|
}else if ("Utique Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED_PROP();
|
284
|
|
285
|
}else if ("Orthography Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED();
|
286
|
|
287
|
}else if ("Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED_PROP();
|
288
|
|
289
|
}else if ("Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
|
290
|
}else if ("nom. cons.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
|
291
|
|
292
|
}else if ("Sanctioned".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SANCTIONED();
|
293
|
|
294
|
}else if ("Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
|
295
|
}else if ("nom. inval.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
|
296
|
|
297
|
}else if ("Nudum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
|
298
|
}else if ("nom. nud.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
|
299
|
|
300
|
}else if ("Combination Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.COMBINATION_INVALID();
|
301
|
|
302
|
}else if ("Provisional".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
|
303
|
}else if ("nom. provis.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
|
304
|
}
|
305
|
else {
|
306
|
throw new UnknownCdmTypeException("Unknown Nomenclatural status type " + nomStatus);
|
307
|
}
|
308
|
}
|
309
|
|
310
|
|
311
|
}
|