Project

General

Profile

Revision 7c4fffcd

ID7c4fffcd2968d8ab532afba95cdbb4864a3357ec
Parent 2f8559af
Child cafaa5dd

Added by Andreas Müller 12 months ago

ref #6794 add TermRelationshipType

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermRelationshipType.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.model.term;
11

  
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

  
17
import javax.persistence.Entity;
18
import javax.xml.bind.annotation.XmlAccessType;
19
import javax.xml.bind.annotation.XmlAccessorType;
20
import javax.xml.bind.annotation.XmlRootElement;
21
import javax.xml.bind.annotation.XmlType;
22

  
23
import org.apache.log4j.Logger;
24
import org.hibernate.envers.Audited;
25

  
26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
27
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
28
import eu.etaxonomy.cdm.model.common.TermType;
29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30

  
31

  
32
/**
33
 * The class representing categories of relationships between {@link DefinedTermBase terms}
34
 * (like "is congruent to" or "is misapplied name for").
35
 * <P>
36
 * A standard (ordered) list of taxon relationship type instances will be
37
 * automatically created as the project starts. But this class allows to extend
38
 * this standard list by creating new instances of additional taxon
39
 * relationship types if needed.
40
 * <P>
41
 * This class corresponds in part to: <ul>
42
 * <li> TaxonRelationshipTerm according to the TDWG ontology
43
 * <li> RelationshipType according to the TCS
44
 * </ul>
45
 *
46
 * @author m.doering
47
 * @since 08-Nov-2007 13:06:17
48
 */
49
/**
50
 * @author a.mueller
51
 * @since 28.02.2019
52
 *
53
 */
