Skip to content

Commit 64d8bb5

Browse files
committed
Merge PR #1155 head update into the gRPC helper base
2 parents 1753093 + 9c0e9a0 commit 64d8bb5

17 files changed

Lines changed: 1852 additions & 67 deletions

File tree

dev/test-omw-wordnets.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
readonly RELEASE_URL="https://github.com/omwn/omw-data/releases/download/v2.0"
20+
readonly IT_SHA512="d0ed09eaa6617509a7c8a1162e92d8085570328f5f773a108a168d7c517b02c8a1a79fe81297b7e94722b480b22f44f34419c46675f0c3e3af253504c2c5b380"
21+
readonly ES_SHA512="86851763f10cf9ba1c5ea42e8c09bcbff7954aea22c62fbd229bcf546f236de4d67251582ecfd7956e8dae22e975fdf1d5bfa3fd7e2fbf4d901751c89bc0ca66"
22+
readonly SV_SHA512="897a79c6a6ec43c10024c6ee55aac886bd27182e28127ef1248cc8748c1189e573b05b0b2cd9ada91756f0527b25cbac9a49b88a1f13a897f5442da7f0656c13"
23+
24+
fixture_dir=$(mktemp -d "${TMPDIR:-/tmp}/opennlp-omw.XXXXXXXX")
25+
trap 'rm -rf -- "$fixture_dir"' EXIT
26+
27+
fetch() {
28+
local language=$1
29+
local expected=$2
30+
local archive="$fixture_dir/omw-$language-2.0.tar.xz"
31+
curl --fail --location --silent --show-error \
32+
--connect-timeout 15 --max-time 120 \
33+
--output "$archive" "$RELEASE_URL/omw-$language-2.0.tar.xz"
34+
local actual
35+
actual=$(sha512sum "$archive" | cut -d' ' -f1)
36+
if [[ "$actual" != "$expected" ]]; then
37+
echo "SHA-512 mismatch for omw-$language-2.0.tar.xz" >&2
38+
exit 1
39+
fi
40+
tar -xJf "$archive" -C "$fixture_dir"
41+
}
42+
43+
fetch it "$IT_SHA512"
44+
fetch es "$ES_SHA512"
45+
fetch sv "$SV_SHA512"
46+
47+
repo_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
48+
cd "$repo_dir"
49+
./mvnw -pl opennlp-extensions/opennlp-wordnet -am \
50+
-Dopennlp.forkCount=1 -Drat.skip=true \
51+
-Dtest=WnLmfOmwIntegrationTest -Dsurefire.failIfNoSpecifiedTests=false \
52+
-Dopennlp.wordnet.omwDir="$fixture_dir" test

