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