fix #9617 rename ICNB to ICNP in cdmlib
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / tcsrdf / TcsRdfTransformer.java
1 /**
2 * Copyright (C) 2007 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.tcsrdf;
11
12 import org.apache.log4j.Logger;
13
14 import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
15 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
16 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
17 import eu.etaxonomy.cdm.model.name.Rank;
18 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
19 import eu.etaxonomy.cdm.model.reference.Reference;
20 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
21 import eu.etaxonomy.cdm.model.taxon.SynonymType;
22 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
23 import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
24
25 /**
26 * @author a.mueller
27 * @since 29.05.2008
28 */
29 public final class TcsRdfTransformer {
30 @SuppressWarnings("unused")
31 private static final Logger logger = Logger.getLogger(TcsRdfTransformer.class);
32
33
34 //TypeDesignation
35 public static SpecimenTypeDesignationStatus typeStatusId2TypeStatus (int typeStatusId) throws UnknownCdmTypeException{
36 switch (typeStatusId){
37 case 1: return SpecimenTypeDesignationStatus.HOLOTYPE();
38 case 2: return SpecimenTypeDesignationStatus.LECTOTYPE();
39 case 3: return SpecimenTypeDesignationStatus.NEOTYPE();
40 case 4: return SpecimenTypeDesignationStatus.EPITYPE();
41 case 5: return SpecimenTypeDesignationStatus.ISOLECTOTYPE();
42 case 6: return SpecimenTypeDesignationStatus.ISONEOTYPE();
43 case 7: return SpecimenTypeDesignationStatus.ISOTYPE();
44 case 8: return SpecimenTypeDesignationStatus.PARANEOTYPE();
45 case 9: return SpecimenTypeDesignationStatus.PARATYPE();
46 case 10: return SpecimenTypeDesignationStatus.SECOND_STEP_LECTOTYPE();
47 case 11: return SpecimenTypeDesignationStatus.SECOND_STEP_NEOTYPE();
48 case 12: return SpecimenTypeDesignationStatus.SYNTYPE();
49 case 21: return SpecimenTypeDesignationStatus.ICONOTYPE();
50 case 22: return SpecimenTypeDesignationStatus.PHOTOTYPE();
51 default: {
52 throw new UnknownCdmTypeException("Unknown TypeDesignationStatus (id=" + Integer.valueOf(typeStatusId).toString() + ")");
53 }
54 }
55 }
56
57
58
59
60 /** Creates an cdm-Rank by the tcs rank
61 */
62 public static Rank rankString2Rank (String strRank) throws UnknownCdmTypeException{
63 String tcsRoot = "http://rs.tdwg.org/ontology/voc/taxonrank#";
64 String tcsFamily = "family";
65 String tcsSubFamily = "subfamily";
66 String tcsTribe = "tribe";
67 String tcsSubtribe = "subtribe";
68 String tcsGenus = "genus";
69 String tcsSection = "section";
70 String tcsSpecies = "species";
71 String tcsSubSpecies = "subspecies";
72 String tcsVariety = "variety";
73 String tcsSubVariety = "subvariety";
74 String tcsForm = "form";
75
76
77 String tcsAbbFamily = "fam.";
78 String tcsAbbrSubFamily = "subfam.";
79 String tcsAbbrTribe = "trib.";
80 String tcsAbbrSubtribe = "subtrib.";
81 String tcsAbbrGenus = "gen.";
82 String tcsAbbrSubGenus = "subgen.";
83 String tcsAbbrSection = "sect.";
84 String tcsAbbrSubSection = "subsect.";
85 String tcsAbbrSeries = "ser.";
86 String tcsAbbrSpecies = "spec.";
87 String tcsAbbrSubSpecies = "subsp.";
88 String tcsAbbrVariety = "var.";
89 String tcsAbbrSubVariety ="subvar.";
90 String tcsAbbrForm = "f.";
91 String tcsAbbrForma = "forma";
92 String tcsAbbrSubForm = "subf.";
93 String tcsAbbrInfraspecUnranked ="[infrasp.unranked]";
94 String tcsAbbrInfragenUnranked ="[infragen.unranked]";
95 String tcsAbbrNothoSubSpecies = "nothosubsp.";
96
97 if (strRank == null){return null;
98 }else{
99 strRank = strRank.toLowerCase();
100 }
101 if (tcsFamily.equals(strRank) || tcsRoot.concat(tcsFamily).equals(strRank)){return Rank.FAMILY();
102 }else if (tcsSubFamily.equals(strRank)|| tcsRoot.concat(tcsSubFamily).equals(strRank)){return Rank.SUBFAMILY();
103 }else if (tcsTribe.equals(strRank)|| tcsRoot.concat(tcsTribe).equals(strRank)){return Rank.TRIBE();
104 }else if (tcsSubtribe.equals(strRank)|| tcsRoot.concat(tcsSubtribe).equals(strRank)){return Rank.SUBTRIBE();
105 }else if (tcsGenus.equals(strRank)|| tcsRoot.concat(tcsGenus).equals(strRank)){return Rank.GENUS();
106 }else if (tcsSection.equals(strRank)|| tcsRoot.concat(tcsSection).equals(strRank)){return Rank.SECTION_BOTANY();
107 }else if (tcsSpecies.equals(strRank)|| tcsRoot.concat(tcsSpecies).equals(strRank)){return Rank.SPECIES();
108 }else if (tcsVariety.equals(strRank)|| tcsRoot.concat(tcsVariety).equals(strRank)){return Rank.VARIETY();
109 }else if (tcsSubVariety.equals(strRank)|| tcsRoot.concat(tcsSubVariety).equals(strRank)){return Rank.SUBVARIETY();
110 }else if (tcsSubSpecies.equals(strRank) || tcsRoot.concat(tcsSubSpecies).equals(strRank)){return Rank.SUBSPECIES();
111 }else if (tcsForm.equals(strRank)|| tcsRoot.concat(tcsForm).equals(strRank)){return Rank.FORM();
112 }else if (tcsAbbFamily.equals(strRank)){return Rank.FAMILY();
113 }else if (tcsAbbrSubFamily.equals(strRank)){return Rank.SUBFAMILY();
114 }else if (tcsAbbrTribe.equals(strRank)){return Rank.TRIBE();
115 }else if (tcsAbbrSubtribe.equals(strRank)){return Rank.SUBTRIBE();
116 }else if (tcsAbbrGenus.equals(strRank)){return Rank.GENUS();
117 }else if (tcsAbbrSubGenus.equals(strRank)){return Rank.SUBGENUS();
118 }else if (tcsAbbrSection.equals(strRank)){return Rank.SECTION_BOTANY();
119 }else if (tcsAbbrSubSection.equals(strRank)){return Rank.SUBSECTION_BOTANY();
120 }else if (tcsAbbrSeries.equals(strRank)){return Rank.SERIES();
121 }else if (tcsAbbrSpecies.equals(strRank)){return Rank.SPECIES();
122 }else if (tcsAbbrSubSpecies.equals(strRank) || tcsAbbrNothoSubSpecies.equals(strRank)){return Rank.SUBSPECIES();
123 }else if (tcsAbbrVariety.equals(strRank)){return Rank.VARIETY();
124 }else if (tcsAbbrSubVariety.equals(strRank)){return Rank.SUBVARIETY();
125 }else if (tcsAbbrForm.equals(strRank) ||tcsAbbrForma.equals(strRank)){return Rank.FORM();
126 }else if (tcsAbbrSubForm.equals(strRank)){return Rank.SUBFORM();
127 }else if (tcsAbbrInfraspecUnranked.equals(strRank)){return Rank.UNRANKED_INFRASPECIFIC();
128 }else if (tcsAbbrInfragenUnranked.equals(strRank)){return Rank.UNRANKED_INFRAGENERIC();
129 }else{
130 throw new UnknownCdmTypeException("Unknown Rank " + strRank);
131 }
132 }
133
134 /** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
135 */
136 public static NomenclaturalCode nomCodeString2NomCode (String nomCode) throws UnknownCdmTypeException{
137
138
139 String tcsRoot = "http://rs.tdwg.org/ontology/voc/TaxonName#";
140 String tcsBotanical = tcsRoot + "botanical";
141 String tcsICBN = tcsRoot + "ICBN";
142 String tcsICZN = tcsRoot + "ICZN";
143 String tcsICNCP = tcsRoot + "ICNCP";
144 String tcsBacteriological = tcsRoot + "BACTERIOLOGICAL";
145 String tcsViral = tcsRoot + "VIRAL";
146
147 if (nomCode == null){ return null;
148 }else if (tcsICBN.equals(nomCode)){return NomenclaturalCode.ICNAFP;
149 }else if (tcsBotanical.equals(nomCode)){return NomenclaturalCode.ICNAFP;
150 }else if (tcsICZN.equals(nomCode)){return NomenclaturalCode.ICZN;
151 }else if (tcsICNCP.equals(nomCode)){return NomenclaturalCode.ICNCP;
152 }else if (tcsBacteriological.equals(nomCode)){return NomenclaturalCode.ICNP;
153 }else if (tcsViral.equals(nomCode)){return NomenclaturalCode.ICVCN;
154 }
155 else {
156 throw new UnknownCdmTypeException("Unknown Nomenclatural Code " + nomCode);
157 }
158 }
159
160 public static boolean isReverseRelationshipCategory (String tcsRelationshipCategory){
161 String str = tcsRelationshipCategory.replace("http://rs.tdwg.org/ontology/voc/TaxonConcept#", "");
162 if ("HasSynonym".equalsIgnoreCase(str)
163 || "IsParentTaxonOf".equalsIgnoreCase(str)
164 || "IsIncludedIn".equalsIgnoreCase(str)
165 || "DoesNotInclude".equalsIgnoreCase(str)
166 ){
167
168 return true;
169 }
170 return false;
171 }
172
173 /** Creates an cdm-Rank by the tcs rank
174 */
175 public static Reference pubTypeStr2PubType (String strPubType) throws UnknownCdmTypeException{
176 String tcsRoot = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
177 String tcsBook = tcsRoot + "Book";
178 String tcsJournal = tcsRoot + "Journal";
179 String tcsWebPage = tcsRoot + "WebPage";
180 String tcsCommunication = tcsRoot + "Communication";
181 String tcsBookSeries = tcsRoot + "BookSeries";
182 String tcsArticle = tcsRoot + "JournalArticle";
183 String tcsBookSection = tcsRoot + "BookSection";
184
185
186 // Artwork An Artwork type publication.
187 // AudiovisualMaterial A Audiovisual Material type publication.
188 // BookSeries A Book Series type publication.
189 // Commentary A Commentary type publication.
190 // Communication A Communication type publication.
191 // ComputerProgram A Computer Program type publication.
192 // ConferenceProceedings A Conference Proceedings type publication.
193 // Determination A Determination type publication.
194 // EditedBook A Edited Book type publication.
195 // Generic A generic publication.
196 // Journal A Journal type publication.
197 // MagazineArticle A Magazine Article type publication.
198 // Map A Map type publication.
199 // NewspaperArticle A Newspaper Article type publication.
200 // Patent A Patent type publication.
201 // Report A Report type publication.
202 // SubReference A Sub-Reference type publication.
203 // Thesis A Thesis type publication.
204
205 if (strPubType == null){return null;
206 }else if (tcsBookSection.equals(strPubType)){return ReferenceFactory.newBookSection();
207 }else if (tcsBook.equals(strPubType)){return ReferenceFactory.newBook();
208 }else if (tcsArticle.equals(strPubType)){return ReferenceFactory.newArticle();
209 }else if (tcsJournal.equals(strPubType)){return ReferenceFactory.newJournal();
210 }else if (tcsWebPage.equals(strPubType)){return ReferenceFactory.newWebPage();
211 }else if (tcsCommunication.equals(strPubType)){return ReferenceFactory.newPersonalCommunication();
212 }else if (tcsBookSeries.equals(strPubType)){return ReferenceFactory.newPrintSeries();
213 }
214 else {
215 throw new UnknownCdmTypeException("Unknown publication type " + strPubType);
216 }
217 }
218
219 /** Creates an cdm-RelationshipTermBase by the tcsRelationshipCategory
220 */
221 public static RelationshipTermBase<?> tcsRelationshipCategory2Relationship (String tcsRelationshipCategory) throws UnknownCdmTypeException{
222 String tcsRoot = "http://rs.tdwg.org/ontology/voc/TaxonConcept#";
223 String doesNotInclude = tcsRoot + "DoesNotInclude";
224 String doesNotOverlap = tcsRoot + "DoesNotOverlap";
225 String excludes = tcsRoot + "Excludes";
226 String hasSynonym = tcsRoot + "HasSynonym";
227 String hasVernacular = tcsRoot + "HasVernacular";
228 String includes = tcsRoot + "Includes";
229 String isAmbiregnalOf = tcsRoot + "IsAmbiregnalOf";
230 String isAnamorphOf = tcsRoot + "IsAnamorphOf";
231 String isChildTaxonOf = tcsRoot + "IsChildTaxonOf";
232 String isCongruentTo = tcsRoot + "IsCongruentTo";
233 String isFemaleParentOf = tcsRoot + "IsFemaleParentOf";
234 String isFirstParentOf = tcsRoot + "IsFirstParentOf";
235 String isHybridChildOf = tcsRoot + "IsHybridChildOf";
236 String isHybridParentOf = tcsRoot + "IsHybridParentOf";
237 String isIncludedIn = tcsRoot + "IsIncludedIn";
238 String isMaleParentOf = tcsRoot + "IsMaleParentOf";
239 String isNotCongruentTo = tcsRoot + "IsNotCongruentTo";
240 String isNotIncludedIn = tcsRoot + "IsNotIncludedIn";
241 String isParentTaxonOf = tcsRoot + "IsParentTaxonOf";
242 String isSecondParentOf = tcsRoot + "IsSecondParentOf";
243 String isSynonymFor = tcsRoot + "IsSynonymFor";
244 String isTeleomorphOf = tcsRoot + "IsTeleomorphOf";
245 String isVernacularFor = tcsRoot + "IsVernacularFor";
246 String overlaps = tcsRoot + "Overlaps";
247
248 if (tcsRelationshipCategory == null){ return null;
249
250 //Synonym relationships
251 }else if (isSynonymFor.equals(tcsRelationshipCategory)){return SynonymType.SYNONYM_OF();
252 }else if (hasSynonym.equals(tcsRelationshipCategory)){/*isReverse = true; */ return SynonymType.SYNONYM_OF();
253
254 //Taxon relationships
255 }else if (isChildTaxonOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
256 }else if (isParentTaxonOf.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN();
257
258 //concept relationships
259 }else if (doesNotOverlap.equals(tcsRelationshipCategory)){return TaxonRelationshipType.DOES_NOT_OVERLAP();
260 }else if (excludes.equals(tcsRelationshipCategory)){return TaxonRelationshipType.EXCLUDES();
261 }else if (includes.equals(tcsRelationshipCategory)){return TaxonRelationshipType.INCLUDES();
262 }else if (isCongruentTo.equals(tcsRelationshipCategory)){return TaxonRelationshipType.CONGRUENT_TO();
263 }else if (isNotCongruentTo.equals(tcsRelationshipCategory)){return TaxonRelationshipType.NOT_CONGRUENT_TO();
264 }else if (isNotIncludedIn.equals(tcsRelationshipCategory)){return TaxonRelationshipType.NOT_INCLUDED_IN();
265 }else if (overlaps.equals(tcsRelationshipCategory)){return TaxonRelationshipType.OVERLAPS();
266 //reverse concept relationships
267 }else if (isIncludedIn.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.INCLUDES();
268 }else if (doesNotInclude.equals(tcsRelationshipCategory)){/*isReverse = true; */ return TaxonRelationshipType.NOT_INCLUDED_IN();
269
270 //TODO
271 // }else if (hasVernacular.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
272 // }else if (isAmbiregnalOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
273 // }else if (isAnamorphOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
274 // }else if (isFemaleParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
275 // }else if (isFirstParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
276 // }else if (isHybridChildOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
277 // }else if (isHybridParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
278 // }else if (isMaleParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
279 // }else if (isSecondParentOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
280 // }else if (isTeleomorphOf.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
281 // }else if (isVernacularFor.equals(tcsRelationshipCategory)){return TaxonRelationshipType.X;
282
283 }else {
284 throw new UnknownCdmTypeException("Unknown RelationshipCategory " + tcsRelationshipCategory);
285 }
286 }
287
288
289 /** Creates an cdm-NomenclaturalCode by the tcs NomenclaturalCode
290 */
291 public static NomenclaturalStatusType nomStatusString2NomStatus (String nomStatus) throws UnknownCdmTypeException{
292
293 if (nomStatus == null){ return null;
294 }else if ("Valid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.VALID();
295
296 }else if ("Alternative".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
297 }else if ("nom. altern.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ALTERNATIVE();
298
299 }else if ("Ambiguous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.AMBIGUOUS();
300
301 }else if ("Doubtful".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.DOUBTFUL();
302
303 }else if ("Confusum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONFUSUM();
304
305 }else if ("Illegitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
306 }else if ("nom. illeg.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ILLEGITIMATE();
307
308 }else if ("Superfluous".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
309 }else if ("nom. superfl.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SUPERFLUOUS();
310
311 }else if ("Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
312 }else if ("nom. rej.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED();
313
314 }else if ("Utique Rejected".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED();
315
316 }else if ("Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED_PROP();
317
318 }else if ("Orthography Conserved Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED_PROP();
319
320 }else if ("Legitimate".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.LEGITIMATE();
321
322 }else if ("Novum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
323 }else if ("nom. nov.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NOVUM();
324
325 }else if ("Utique Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.UTIQUE_REJECTED_PROP();
326
327 }else if ("Orthography Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.ORTHOGRAPHY_CONSERVED();
328
329 }else if ("Rejected Prop".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.REJECTED_PROP();
330
331 }else if ("Conserved".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
332 }else if ("nom. cons.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.CONSERVED();
333
334 }else if ("Sanctioned".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.SANCTIONED();
335
336 }else if ("Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
337 }else if ("nom. inval.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.INVALID();
338
339 }else if ("Nudum".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
340 }else if ("nom. nud.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.NUDUM();
341
342 }else if ("Combination Invalid".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.COMBINATION_INVALID();
343
344 }else if ("Provisional".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
345 }else if ("nom. provis.".equalsIgnoreCase(nomStatus)){return NomenclaturalStatusType.PROVISIONAL();
346 }
347 else {
348 throw new UnknownCdmTypeException("Unknown Nomenclatural status type " + nomStatus);
349 }
350 }
351
352
353 }