opennlp-api/src/main/java/opennlp/tools/wordnet/Synset.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
* empty.
4040
* @param pos The part of speech. Must not be {@code null}.
4141
* @param lemmas The member lemmas in source order, human-readable (multiword lemmas use
42-
* spaces, not the underscores some formats store). Must not be {@code null} or
43-
* empty, and must not contain {@code null} or empty elements.
42+
* spaces, not the underscores some formats store). Must not be {@code null} and
43+
* must not contain {@code null} or empty elements. May be empty for an
44+
* unlexicalized concept retained as a relation target.
4445
* @param gloss The definition text, possibly empty when the source has none. Must not be
4546
* {@code null}.
4647
* @param relations The typed relations, each mapping to the target synset ids in source order.
@@ -67,8 +68,8 @@ public record Synset(
6768
if (pos == null) {
6869
throw new IllegalArgumentException("Pos must not be null");
6970
}
70-
if (lemmas == null || lemmas.isEmpty()) {
71-
throw new IllegalArgumentException("Lemmas must not be null or empty for synset " + id);
71+
if (lemmas == null) {
72+
throw new IllegalArgumentException("Lemmas must not be null for synset " + id);
7273
}
7374
for (final String lemma : lemmas) {
7475
if (lemma == null || lemma.isEmpty()) {

opennlp-api/src/main/java/opennlp/tools/wordnet/WordNetRelation.java

Lines changed: 239 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
* <p>Relations that a source format draws between individual word senses (antonymy and
2424
* derivation, for example) surface here at the synset level: the synset containing the source
2525
* sense carries the relation to the synset containing the target sense.</p>
26+
*
27+
* <p>The vocabulary includes every typed synset and sense relation in the
28+
* <a href="https://globalwordnet.github.io/schemas/WN-LMF-1.4.dtd">Global WordNet Association
29+
* WN-LMF 1.4 format</a>. Format-specific readers document any contextual mapping.</p>
2630
*/
2731
public enum WordNetRelation {
2832

@@ -111,5 +115,239 @@ public enum WordNetRelation {
111115
DOMAIN_USAGE,
112116

113117
/** A synset belonging to this usage domain. */
114-
MEMBER_OF_DOMAIN_USAGE
118+
MEMBER_OF_DOMAIN_USAGE,
119+
120+
/** An entity that intentionally performs or initiates an event. */
121+
AGENT,
122+
123+
/** A state that this concept enters or occupies. */
124+
BE_IN_STATE,
125+
126+
/** A semantic class that classifies this concept. */
127+
CLASSIFIED_BY,
128+
129+
/** A concept classified by this semantic class. */
130+
CLASSIFIES,
131+
132+
/** An instrument that participates with this agent. */
133+
CO_AGENT_INSTRUMENT,
134+
135+
/** A patient that participates with this agent. */
136+
CO_AGENT_PATIENT,
137+
138+
/** A result that participates with this agent. */
139+
CO_AGENT_RESULT,
140+
141+
/** An agent that participates with this instrument. */
142+
CO_INSTRUMENT_AGENT,
143+
144+
/** A patient that participates with this instrument. */
145+
CO_INSTRUMENT_PATIENT,
146+
147+
/** A result that participates with this instrument. */
148+
CO_INSTRUMENT_RESULT,
149+
150+
/** An agent that participates with this patient. */
151+
CO_PATIENT_AGENT,
152+
153+
/** An instrument that participates with this patient. */
154+
CO_PATIENT_INSTRUMENT,
155+
156+
/** An agent that participates with this result. */
157+
CO_RESULT_AGENT,
158+
159+
/** An instrument that participates with this result. */
160+
CO_RESULT_INSTRUMENT,
161+
162+
/** A semantic role that participates with this role. */
163+
CO_ROLE,
164+
165+
/** A direction associated with an event or entity. */
166+
DIRECTION,
167+
168+
/** An equivalent synonym relation from WN-LMF. */
169+
EQ_SYNONYM,
170+
171+
/** The location whole that contains this concept. */
172+
LOCATION_HOLONYM,
173+
174+
/** The portion whole that contains this concept. */
175+
PORTION_HOLONYM,
176+
177+
/** A whole related by an unspecified holonym relation. */
178+
HOLONYM,
179+
180+
/** The manner in which this concept occurs. */
181+
IN_MANNER,
182+
183+
/** An instrument used in an event. */
184+
INSTRUMENT,
185+
186+
/** A location associated with an entity or event. */
187+
LOCATION,
188+
189+
/** An event or situation in which this concept is involved. */
190+
INVOLVED,
191+
192+
/** The agent involved in an event. */
193+
INVOLVED_AGENT,
194+
195+
/** The direction involved in an event. */
196+
INVOLVED_DIRECTION,
197+
198+
/** The instrument involved in an event. */
199+
INVOLVED_INSTRUMENT,
200+
201+
/** The location involved in an event. */
202+
INVOLVED_LOCATION,
203+
204+
/** The patient involved in an event. */
205+
INVOLVED_PATIENT,
206+
207+
/** The result involved in an event. */
208+
INVOLVED_RESULT,
209+
210+
/** The source direction involved in an event. */
211+
INVOLVED_SOURCE_DIRECTION,
212+
213+
/** The target direction involved in an event. */
214+
INVOLVED_TARGET_DIRECTION,
215+
216+
/** A synonym relation that is intentionally irregular or non-equivalent. */
217+
IR_SYNONYM,
218+
219+
/** An event of which this concept is a subevent. */
220+
IS_SUBEVENT_OF,
221+
222+
/** An event for which this concept specifies the manner. */
223+
MANNER_OF,
224+
225+
/** A location part contained by this concept. */
226+
LOCATION_MERONYM,
227+
228+
/** A portion contained by this concept. */
229+
PORTION_MERONYM,
230+
231+
/** A part related by an unspecified meronym relation. */
232+
MERONYM,
233+
234+
/** An entity affected by an event. */
235+
PATIENT,
236+
237+
/** A concept that restricts this concept. */
238+
RESTRICTED_BY,
239+
240+
/** A concept restricted by this concept. */
241+
RESTRICTS,
242+
243+
/** A result produced by an event. */
244+
RESULT,
245+
246+
/** A semantic role associated with an event. */
247+
ROLE,
248+
249+
/** The source direction of an event. */
250+
SOURCE_DIRECTION,
251+
252+
/** An event or entity for which this concept is a state. */
253+
STATE_OF,
254+
255+
/** An event contained within this event. */
256+
SUBEVENT,
257+
258+
/** The target direction of an event. */
259+
TARGET_DIRECTION,
260+
261+
/** A feminine form related to this concept. */
262+
FEMININE,
263+
264+
/** A concept whose feminine form is this concept. */
265+
HAS_FEMININE,
266+
267+
/** A masculine form related to this concept. */
268+
MASCULINE,
269+
270+
/** A concept whose masculine form is this concept. */
271+
HAS_MASCULINE,
272+
273+
/** A young form related to this concept. */
274+
YOUNG,
275+
276+
/** A concept whose young form is this concept. */
277+
HAS_YOUNG,
278+
279+
/** A diminutive form related to this concept. */
280+
DIMINUTIVE,
281+
282+
/** A concept whose diminutive form is this concept. */
283+
HAS_DIMINUTIVE,
284+
285+
/** An augmentative form related to this concept. */
286+
AUGMENTATIVE,
287+
288+
/** A concept whose augmentative form is this concept. */
289+
HAS_AUGMENTATIVE,
290+
291+
/** A gradable antonym relation. */
292+
ANTO_GRADABLE,
293+
294+
/** A simple antonym relation. */
295+
ANTO_SIMPLE,
296+
297+
/** A converse antonym relation. */
298+
ANTO_CONVERSE,
299+
300+
/** A simple imperfective-to-perfective aspect relation. */
301+
SIMPLE_ASPECT_IP,
302+
303+
/** A secondary imperfective-to-perfective aspect relation. */
304+
SECONDARY_ASPECT_IP,
305+
306+
/** A simple perfective-to-imperfective aspect relation. */
307+
SIMPLE_ASPECT_PI,
308+
309+
/** A secondary perfective-to-imperfective aspect relation. */
310+
SECONDARY_ASPECT_PI,
311+
312+
/** A metaphorically related sense. */
313+
METAPHOR,
314+
315+
/** A sense for which this sense is a metaphor. */
316+
HAS_METAPHOR,
317+
318+
/** A metonymically related sense. */
319+
METONYM,
320+
321+
/** A sense for which this sense is a metonym. */
322+
HAS_METONYM,
323+
324+
/** The material associated with an entity or event. */
325+
MATERIAL,
326+
327+
/** An event associated with a sense. */
328+
EVENT,
329+
330+
/** The means by which an event occurs. */
331+
BY_MEANS_OF,
332+
333+
/** An entity that undergoes an event. */
334+
UNDERGOER,
335+
336+
/** A property expressed by a sense. */
337+
PROPERTY,
338+
339+
/** A state expressed by a sense. */
340+
STATE,
341+
342+
/** A resource or entity used by an event. */
343+
USES,
344+
345+
/** The destination of an event. */
346+
DESTINATION,
347+
348+
/** A body part associated with a sense. */
349+
BODY_PART,
350+
351+
/** A vehicle associated with a sense. */
352+
VEHICLE
115353
}

opennlp-api/src/test/java/opennlp/tools/wordnet/SynsetTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ void testRejectsNullPos() {
109109
}
110110

111111
@Test
112-
void testRejectsNullOrEmptyLemmas() {
112+
void testAllowsUnlexicalizedSynsetButRejectsInvalidLemmaLists() {
113113
assertThrows(IllegalArgumentException.class,
114114
() -> new Synset("test-1-n", WordNetPOS.NOUN, null, "", Map.of()));
115-
assertThrows(IllegalArgumentException.class,
116-
() -> new Synset("test-1-n", WordNetPOS.NOUN, List.of(), "", Map.of()));
115+
assertTrue(new Synset("test-1-n", WordNetPOS.NOUN, List.of(), "", Map.of())
116+
.lemmas().isEmpty());
117117
final List<String> withNull = new ArrayList<>();
118118
withNull.add(null);
119119
assertThrows(IllegalArgumentException.class,

0 commit comments

Comments
 (0)