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.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
24
|
import org.hibernate.envers.Audited;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* The class representing categories of relationships between {@link DefinedTermBase terms}
|
31
|
* (like "is congruent to" or "is misapplied name for").
|
32
|
* <P>
|
33
|
* A standard (ordered) list of taxon relationship type instances will be
|
34
|
* automatically created as the project starts. But this class allows to extend
|
35
|
* this standard list by creating new instances of additional taxon
|
36
|
* relationship types if needed.
|
37
|
* <P>
|
38
|
* This class corresponds in part to: <ul>
|
39
|
* <li> TaxonRelationshipTerm according to the TDWG ontology
|
40
|
* <li> RelationshipType according to the TCS
|
41
|
* </ul>
|
42
|
*
|
43
|
* @author m.doering
|
44
|
* @since 08-Nov-2007 13:06:17
|
45
|
*/
|
46
|
/**
|
47
|
* @author a.mueller
|
48
|
* @since 28.02.2019
|
49
|
*
|
50
|
*/
|
51
|
@XmlAccessorType(XmlAccessType.FIELD)
|
52
|
@XmlType(name = "TermRelationshipType")
|
53
|
@XmlRootElement(name = "TermRelationshipType")
|
54
|
@Entity
|
55
|
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
|
56
|
//@Indexed(index = "eu.etaxonomy.cdm.model.common.DefinedTermBase")
|
57
|
@Audited
|
58
|
public class TermRelationshipType extends RelationshipTermBase<TermRelationshipType> {
|
59
|
private static final long serialVersionUID = 6575652105931691670L;
|
60
|
@SuppressWarnings("unused")
|
61
|
private static final Logger logger = LogManager.getLogger(TermRelationshipType.class);
|
62
|
|
63
|
protected static Map<UUID, TermRelationshipType> termMap = null;
|
64
|
|
65
|
private static final UUID uuidSameAs = UUID.fromString("c61f8e7e-6965-4975-8238-3a1269b093d2");
|
66
|
|
67
|
private static final UUID uuidPartOf = UUID.fromString("6ea378a9-d211-4a78-8b87-674db5c9118d");
|
68
|
private static final UUID uuidKindOf = UUID.fromString("9b6d38b3-9145-4302-9a46-92c7633aa013");
|
69
|
|
70
|
|
71
|
public static TermRelationshipType NewInstance(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
|
72
|
return new TermRelationshipType(term, label, labelAbbrev, symmetric, transitive);
|
73
|
}
|
74
|
|
75
|
|
76
|
//********************************** CONSTRUCTOR *********************************/
|
77
|
|
78
|
/**
|
79
|
* @deprecated for inner (hibernate) use only
|
80
|
*/
|
81
|
@Deprecated
|
82
|
protected TermRelationshipType() {
|
83
|
super(TermType.TermRelationType);
|
84
|
}
|
85
|
/**
|
86
|
* Class constructor: creates an additional term relationship type
|
87
|
* instance with a description (in the {@link eu.etaxonomy.cdm.model.common.Language#DEFAULT() default language}),
|
88
|
* a label, a label abbreviation and the flags indicating whether this new term
|
89
|
* relationship type is symmetric and/or transitive.
|
90
|
*
|
91
|
* @param term the string (in the default language) describing the
|
92
|
* new term relationship type to be created
|
93
|
* @param label the string identifying the new taxon relationship
|
94
|
* type to be created
|
95
|
* @param labelAbbrev the string identifying (in abbreviated form) the
|
96
|
* new term relationship type to be created
|
97
|
* @param symmetric the boolean indicating whether the new term
|
98
|
* relationship type to be created is symmetric
|
99
|
* @param transitive the boolean indicating whether the new term
|
100
|
* relationship type to be created is transitive
|
101
|
* @see #TermRelationshipType()
|
102
|
*/
|
103
|
private TermRelationshipType(String term, String label, String labelAbbrev, boolean symmetric, boolean transitive) {
|
104
|
super(TermType.TaxonRelationshipType, term, label, labelAbbrev, symmetric, transitive);
|
105
|
}
|
106
|
|
107
|
|
108
|
//************************** METHODS ********************************
|
109
|
|
110
|
@Override
|
111
|
public void resetTerms(){
|
112
|
termMap = null;
|
113
|
}
|
114
|
|
115
|
protected static TermRelationshipType getTermByUuid(UUID uuid){
|
116
|
if (termMap == null || termMap.isEmpty()){
|
117
|
return getTermByClassAndUUID(TermRelationshipType.class, uuid);
|
118
|
} else {
|
119
|
return termMap.get(uuid);
|
120
|
}
|
121
|
}
|
122
|
|
123
|
|
124
|
/**
|
125
|
* Returns the term relationship type "is same as". This
|
126
|
* indicates that the 2 terms linked in the term relationship
|
127
|
* are considered to be equivalent/congruent.
|
128
|
* This type is both symmetric and transitive.
|
129
|
*/
|
130
|
@Deprecated
|
131
|
public static final TermRelationshipType SAME_AS(){
|
132
|
return getTermByUuid(uuidSameAs);
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* Returns the term relationship type "is part of". This
|
137
|
* indicates that the concept represented by the first ("from") term
|
138
|
* is considered to be part of the second ("to") term.<BR>
|
139
|
* E.g. a country is considered to be part of a continent.<BR>
|
140
|
* It also means that both terms must not be of the exact
|
141
|
* same type, e.g. a leaf is not considered to be a plant
|
142
|
* but is part of a plant.<BR>
|
143
|
*
|
144
|
* This type is transitive but not symmetric.
|
145
|
*
|
146
|
* @see #KIND_OF()
|
147
|
*/
|
148
|
public static final TermRelationshipType PART_OF(){
|
149
|
return getTermByUuid(uuidPartOf);
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* Returns the term relationship type "is kind of". This
|
154
|
* indicates that the concept represented by the first ("from") term
|
155
|
* is considered to be of a similar but more specific type as the second ("to") term.<BR>
|
156
|
*
|
157
|
* E.g. a tree is considered to be a plant but a specific type of plant.
|
158
|
* Or for more abstract terms, a homotypic synonym relation is
|
159
|
* considered to be a synonym relation but a specific synonym relation.
|
160
|
* So often kind-of terms define certain properties to define sets
|
161
|
* of objects having this property. The more specific term then defines
|
162
|
* less objects then the more general one.<BR>
|
163
|
* In this way {@link #KIND_OF()} is complementary to {@link #PART_OF()}
|
164
|
* Both of them can usually not be true at the same time.
|
165
|
*
|
166
|
* This type is transitive but not symmetric.
|
167
|
*
|
168
|
* @see #PART_OF()
|
169
|
*/
|
170
|
public static final TermRelationshipType KIND_OF(){
|
171
|
return getTermByUuid(uuidKindOf);
|
172
|
}
|
173
|
|
174
|
|
175
|
|
176
|
@Override
|
177
|
protected void setDefaultTerms(TermVocabulary<TermRelationshipType> termVocabulary) {
|
178
|
termMap = new HashMap<>();
|
179
|
for (TermRelationshipType term : termVocabulary.getTerms()){
|
180
|
termMap.put(term.getUuid(), term);
|
181
|
}
|
182
|
}
|
183
|
|
184
|
|
185
|
@Override
|
186
|
public TermRelationshipType readCsvLine(Class<TermRelationshipType> termClass,
|
187
|
List<String> csvLine, TermType termType, Map<UUID,DefinedTermBase> terms, boolean abbrevAsId) {
|
188
|
|
189
|
TermRelationshipType newInstance = super.readCsvLine(termClass, csvLine, termType, terms, abbrevAsId);
|
190
|
newInstance.setSymbol(newInstance.getIdInVocabulary());
|
191
|
String inverseLabelAbbrev = csvLine.get(7).trim();
|
192
|
newInstance.setInverseSymbol(inverseLabelAbbrev);
|
193
|
return newInstance;
|
194
|
}
|
195
|
}
|