1
15
16 package gate.wordnet;
17
18 import net.didion.jwnl.data.POS;
19 import net.didion.jwnl.data.PointerType;
20
21
22 final class WNHelper {
23
24 private WNHelper() {
25 }
26
27
28 public static POS int2POS(int pos) {
29
30 POS result = null;
31
32 switch(pos) {
33
34 case WordNet.POS_ADJECTIVE:
35 result = POS.ADJECTIVE;
36 break;
37
38 case WordNet.POS_ADVERB:
39 result = POS.ADVERB;
40 break;
41
42 case WordNet.POS_NOUN:
43 result = POS.NOUN;
44 break;
45
46 case WordNet.POS_VERB:
47 result = POS.VERB;
48 break;
49
50 default:
51 throw new IllegalArgumentException();
52 }
53
54 return result;
55 }
56
57
58 public static int POS2int(POS pos) {
59
60 int result;
61
62 if (pos.equals(POS.ADJECTIVE)) {
64 result = WordNet.POS_ADJECTIVE;
65 }
66 else if (pos.equals(POS.ADVERB)) {
67 result = WordNet.POS_ADVERB;
68 }
69 else if (pos.equals(POS.NOUN)) {
70 result = WordNet.POS_NOUN;
71 }
72 else if (pos.equals(POS.VERB)) {
73 result = WordNet.POS_VERB;
74 }
75 else {
76 throw new IllegalArgumentException();
77 }
78
79 return result;
80 }
81
82
83
84 public static int PointerType2int(PointerType pt) {
85
86 if (null == pt) {
88 throw new IllegalArgumentException();
89 }
90
91 if (pt.equals(PointerType.ANTONYM)) {
92 return Relation.REL_ANTONYM;
93 }
94 else if (pt.equals(PointerType.ATTRIBUTE)) {
95 return Relation.REL_ATTRIBUTE;
96 }
97 else if (pt.equals(PointerType.CAUSE)) {
98 return Relation.REL_CAUSE;
99 }
100 else if (pt.equals(PointerType.DERIVED)) {
101 return Relation.REL_DERIVED_FROM_ADJECTIVE;
102 }
103 else if (pt.equals(PointerType.ENTAILMENT)) {
104 return Relation.REL_ENTAILMENT;
105 }
106 else if (pt.equals(PointerType.HYPERNYM)) {
107 return Relation.REL_HYPERNYM;
108 }
109 else if (pt.equals(PointerType.HYPONYM)) {
110 return Relation.REL_HYPONYM;
111 }
112 else if (pt.equals(PointerType.MEMBER_HOLONYM)) {
113 return Relation.REL_MEMBER_HOLONYM;
114 }
115 else if (pt.equals(PointerType.MEMBER_MERONYM)) {
116 return Relation.REL_MEMBER_MERONYM;
117 }
118 else if (pt.equals(PointerType.PARTICIPLE_OF)) {
119 return Relation.REL_PARTICIPLE_OF_VERB;
120 }
121 else if (pt.equals(PointerType.PART_HOLONYM)) {
122 return Relation.REL_PART_HOLONYM;
123 }
124 else if (pt.equals(PointerType.PART_MERONYM)) {
125 return Relation.REL_PART_MERONYM;
126 }
127 else if (pt.equals(PointerType.SIMILAR_TO)) {
128 return Relation.REL_SIMILAR_TO;
129 }
130 else if (pt.equals(PointerType.SEE_ALSO)) {
131 return Relation.REL_SEE_ALSO;
132 }
133 else if (pt.equals(PointerType.SUBSTANCE_MERONYM)) {
134 return Relation.REL_SUBSTANCE_MERONYM;
135 }
136 else if (pt.equals(PointerType.SUBSTANCE_HOLONYM)) {
137 return Relation.REL_SUBSTANCE_HOLONYM;
138 }
139 else if (pt.equals(PointerType.VERB_GROUP)) {
140 return Relation.REL_VERB_GROUP;
141 }
142 else{
143 throw new IllegalArgumentException();
144 }
145
146 }
147
148
149
150 public static PointerType int2PointerType(int type) {
151
152 switch(type) {
153
154 case Relation.REL_ANTONYM:
155 return PointerType.ANTONYM;
156
157 case Relation.REL_ATTRIBUTE:
158 return PointerType.ATTRIBUTE;
159
160 case Relation.REL_CAUSE:
161 return PointerType.CAUSE;
162
163 case Relation.REL_DERIVED_FROM_ADJECTIVE:
164 return PointerType.DERIVED;
165
166 case Relation.REL_ENTAILMENT:
167 return PointerType.ENTAILMENT;
168
169 case Relation.REL_HYPERNYM:
170 return PointerType.HYPERNYM;
171
172 case Relation.REL_HYPONYM:
173 return PointerType.HYPONYM;
174
175 case Relation.REL_MEMBER_HOLONYM:
176 return PointerType.MEMBER_HOLONYM;
177
178 case Relation.REL_MEMBER_MERONYM:
179 return PointerType.MEMBER_MERONYM;
180
181 case Relation.REL_PARTICIPLE_OF_VERB:
182 return PointerType.PARTICIPLE_OF;
183
184 case Relation.REL_PART_HOLONYM:
185 return PointerType.PART_HOLONYM;
186
187 case Relation.REL_PART_MERONYM:
188 return PointerType.PART_MERONYM;
189
190 case Relation.REL_PERTAINYM:
191 return null;
192
193 case Relation.REL_SEE_ALSO:
194 return PointerType.SEE_ALSO;
195
196 case Relation.REL_SIMILAR_TO:
197 return PointerType.SIMILAR_TO;
198
199 case Relation.REL_SUBSTANCE_HOLONYM:
200 return PointerType.SUBSTANCE_HOLONYM;
201
202 case Relation.REL_SUBSTANCE_MERONYM:
203 return PointerType.SUBSTANCE_MERONYM;
204
205 case Relation.REL_VERB_GROUP:
206 return PointerType.VERB_GROUP;
207
208 default:
209 throw new IllegalArgumentException();
210 }
211 }
212
213
214 public static boolean isValidSemanticPointer(int _type) {
215 return _type == Relation.REL_ATTRIBUTE ||
216 _type == Relation.REL_CAUSE ||
217 _type == Relation.REL_ENTAILMENT ||
219 _type == Relation.REL_HYPERNYM ||
220 _type == Relation.REL_HYPONYM ||
221 _type == Relation.REL_MEMBER_HOLONYM ||
222 _type == Relation.REL_MEMBER_MERONYM ||
223 _type == Relation.REL_PART_HOLONYM ||
224 _type == Relation.REL_PART_MERONYM ||
225 _type == Relation.REL_SIMILAR_TO ||
226 _type == Relation.REL_SUBSTANCE_HOLONYM ||
227 _type == Relation.REL_SUBSTANCE_MERONYM ||
228 _type == Relation.REL_SEE_ALSO ||
229 _type == Relation.REL_VERB_GROUP;
230 }
231
232
233 public static boolean isValidLexicalPointer(int _type) {
234 return _type == Relation.REL_ANTONYM ||
235 _type == Relation.REL_PERTAINYM ||
236 _type == Relation.REL_PARTICIPLE_OF_VERB ||
237 _type == Relation.REL_SEE_ALSO ||
238 _type == Relation.REL_DERIVED_FROM_ADJECTIVE;
239 }
240
241
242
243 public static int AdjPosition2int(net.didion.jwnl.data.Adjective adj) {
244
245 int result;
246
247 if (adj.getAdjectivePosition().equals(net.didion.jwnl.data.Adjective.ATTRIBUTIVE)) {
248 result = Adjective.ADJ_POS_ATTRIBUTIVE;
249 }
250 else if (adj.getAdjectivePosition().equals(net.didion.jwnl.data.Adjective.IMMEDIATE_POSTNOMINAL)) {
251 result = Adjective.ADJ_POS_IMMEDIATE_POSTNOMINAL;
252 }
253 else if (adj.getAdjectivePosition().equals(net.didion.jwnl.data.Adjective.NONE)) {
254 result = Adjective.ADJ_POS_NONE;
255 }
256 else if (adj.getAdjectivePosition().equals(net.didion.jwnl.data.Adjective.PREDICATIVE)) {
257 result = Adjective.ADJ_POS_PREDICATIVE;
258 }
259 else {
260 throw new IllegalArgumentException();
261 }
262
263 return result;
264 }
265 }