1
|
package eu.etaxonomy.cdm.io.tcs;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
|
5
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
6
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
7
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
8
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
9
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
10
|
import eu.etaxonomy.cdm.model.name.Rank;
|
11
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatus;
|
12
|
import eu.etaxonomy.cdm.model.reference.Book;
|
13
|
import eu.etaxonomy.cdm.model.reference.Journal;
|
14
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
15
|
import eu.etaxonomy.cdm.model.reference.WebPage;
|
16
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
17
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
18
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
19
|
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
|
20
|
|
21
|
public final class TcsTransformer {
|
22
|
private static final Logger logger = Logger.getLogger(TcsTransformer.class);
|
23
|
|
24
|
|
25
|
//TypeDesignation
|
26
|
public static TypeDesignationStatus typeStatusId2TypeStatus (int typeStatusId) throws UnknownCdmTypeException{
|
27
|
switch (typeStatusId){
|
28
|
case 1: return TypeDesignationStatus.HOLOTYPE();
|
29
|
case 2: return TypeDesignationStatus.LECTOTYPE();
|
30
|
case 3: return TypeDesignationStatus.NEOTYPE();
|
31
|
case 4: return TypeDesignationStatus.EPITYPE();
|
32
|
case 5: return TypeDesignationStatus.ISOLECTOTYPE();
|
33
|
case 6: return TypeDesignationStatus.ISONEOTYPE();
|
34
|
case 7: return TypeDesignationStatus.ISOTYPE();
|
35
|
case 8: return TypeDesignationStatus.PARANEOTYPE();
|
36
|
case 9: return TypeDesignationStatus.PARATYPE();
|
37
|
case 10: return TypeDesignationStatus.SECOND_STEP_LECTOTYPE();
|
38
|
case 11: return TypeDesignationStatus.SECOND_STEP_NEOTYPE();
|
39
|
case 12: return TypeDesignationStatus.SYNTYPE();
|
40
|
case 21: return TypeDesignationStatus.ICONOTYPE();
|
41
|
case 22: return TypeDesignationStatus.PHOTOTYPE();
|
42
|
default: {
|
43
|
throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(typeStatusId).toString() + ")");
|
44
|
}
|
45
|
}
|
46
|
}
|
47
|
|
48
|
|
49
|
|
50
|
|
51
|
/** Creates an cdm-Rank by the tcs rank
|
52
|
*/
|
53
|
public static Rank rankString2Rank (String strRank) throws UnknownCdmTypeException{
|
54
|
String tcsRoot = "http://rs.tdwg.org/ontology/voc/TaxonRank#";
|
55
|
String tcsGenus = tcsRoot + "Genus";
|
56
|
String tcsSpecies = tcsRoot + "Species";
|
57
|
String tcsVariety = tcsRoot + "Variety";
|
58
|
String tcsSubVariety = tcsRoot + "Sub-Variety";
|
59
|
String tcsForm = tcsRoot + "Form";
|
60
|
String tcsSubSpecies = tcsRoot + "Subspecies";
|
61
|
|
62
|
|
63
|
if (strRank == null){return null;
|
64
|
}else if (tcsGenus.equals(strRank)){return Rank.GENUS();
|
65
|
}else if (tcsSpecies.equals(strRank)){return Rank.SPECIES();
|
66
|
}else if (tcsVariety.equals(strRank)){return Rank.VARIETY();
|
67
|
}else if (tcsSubVariety.equals(strRank)){return Rank.SUBVARIETY();
|
68
|
}else if (tcsSubSpecies.equals(strRank)){return Rank.SUBSPECIES();
|
69
|
}else if (tcsForm.equals(strRank)){return Rank.FORM();
|
70
|
}
|
71
|
else {
|
72
|
throw new UnknownCdmTypeException("Unknown Rank " + strRank);
|
73
|
}
|
74
|
}
|
75
|
|
76
|
/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
|
77
|
*/
|
78
|
public static NomenclaturalCode nomCodeString2NomCode (String nomCode) throws UnknownCdmTypeException{
|
79
|
|
80
|
String tcsRoot = "http://rs.tdwg.org/ontology/voc/TaxonName#";
|
81
|
String tcsICBN = tcsRoot + "ICBN";
|
82
|
String tcsICZN = tcsRoot + "ICZN";
|
83
|
String tcsICNCP = tcsRoot + "ICNCP";
|
84
|
String tcsBacteriological = tcsRoot + "BACTERIOLOGICAL";
|
85
|
String tcsViral = tcsRoot + "VIRAL";
|
86
|
|
87
|
if (nomCode == null){ return null;
|
88
|
}else if (tcsICBN.equals(nomCode)){return NomenclaturalCode.ICBN();
|
89
|
}else if (tcsICZN.equals(nomCode)){return NomenclaturalCode.ICZN();
|
90
|
}else if (tcsICNCP.equals(nomCode)){return NomenclaturalCode.ICNCP();
|
91
|
}else if (tcsBacteriological.equals(nomCode)){return NomenclaturalCode.ICNB();
|
92
|
}else if (tcsViral.equals(nomCode)){return NomenclaturalCode.ICVCN();
|
93
|
}
|
94
|
else {
|
95
|
throw new UnknownCdmTypeException("Unknown Nomenclatural Code " + nomCode);
|
96
|
}
|
97
|
}
|
98
|
|
99
|
public static boolean isReverseRelationshipCategory (String tcsRelationshipCategory){
|
100
|
String str = tcsRelationshipCategory.replace("http://rs.tdwg.org/ontology/voc/TaxonConcept#", "");
|
101
|
if ("HasSynonym".equalsIgnoreCase(str)
|
102
|
|| "IsParentTaxonOf".equalsIgnoreCase(str)
|
103
|
|| "IsIncludedIn".equalsIgnoreCase(str)
|
104
|
|| "DoesNotInclude".equalsIgnoreCase(str)
|
105
|
){
|
106
|
|
107
|
return true;
|
108
|
}
|
109
|
return false;
|
110
|
}
|
111
|
|
112
|
/** Creates an cdm-Rank by the tcs rank
|
113
|
*/
|
114
|
public static ReferenceBase pubTypeStr2PubType (String strPubType) throws UnknownCdmTypeException{
|
115
|
String tcsRoot = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
|
116
|
String tcsBook = tcsRoot + "Book";
|
117
|
String tcsJournal = tcsRoot + "Journal";
|
118
|
String tcsWebPage = tcsRoot + "WebPage";
|
119
|
String tcsCommunication = tcsRoot + "Communication";
|
120
|
String tcsBookSeries = tcsRoot + "BookSeries";
|
121
|
|
122
|
|
123
|
if (strPubType == null){return null;
|
124
|
}else if (tcsBook.equals(strPubType)){return Book.NewInstance();
|
125
|
}else if (tcsJournal.equals(strPubType)){return Journal.NewInstance();
|
126
|
}else if (tcsWebPage.equals(strPubType)){return WebPage.NewInstance();
|
127
|
}
|
128
|
else {
|
129
|
throw new UnknownCdmTypeException("Unknown publication type " + strPubType);
|
130
|
}
|
131
|
}
|
132
|
|
133
|
/** Creates an cdm-RelationshipTermBase by the tcsRelationshipCategory
|
134
|
*/
|
135
|
public static RelationshipTermBase tcsRelationshipCategory2Relationship (String tcsRelationshipCategory) throws UnknownCdmTypeException{
|
136
|
String tcsRoot = "http://rs.tdwg.org/ontology/voc/TaxonConcept#";
|
137
|
String doesNotInclude = tcsRoot + "DoesNotInclude";
|
138
|
String doesNotOverlap = tcsRoot + "DoesNotOverlap";
|
139
|
String excludes = tcsRoot + "Excludes";
|
140
|
String hasSynonym = tcsRoot + "HasSynonym";
|
141
|
String hasVernacular = tcsRoot + "HasVernacular";
|
142
|
String includes = tcsRoot + "Includes";
|
143
|
String isAmbiregnalOf = tcsRoot + "IsAmbiregnalOf";
|
144
|
String isAnamorphOf = tcsRoot + "IsAnamorphOf";
|
145
|
String isChildTaxonOf = tcsRoot + "IsChildTaxonOf";
|
146
|
String isCongruentTo = tcsRoot + "IsCongruentTo";
|
147
|
String isFemaleParentOf = tcsRoot + "IsFemaleParentOf";
|
148
|
String isFirstParentOf = tcsRoot + "IsFirstParentOf";
|
149
|
String isHybridChildOf = tcsRoot + "IsHybridChildOf";
|
150
|
String isHybridParentOf = tcsRoot + "IsHybridParentOf";
|
151
|
String isIncludedIn = tcsRoot + "IsIncludedIn";
|
152
|
String isMaleParentOf = tcsRoot + "IsMaleParentOf";
|
153
|
String isNotCongruentTo = tcsRoot + "IsNotCongruentTo";
|
154
|
String isNotIncludedIn = tcsRoot + "IsNotIncludedIn";
|
155
|
String isParentTaxonOf = tcsRoot + "IsParentTaxonOf";
|
156
|
String isSecondParentOf = tcsRoot + "IsSecondParentOf";
|
157
|
String isSynonymFor = tcsRoot + "IsSynonymFor";
|
158
|
String isTeleomorphOf = tcsRoot + "IsTeleomorphOf";
|
159
|
String isVernacularFor = tcsRoot + "IsVernacularFor";
|
160
|
String overlaps = tcsRoot + "Overlaps";
|
161
|
|
162
|
if (tcsRelationshipCategory == null){ return null;
|
163
|
|
164
|
//Synonym relationships
|
165
|
}else if (isSynonymFor.equals(tcsRelationshipCategory)){return SynonymRelationshipType.SYNONYM_OF();
|
166
|
}else if (hasSynonym.equals(tcsRelationshipCategory)){/*isReverse = true; */ return SynonymRelationshipType.SYNONYM_OF();
|
167
|
|
168
|
//Taxon relationships
|
169
|
}else if (isChildTaxonOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
|
170
|
}else if (isParentTaxonOf.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
|
171
|
|
172
|
//concept relationships
|
173
|
}else if (doesNotOverlap.equals(tcsRelationshipCategory)){return TaxonRelationshipType.DOESNOTOVERLAP();
|
174
|
}else if (excludes.equals(tcsRelationshipCategory)){return TaxonRelationshipType.EXCLUDES();
|
175
|
}else if (includes.equals(tcsRelationshipCategory)){return TaxonRelationshipType.INCLUDES();
|
176
|
}else if (isCongruentTo.equals(tcsRelationshipCategory)){return TaxonRelationshipType.CONGRUENTTO();
|
177
|
}else if (isNotCongruentTo.equals(tcsRelationshipCategory)){return TaxonRelationshipType.NOTCONGRUENTTO();
|
178
|
}else if (isNotIncludedIn.equals(tcsRelationshipCategory)){return TaxonRelationshipType.NOTINCLUDEDIN();
|
179
|
}else if (overlaps.equals(tcsRelationshipCategory)){return TaxonRelationshipType.OVERLAPS();
|
180
|
//reverse concept relationships
|
181
|
}else if (isIncludedIn.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.INCLUDES();
|
182
|
}else if (doesNotInclude.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.NOTINCLUDEDIN();
|
183
|
|
184
|
//TODO
|
185
|
// }else if (hasVernacular.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
186
|
// }else if (isAmbiregnalOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
187
|
// }else if (isAnamorphOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
188
|
// }else if (isFemaleParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
189
|
// }else if (isFirstParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
190
|
// }else if (isHybridChildOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
191
|
// }else if (isHybridParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
192
|
// }else if (isMaleParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
193
|
// }else if (isSecondParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
194
|
// }else if (isTeleomorphOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
195
|
// }else if (isVernacularFor.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
|
196
|
|
197
|
}else {
|
198
|
throw new UnknownCdmTypeException("Unknown RelationshipCategory " + tcsRelationshipCategory);
|
199
|
}
|
200
|
}
|
201
|
|
202
|
|
203
|
/** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
|
204
|
*/
|
205
|
public static NomenclaturalStatusType nomStatusString2NomStatus (String nomStatus) throws UnknownCdmTypeException{
|
206
|
|
207
|
if (nomStatus == null){ return null;
|
208
|
}else if ("Valid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.VALID();
|
209
|
|
210
|
}else if ("Alternative".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
|
211
|
}else if ("nom. altern.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
|
212
|
|
213
|
}else if ("Ambiguous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.AMBIGUOUS();
|
214
|
|
215
|
}else if ("Doubtful".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.DOUBTFUL();
|
216
|
|
217
|
}else if ("Confusum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONFUSUM();
|
218
|
|
219
|
}else if ("Illegitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
|
220
|
}else if ("nom. illeg.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
|
221
|
|
222
|
}else if ("Superfluous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
|
223
|
}else if ("nom. superfl.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
|
224
|
|
225
|
}else if ("Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
|
226
|
}else if ("nom. rej.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
|
227
|
|
228
|
}else if ("Utique Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED();
|
229
|
|
230
|
}else if ("Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED_PROP();
|
231
|
|
232
|
}else if ("Orthography Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP();
|
233
|
|
234
|
}else if ("Legitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.LEGITIMATE();
|
235
|
|
236
|
}else if ("Novum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
|
237
|
}else if ("nom. nov.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
|
238
|
|
239
|
}else if ("Utique Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED_PROP();
|
240
|
|
241
|
}else if ("Orthography Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED();
|
242
|
|
243
|
}else if ("Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED_PROP();
|
244
|
|
245
|
}else if ("Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
|
246
|
}else if ("nom. cons.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
|
247
|
|
248
|
}else if ("Sanctioned".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SANCTIONED();
|
249
|
|
250
|
}else if ("Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
|
251
|
}else if ("nom. inval.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
|
252
|
|
253
|
}else if ("Nudum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
|
254
|
}else if ("nom. nud.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
|
255
|
|
256
|
}else if ("Combination Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.COMBINATION_INVALID();
|
257
|
|
258
|
}else if ("Provisional".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
|
259
|
}else if ("nom. provis.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
|
260
|
}
|
261
|
else {
|
262
|
throw new UnknownCdmTypeException("Unknown Nomenclatural status type " + nomStatus);
|
263
|
}
|
264
|
}
|
265
|
|
266
|
|
267
|
}
|