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