root/trunk/cdmlib/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/TaxonRelationshipType.java

Revision 13119, 20.2 kB (checked in by a.mueller, 8 months ago)

Symbols for relations (#2634)

  • Property svn:keywords set to Id
Line 
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
10package eu.etaxonomy.cdm.model.taxon;
11
12import java.util.HashMap;
13import java.util.List;
14import java.util.Map;
15import java.util.UUID;
16
17import javax.persistence.Entity;
18import javax.xml.bind.annotation.XmlAccessType;
19import javax.xml.bind.annotation.XmlAccessorType;
20import javax.xml.bind.annotation.XmlRootElement;
21import javax.xml.bind.annotation.XmlType;
22
23import org.apache.log4j.Logger;
24import org.hibernate.envers.Audited;
25import org.hibernate.search.annotations.Indexed;
26
27import eu.etaxonomy.cdm.model.common.DefinedTermBase;
28import eu.etaxonomy.cdm.model.common.Language;
29import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
30import eu.etaxonomy.cdm.model.common.Representation;
31import eu.etaxonomy.cdm.model.common.TermVocabulary;
32
33
34/**
35 * The class representing categories of {@link TaxonRelationship taxon relationships}
36 * (like "is congruent to" or "is misapplied name for").
37 * <P>
38 * A standard (ordered) list of taxon relationship type instances will be
39 * automatically created as the project starts. But this class allows to extend
40 * this standard list by creating new instances of additional taxon
41 * relationship types if needed.
42 * <P>
43 * This class corresponds in part to: <ul>
44 * <li> TaxonRelationshipTerm according to the TDWG ontology
45 * <li> RelationshipType according to the TCS
46 * </ul>
47 *
48 * @author m.doering
49 * @version 1.0
50 * @created 08-Nov-2007 13:06:17
51 */
52@XmlAccessorType(XmlAccessType.FIELD)
53@XmlType(name = "TaxonRelationshipType")
54@XmlRootElement(name = "TaxonRelationshipType")
55@Entity
56@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
57@Audited
58public class TaxonRelationshipType extends RelationshipTermBase<TaxonRelationshipType> {
59       
60        static Logger logger = Logger.getLogger(TaxonRelationshipType.class);
61
62        protected static Map<UUID, TaxonRelationshipType> termMap = null;               
63       
64        @Deprecated //will be removed in future versions. Use Classification/TaxonNode instead
65        private static final UUID uuidTaxonomicallyIncludedIn = UUID.fromString("d13fecdf-eb44-4dd7-9244-26679c05df1c");
66
67        private static final UUID uuidMisappliedNameFor = UUID.fromString("1ed87175-59dd-437e-959e-0d71583d8417");
68        private static final UUID uuidInvalidDesignationFor = UUID.fromString("605b1d01-f2b1-4544-b2e0-6f08def3d6ed");
69       
70        private static final UUID uuidContradiction = UUID.fromString("a8f03491-2ad6-4fae-a04c-2a4c117a2e9b");
71        private static final UUID uuidCongruentTo = UUID.fromString("60974c98-64ab-4574-bb5c-c110f6db634d");
72        private static final UUID uuidIncludes = UUID.fromString("0501c385-cab1-4fbe-b945-fc747419bb13");
73        private static final UUID uuidOverlaps = UUID.fromString("2046a0fd-4fd6-45a1-b707-2b91547f3ec7");
74        private static final UUID uuidExcludes = UUID.fromString("4535a63c-4a3f-4d69-9350-7bf02e2c23be");
75        private static final UUID uuidDoesNotExclude = UUID.fromString("0e5099bb-87c0-400e-abdc-bcfed5b5eece");
76        private static final UUID uuidDoesNotOverlap = UUID.fromString("ecd2382b-3d94-4169-9dd2-2c4ea1d24605");
77        private static final UUID uuidNotIncludedIn = UUID.fromString("89dffa4e-e004-4d42-b0d1-ae1827529e43");
78        private static final UUID uuidNotCongruentTo = UUID.fromString("6c16c33b-cfc5-4a00-92bd-a9f9e448f389");
79       
80       
81        private static final UUID uuidCongruentToOrIncludes = UUID.fromString("b55cb3a2-6e20-4ca3-95bc-12b59d3235b0");
82        private static final UUID uuidIncludedInOrIncludes = UUID.fromString("c3ed5089-6779-4051-bb24-f5ea0eca80d5");
83        private static final UUID uuidCongruentIncludedInOrIncludes = UUID.fromString("0170cd83-93ad-43c2-9ad1-7ac879300e2f");
84        private static final UUID uuidCongruentToOrOverlaps = UUID.fromString("78355cfa-5200-432f-8e00-82b97afad0ed");
85        private static final UUID uuidIncludesOrOverlaps = UUID.fromString("f1ec567b-3c73-436b-8625-b4fd53588abb");
86       
87        private static final UUID uuidCongruentToOrIncludesOrOverlaps = UUID.fromString("2d923b1a-6c0f-414c-ac9b-bbc502e18078");
88        private static final UUID uuidIncludedInOrIncludesOrOverlaps = UUID.fromString("43466aa9-e431-4f37-8bca-febfd9f63716");
89        private static final UUID uuidCongruentToOrExcludes = UUID.fromString("758e6cf3-05a0-49ed-9496-d8c4a9fd02ae");
90        private static final UUID uuidIncludesOrExcludes = UUID.fromString("6ee440bc-fd3d-4da2-ad85-906d35a94731");
91        private static final UUID uuidCongruentToOrIncludesOrExcludes = UUID.fromString("d5c6953d-aa53-46f8-aafc-ebc6428ad5d0");
92        private static final UUID uuidIncludedInOrIncludesOrExcludes = UUID.fromString("43d8492c-8bd5-4f38-a633-f1ad910a34dd");
93        private static final UUID uuidOverlapsOrExcludes = UUID.fromString("623ecdeb-ff1f-471d-a8dc-0d75b2fe8d94");
94        private static final UUID uuidCongruentToOrOverlapsOrExcludes = UUID.fromString("6fabef72-5264-44f1-bfc0-8e2e141375f2");
95        private static final UUID uuidIncludesOrOverlapsOrExcludes = UUID.fromString("b7153c89-cc6c-4f8c-bf74-216f10feac46");
96       
97        private static final UUID uuidAllRelationships = UUID.fromString("831fcd88-e5c9-49e0-b06e-bbb67d1c05c9");
98       
99       
100// ************* CONSTRUCTORS *************/   
101
102        /**
103         * Class constructor: creates a new empty taxon relationship type instance.
104         *
105         * @see         #TaxonRelationshipType(String, String, String, boolean, boolean)
106         */
107        public TaxonRelationshipType() {
108        }
109        /**
110         * Class constructor: creates an additional taxon relationship type
111         * instance with a description (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}), a label,
112         * a label abbreviation and the flags indicating whether this new taxon
113         * relationship type is symmetric and/or transitive.
114         *
115         * @param       term             the string (in the default language) describing the
116         *                                               new taxon relationship type to be created
117         * @param       label            the string identifying the new taxon relationship
118         *                                               type to be created
119         * @param       labelAbbrev  the string identifying (in abbreviated form) the
120         *                                               new taxon relationship type to be created
121         * @param       symmetric        the boolean indicating whether the new taxon
122         *                                               relationship type to be created is symmetric
123         * @param       transitive       the boolean indicating whether the new taxon
124         *                                               relationship type to be created is transitive
125         * @see                                  #TaxonRelationshipType()
126         */
127        public TaxonRelationshipType(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
128                super(term, label, labelAbbrev, symmetric, transitive);
129        }
130
131       
132//************************** METHODS ********************************
133       
134        /* (non-Javadoc)
135         * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
136         */
137        @Override
138        public void resetTerms(){
139                termMap = null;
140        }
141
142       
143        protected static TaxonRelationshipType getTermByUuid(UUID uuid){
144                if (termMap == null){
145                        return null;  //better return null then initialize the termMap in an unwanted way
146                }
147                return (TaxonRelationshipType)termMap.get(uuid);
148        }
149       
150       
151        /**
152         * Returns true, if this relationship type is not a <i>misapplied name for<i>
153         * and also no <i>taxonomically included in</i> relationship.<BR>
154         * It assumes that all other relationships are concept relationships.
155         * @return
156         */
157        public boolean isConceptRelationship(){
158                if (this.equals(MISAPPLIED_NAME_FOR())){
159                        return false;
160                }else if (this.equals(TAXONOMICALLY_INCLUDED_IN())){
161                        return false;
162                }
163                return true;
164        }
165
166        /**
167         * Returns the taxon relationship type "is taxonomically included in". This
168         * indicates that the {@link TaxonRelationship#getFromTaxon() source taxon}
169         * in such a {@link TaxonRelationship taxon relationship} has the target {@link Taxon taxon}
170         * as immediate next higher parent within the classification. Generally
171         * the {@link Taxon#getSec() concept reference} of both taxa are the same
172         * except if the concept reference follows the taxonomical opinion of
173         * another reference.<BR>
174         * This type is neither symmetric nor transitive.
175         * @deprecated will be removed in version 3.0
176         */
177        @Deprecated 
178        public static final TaxonRelationshipType TAXONOMICALLY_INCLUDED_IN(){
179                return getTermByUuid(uuidTaxonomicallyIncludedIn);
180        }
181        /**
182         * Returns the taxon relationship type "is misapplied name for". This
183         * indicates that the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} of the {@link TaxonRelationship#getFromTaxon() source taxon}
184         * in such a {@link TaxonRelationship taxon relationship} has been erroneously used by
185         * the {@link TaxonBase#getSec() concept reference} to denominate the same real taxon
186         * as the one meant by the target {@link Taxon taxon}.<BR>
187         * This type is neither symmetric nor transitive.
188         */
189        public static final TaxonRelationshipType MISAPPLIED_NAME_FOR(){
190                return getTermByUuid(uuidMisappliedNameFor);
191        }
192        /**
193         * Returns the taxon relationship type "is invalid designation for". This
194         * indicates that the {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon name} of the {@link TaxonRelationship#getFromTaxon() source taxon}
195         * in such a {@link TaxonRelationship taxon relationship} has
196         * {@link eu.etaxonomy.cdm.model.name.NomenclaturalStatusType#isInvalidType() not been validly published} but was intended to denominate
197         * a real taxon which is the same as the one meant by the target {@link Taxon taxon}.<BR>
198         * According to the nomenclature codes a not validly published taxon name is
199         * not a taxon name at all.<BR>
200         * This type is neither symmetric nor transitive.
201         */
202        public static final TaxonRelationshipType INVALID_DESIGNATION_FOR(){
203                return getTermByUuid(uuidInvalidDesignationFor);
204        }
205        /**
206         * Returns the (concept) taxon relationship type "is impossible"
207         * (contradiction). This is a concept relationship type which means that the
208         * circumscriptions (the set of organisms/specimens that belong to a {@link Taxon taxon}
209         * according to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
210         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
211         * beeing compared. In a concept relationship the concept references of the
212         * involved taxa must be distinct. <BR>
213         * The "is impossible" (contradiction) taxon relationship type arises
214         * logically if two or more incompatible (concept) taxon relationships
215         * between the two taxa already exist (for instance with the types
216         * "is congruent to" and "excludes").<BR>
217         * This type is symmetric but not transitive.
218         */
219        public static final TaxonRelationshipType CONTRADICTION(){
220                return getTermByUuid(uuidContradiction);
221        }
222        /**
223         * Returns the (concept) taxon relationship type "is congruent to".
224         * This is a concept relationship type which means that the circumscriptions
225         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
226         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
227         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
228         * beeing compared. In a concept relationship the concept references of the
229         * involved taxa must be distinct. <BR>
230         * The "is congruent to" taxon relationship type indicates that the
231         * circumscriptions of both taxa involved in the taxon relationship are
232         * identical.<BR>
233         * This type is symmetric and transitive.
234         */
235        public static final TaxonRelationshipType CONGRUENT_TO(){
236                return getTermByUuid(uuidCongruentTo);
237        }
238        /**
239         * Returns the (concept) taxon relationship type "includes".
240         * This is a concept relationship type which means that the circumscriptions
241         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
242         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
243         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
244         * beeing compared. In a concept relationship the concept references of the
245         * involved taxa must be distinct. <BR>
246         * The "includes" taxon relationship type indicates that each element
247         * belonging to the circumscription of the target taxon involved in the
248         * taxon relationship belongs to the circumscription of the source taxon,
249         * but that some elements belonging to the circumscription of the source
250         * taxon do not belong to the circumscription of the target taxon.<BR>
251         * This type is not symmetric but transitive.
252         */
253        public static final TaxonRelationshipType INCLUDES(){
254                return getTermByUuid(uuidIncludes);
255        }
256        /**
257         * Returns the (concept) taxon relationship type "overlaps".
258         * This is a concept relationship type which means that the circumscriptions
259         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
260         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
261         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
262         * beeing compared. In a concept relationship the concept references of the
263         * involved taxa must be distinct. <BR>
264         * The "overlaps" taxon relationship type indicates that both
265         * circumscriptions have common elements but that some elements belonging
266         * to the circumscription of the source taxon do not belong to the
267         * circumscription of the target taxon and vice-versa.<BR>
268         * This type is symmetric but not transitive.
269         */
270        public static final TaxonRelationshipType OVERLAPS(){
271                return getTermByUuid(uuidOverlaps);
272        }
273        /**
274         * Returns the (concept) taxon relationship type "excludes".
275         * This is a concept relationship type which means that the circumscriptions
276         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
277         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
278         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
279         * beeing compared. In a concept relationship the concept references of the
280         * involved taxa must be distinct. <BR>
281         * The "excludes" taxon relationship type indicates that both
282         * circumscriptions have no common elements.<BR>
283         * This type is symmetric but not transitive.
284         */
285        public static final TaxonRelationshipType EXCLUDES(){
286                return getTermByUuid(uuidExcludes);
287        }
288        /**
289         * Returns the (concept) taxon relationship type "does not exclude".
290         * This is a concept relationship type which means that the circumscriptions
291         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
292         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
293         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
294         * beeing compared. In a concept relationship the concept references of the
295         * involved taxa must be distinct. <BR>
296         * The "does not exclude" taxon relationship type indicates that both
297         * circumscriptions have common elements. This type is a generalisation of
298         * {@link #CONGRUENT_TO() "is congruent to"}, {@link #INCLUDES() "includes"} and {@link #OVERLAPS() "overlaps"}.<BR>
299         * This type is symmetric but not transitive.
300         *
301         * @see         #EXCLUDES()
302         */
303        public static final TaxonRelationshipType DOES_NOT_EXCLUDE(){
304                return getTermByUuid(uuidDoesNotExclude);
305        }
306        /**
307         * Returns the (concept) taxon relationship type "does not overlap".
308         * This is a concept relationship type which means that the circumscriptions
309         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
310         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
311         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
312         * beeing compared. In a concept relationship the concept references of the
313         * involved taxa must be distinct. <BR>
314         * The "does not overlap" taxon relationship type is a generalisation of
315         * {@link #CONGRUENT_TO() "is congruent to"}, {@link #INCLUDES() "includes"} and {@link #EXCLUDES() "excludes"}.<BR>
316         * This type is symmetric but not transitive.
317         *
318         * @see         #OVERLAPS()
319         */
320        public static final TaxonRelationshipType DOES_NOT_OVERLAP(){
321                return getTermByUuid(uuidDoesNotOverlap);
322        }
323        /**
324         * Returns the (concept) taxon relationship type "is not included in".
325         * This is a concept relationship type which means that the circumscriptions
326         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
327         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
328         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
329         * beeing compared. In a concept relationship the concept references of the
330         * involved taxa must be distinct. <BR>
331         * The "is not included in" taxon relationship type indicates that at least
332         * one element belonging to the circumscription of the source taxon involved
333         * in the taxon relationship does not belong to the circumscription of the
334         * target taxon. <BR>
335         * This type is neither symmetric nor transitive.
336         *
337         * @see         #INCLUDES()
338         */
339        public static final TaxonRelationshipType NOT_INCLUDED_IN(){
340                return getTermByUuid(uuidNotIncludedIn);
341        }
342        /**
343         * Returns the (concept) taxon relationship type "is not congruent to".
344         * This is a concept relationship type which means that the circumscriptions
345         * (the set of organisms/specimens that belong to a {@link Taxon taxon} according
346         * to the -maybe implicit- opinion of the {@link TaxonBase#getSec() concept reference})
347         * of both taxa involved in such a {@link TaxonRelationship taxon relationship} are
348         * beeing compared. In a concept relationship the concept references of the
349         * involved taxa must be distinct. <BR>
350         * The "is not congruent to" taxon relationship type indicates that at least
351         * one element belonging to one of both circumscriptions does not belong to
352         * the other circumscription. This type is a generalisation of
353         * {@link #INCLUDES() "includes"}, {@link #OVERLAPS() "overlaps"} and {@link #EXCLUDES() "excludes"}.<BR>
354         * This type is symmetric but not transitive.
355         *
356         * @see         #CONGRUENT_TO()
357         */
358        public static final TaxonRelationshipType NOT_CONGRUENT_TO(){
359                return getTermByUuid(uuidNotCongruentTo);
360        }
361
362        public static final TaxonRelationshipType CONGRUENT_OR_INCLUDES(){
363                return getTermByUuid(uuidCongruentToOrIncludes);
364        }
365        public static final TaxonRelationshipType INCLUDED_OR_INCLUDES(){
366                return getTermByUuid(uuidIncludedInOrIncludes);
367        }
368        public static final TaxonRelationshipType CONGRUENT_OR_INCLUDED_OR_INCLUDES(){
369                return getTermByUuid(uuidCongruentIncludedInOrIncludes);
370        }
371        public static final TaxonRelationshipType CONGRUENT_OR_OVERLAPS(){
372                return getTermByUuid(uuidCongruentToOrOverlaps);
373        }
374       
375        public static final TaxonRelationshipType INCLUDES_OR_OVERLAPS(){
376                return getTermByUuid(uuidIncludesOrOverlaps);
377        }
378
379        public static final TaxonRelationshipType CONGRUENT_OR_INCLUDES_OR_EXCLUDES(){
380                return getTermByUuid(uuidCongruentToOrIncludesOrExcludes);
381        }
382       
383        public static final TaxonRelationshipType INCLUDES_OR_EXCLUDES(){
384                return getTermByUuid(uuidIncludesOrExcludes);
385        }
386       
387        public static final TaxonRelationshipType CONGRUENT_OR_EXCLUDES(){
388                return getTermByUuid(uuidCongruentToOrExcludes);
389        }
390       
391        public static final TaxonRelationshipType INCLUDED_OR_INCLUDES_OR_OVERLAPS(){
392                return getTermByUuid(uuidIncludedInOrIncludesOrOverlaps);
393        }
394       
395        public static final TaxonRelationshipType CONGRUENT_OR_INCLUDES_OR_OVERLAPS(){
396                return getTermByUuid(uuidCongruentToOrIncludesOrOverlaps);
397        }
398       
399        public static final TaxonRelationshipType INCLUDES_OR_OVERLAPS_OR_EXCLUDES(){
400                return getTermByUuid(uuidIncludesOrOverlapsOrExcludes);
401        }
402       
403        public static final TaxonRelationshipType CONGRUENT_OR_OVERLAPS_OR_EXCLUDES(){
404                return getTermByUuid(uuidCongruentToOrOverlapsOrExcludes);
405        }
406       
407        public static final TaxonRelationshipType OVERLAPS_OR_EXCLUDES(){
408                return getTermByUuid(uuidOverlapsOrExcludes);
409        }
410       
411        public static final TaxonRelationshipType INCLUDED_OR_INCLUDES_OR_EXCLUDES(){
412                return getTermByUuid(uuidIncludedInOrIncludesOrExcludes);
413        }
414       
415        protected void setDefaultTerms(TermVocabulary<TaxonRelationshipType> termVocabulary) {
416                termMap = new HashMap<UUID, TaxonRelationshipType>();
417                for (TaxonRelationshipType term : termVocabulary.getTerms()){
418                        termMap.put(term.getUuid(), (TaxonRelationshipType)term);
419                }       
420        }
421
422        //TODO ohter relationshipTypes
423
424        public static final TaxonRelationshipType ALL_RELATIONSHIPS(){
425                return getTermByUuid(uuidAllRelationships);
426        }
427       
428        @Override
429        public TaxonRelationshipType readCsvLine(Class<TaxonRelationshipType> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms) {
430                return super.readCsvLine(termClass, csvLine, terms);
431        }
432}
Note: See TracBrowser for help on using the browser.