54
@XmlAccessorType(XmlAccessType.FIELD)
55
@XmlType(name = "TermRelationshipType")
56
@XmlRootElement(name = "TermRelationshipType")
57
@Entity
58
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
59
//@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
60
@Audited
61
public class TermRelationshipType extends RelationshipTermBase<TermRelationshipType> {
62
	private static final long serialVersionUID = 6575652105931691670L;
63
	@SuppressWarnings("unused")
64
	private static final Logger logger = Logger.getLogger(TermRelationshipType.class);
65

  
66
	protected static Map<UUID, TermRelationshipType> termMap = null;
67

  
68
	private static final UUID uuidSameAs = UUID.fromString("c61f8e7e-6965-4975-8238-3a1269b093d2");
69

  
70
	private static final UUID uuidPartOf = UUID.fromString("6ea378a9-d211-4a78-8b87-674db5c9118d");
71
	private static final UUID uuidKindOf = UUID.fromString("9b6d38b3-9145-4302-9a46-92c7633aa013");
72

  
73

  
74
	public static TermRelationshipType NewInstance(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
75
		return new TermRelationshipType(term, label, labelAbbrev, symmetric, transitive);
76
	}
77

  
78

  
79
//********************************** CONSTRUCTOR *********************************/
80

  
81
  	/**
82
  	 * @deprecated for inner (hibernate) use only
83
  	 */
84
  	@Deprecated
85
  	protected TermRelationshipType() {
86
		super(TermType.TermRelationshipType);
87
	}
88
	/**
89
	 * Class constructor: creates an additional term relationship type
90
	 * instance with a description (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}),
91
	 * a label, a label abbreviation and the flags indicating whether this new term
92
	 * relationship type is symmetric and/or transitive.
93
	 *
94
	 * @param	term  		 the string (in the default language) describing the
95
	 * 						 new term relationship type to be created
96
	 * @param	label  		 the string identifying the new taxon relationship
97
	 * 						 type to be created
98
	 * @param	labelAbbrev  the string identifying (in abbreviated form) the
99
	 * 						 new term relationship type to be created
100
	 * @param	symmetric	 the boolean indicating whether the new term
101
	 * 						 relationship type to be created is symmetric
102
	 * @param	transitive	 the boolean indicating whether the new term
103
	 * 						 relationship type to be created is transitive
104
	 * @see 				 #TermRelationshipType()
105
	 */
106
	private TermRelationshipType(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
107
		super(TermType.TaxonRelationshipType, term, label, labelAbbrev, symmetric, transitive);
108
	}
109

  
110

  
111
//************************** METHODS ********************************
112

  
113
	@Override
114
	public void resetTerms(){
115
		termMap = null;
116
	}
117

  
118
	protected static TermRelationshipType getTermByUuid(UUID uuid){
119
	    if (termMap == null || termMap.isEmpty()){
120
            return getTermByClassAndUUID(TermRelationshipType.class, uuid);
121
        } else {
122
            return termMap.get(uuid);
123
        }
124
	}
125

  
126

  
127
	/**
128
	 * Returns the term relationship type "is same as". This
129
	 * indicates that the 2 terms linked in the term relationship
130
	 * are considered to be equivalent/congruent.
131
	 * This type is both symmetric and transitive.
132
	 */
133
	@Deprecated
134
	public static final TermRelationshipType SAME_AS(){
135
		return getTermByUuid(uuidSameAs);
136
	}
137

  
138
	/**
139
	 * Returns the term relationship type "is part of". This
140
	 * indicates that the concept represented by the first ("from") term
141
	 * is considered to be part of the second ("to") term.<BR>
142
	 * E.g. a country is considered to be part of a continent.<BR>
143
	 * It also means that both terms must not be of the exact
144
	 * same type, e.g. a leaf is not considered to be a plant
145
	 * but is part of a plant.<BR>
146
	 *
147
	 * This type is transitive but not symmetric.
148
	 *
149
	 * @see #KIND_OF()
150
	 */
151
	public static final TermRelationshipType PART_OF(){
152
		return getTermByUuid(uuidPartOf);
153
	}
154

  
155
	/**
156
     * Returns the term relationship type "is kind of". This
157
     * indicates that the concept represented by the first ("from") term
158
     * is considered to be of a similar but more specific type as the second ("to") term.<BR>
159
     *
160
     * E.g. a tree is considered to be a plant but a specific type of plant.
161
     * Or for more abstract terms, a homotypic synonym relation is
162
     * considered to be a synonym relation but a specific synonym relation.
163
     * So often kind-of terms define certain properties to define sets
164
     * of objects having this property. The more specific term then defines
165
     * less objects then the more general one.<BR>
166
     * In this way {@link #KIND_OF()} is complementary to {@link #PART_OF()}
167
     * Both of them can usually not be true at the same time.
168
     *
169
     * This type is transitive but not symmetric.
170
     *
171
     * @see #PART_OF()
172
     */
173
	public static final TermRelationshipType KIND_OF(){
174
		return getTermByUuid(uuidKindOf);
175
	}
176

  
177

  
178

  
179
	@Override
180
    protected void setDefaultTerms(TermVocabulary<TermRelationshipType> termVocabulary) {
181
		termMap = new HashMap<>();
182
		for (TermRelationshipType term : termVocabulary.getTerms()){
183
			termMap.put(term.getUuid(), term);
184
		}
185
	}
186

  
187

  
188
    @Override
189
    public TermRelationshipType readCsvLine(Class<TermRelationshipType> termClass,
190
            List<String> csvLine, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
191

  
192
        TermRelationshipType newInstance = super.readCsvLine(termClass, csvLine, terms, abbrevAsId);
193
        newInstance.setSymbol(newInstance.getIdInVocabulary());
194
        String inverseLabelAbbrev = csvLine.get(7).trim();
195
        newInstance.setInverseSymbol(inverseLabelAbbrev);
196
        return newInstance;
197
    }
198
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermType.java
596 596
    public static TermType getByUuid(UUID uuid) {return delegateVoc.getByUuid(uuid);}
597 597

  
598 598
}
599

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/VocabularyEnum.java
37 37
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
38 38
import eu.etaxonomy.cdm.model.taxon.SynonymType;
39 39
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
40
import eu.etaxonomy.cdm.model.term.TermRelationshipType;
40 41

  
41 42
/**
42 43
 * @author n.hoffmann
......
59 60
	HybridRelationshipType("fc4abe52-9c25-4cfa-a682-8615bf4bbf07", HybridRelationshipType.class),
60 61
	NameRelationshipType("6878cb82-c1a4-4613-b012-7e73b413c8cd", NameRelationshipType.class),
61 62
	TaxonRelationshipType("15db0cf7-7afc-4a86-a7d4-221c73b0c9ac", TaxonRelationshipType.class),
62
	MarkerType("19dffff7-e142-429c-a420-5d28e4ebe305", MarkerType.class),
63
	TermRelationshipType("4e5bb743-5ddf-4ee2-b893-36fbd386a5ee", TermRelationshipType.class),
64
    MarkerType("19dffff7-e142-429c-a420-5d28e4ebe305", MarkerType.class),
63 65
	AnnotationType("ca04609b-1ba0-4d31-9c2e-aa8eb2f4e62d", AnnotationType.class),
64 66
	Feature("b187d555-f06f-4d65-9e53-da7c93f8eaa8", Feature.class),
65 67
	NameFeature("a7ca3eef-4092-49e1-beec-ed5096193e5e", Feature.class),
cdmlib-model/src/main/resources/terms/TermRelationshipType.csv
1
"4e5bb743-5ddf-4ee2-b893-36fbd386a5ee",,"Term Relationship Type","Term Relationship Type","TERT","0"
2
"c61f8e7e-6965-4975-8238-3a1269b093d2",,"is same as","is same as","","is same as","is same as","",TRUE,TRUE
3
"6ea378a9-d211-4a78-8b87-674db5c9118d",,"is part of ","is part of","","has part","has part","",FALSE,TRUE
4
"9b6d38b3-9145-4302-9a46-92c7633aa013",,"is kind of","is kind of","","is generalization of","is generalization of","",FALSE,TRUE

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)